Fix access to the DWT peripheral for STM32 HAL (#12434)
Access to the DWT peripheral for the `CYCCNT` register needs to happen before `main()`. The code needs to be called after the setup of the system clocks, so the right place is between the `premain()` and `main()` function of the STM32 Arduino core. This patch moves the DWT access code to a new function, which is then placed between `premain()` and `main()`.
This commit is contained in:
parent
7f225b9421
commit
5a4fd8e0a6
@ -78,14 +78,20 @@ uint16_t HAL_adc_result;
|
|||||||
// Public functions
|
// Public functions
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
// Needed for DELAY_NS() / DELAY_US() on CORTEX-M7
|
||||||
|
#if (defined(__arm__) || defined(__thumb__)) && __CORTEX_M == 7
|
||||||
|
// HAL pre-initialization task
|
||||||
|
// Force the preinit function to run between the premain() and main() function
|
||||||
|
// of the STM32 arduino core
|
||||||
|
__attribute__((constructor (102)))
|
||||||
|
void HAL_preinit() {
|
||||||
|
enableCycleCounter();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// HAL initialization task
|
// HAL initialization task
|
||||||
void HAL_init(void) {
|
void HAL_init(void) {
|
||||||
|
|
||||||
// Needed for DELAY_NS() / DELAY_US() on CORTEX-M7
|
|
||||||
#if (defined(__arm__) || defined(__thumb__)) && __CORTEX_M == 7
|
|
||||||
enableCycleCounter();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
FastIO_init();
|
FastIO_init();
|
||||||
|
|
||||||
#if ENABLED(SDSUPPORT)
|
#if ENABLED(SDSUPPORT)
|
||||||
|
Loading…
Reference in New Issue
Block a user