summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2018-05-02 15:20:24 +1000
committerDamien George <damien.p.george@gmail.com>2018-05-02 15:20:24 +1000
commit051686b0a84ac78219c3509fda2a81dd89f3428a (patch)
tree4697a4320c620470c2ea1deb76b13c9db1ab2570
parenta03e6c1e05203bb71ebee50af2a41de404b05078 (diff)
stm32/main: Clean up and optimise initial start-up code of the MCU.
-rw-r--r--ports/stm32/main.c53
-rw-r--r--ports/stm32/system_stm32.c10
2 files changed, 43 insertions, 20 deletions
diff --git a/ports/stm32/main.c b/ports/stm32/main.c
index eefe47490..4553a07e2 100644
--- a/ports/stm32/main.c
+++ b/ports/stm32/main.c
@@ -3,7 +3,7 @@
*
* The MIT License (MIT)
*
- * Copyright (c) 2013, 2014 Damien P. George
+ * Copyright (c) 2013-2018 Damien P. George
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -418,15 +418,48 @@ STATIC uint update_reset_mode(uint reset_mode) {
#endif
void stm32_main(uint32_t reset_mode) {
- // TODO disable JTAG
-
- /* STM32F4xx HAL library initialization:
- - Configure the Flash prefetch, instruction and Data caches
- - Configure the Systick to generate an interrupt each 1 msec
- - Set NVIC Group Priority to 4
- - Global MSP (MCU Support Package) initialization
- */
- HAL_Init();
+ // Enable caches and prefetch buffers
+
+ #if defined(STM32F4)
+
+ #if INSTRUCTION_CACHE_ENABLE
+ __HAL_FLASH_INSTRUCTION_CACHE_ENABLE();
+ #endif
+ #if DATA_CACHE_ENABLE
+ __HAL_FLASH_DATA_CACHE_ENABLE();
+ #endif
+ #if PREFETCH_ENABLE
+ __HAL_FLASH_PREFETCH_BUFFER_ENABLE();
+ #endif
+
+ #elif defined(STM32F7) || defined(STM32H7)
+
+ #if ART_ACCLERATOR_ENABLE
+ __HAL_FLASH_ART_ENABLE();
+ #endif
+
+ SCB_EnableICache();
+ SCB_EnableDCache();
+
+ #elif defined(STM32L4)
+
+ #if !INSTRUCTION_CACHE_ENABLE
+ __HAL_FLASH_INSTRUCTION_CACHE_DISABLE();
+ #endif
+ #if !DATA_CACHE_ENABLE
+ __HAL_FLASH_DATA_CACHE_DISABLE();
+ #endif
+ #if PREFETCH_ENABLE
+ __HAL_FLASH_PREFETCH_BUFFER_ENABLE();
+ #endif
+
+ #endif
+
+ // Set the priority grouping
+ NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);
+
+ // SysTick is needed by HAL_RCC_ClockConfig (called in SystemClock_Config)
+ HAL_InitTick(TICK_INT_PRIORITY);
// set the system clock to be HSE
SystemClock_Config();
diff --git a/ports/stm32/system_stm32.c b/ports/stm32/system_stm32.c
index 2d9f7a15d..b03a3a357 100644
--- a/ports/stm32/system_stm32.c
+++ b/ports/stm32/system_stm32.c
@@ -602,13 +602,3 @@ void SystemClock_Config(void)
NVIC_SetPriority(SysTick_IRQn, NVIC_EncodePriority(NVIC_PRIORITYGROUP_4, TICK_INT_PRIORITY, 0));
#endif
}
-
-void HAL_MspInit(void) {
-#if defined(STM32F7) || defined(STM32H7)
- /* Enable I-Cache */
- SCB_EnableICache();
-
- /* Enable D-Cache */
- SCB_EnableDCache();
-#endif
-}