From 6ddb5c66777caa3368acb101ec7a34d1c2975c42 Mon Sep 17 00:00:00 2001 From: straccio Date: Fri, 15 Dec 2017 18:06:40 +0100 Subject: [PATCH 1/5] Changes for FreeRTOS library. --- cores/arduino/Arduino.h | 5 +++-- cores/arduino/stm32/clock.c | 6 ++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/cores/arduino/Arduino.h b/cores/arduino/Arduino.h index b5289cbdeb..d2fc443aa4 100644 --- a/cores/arduino/Arduino.h +++ b/cores/arduino/Arduino.h @@ -32,12 +32,13 @@ #include "wiring.h" /* sketch */ -extern void setup( void ) ; -extern void loop( void ) ; #ifdef __cplusplus extern "C"{ #endif // __cplusplus +extern void setup( void ) ; +extern void loop( void ) ; + void yield(void); #ifdef __cplusplus } // extern "C" diff --git a/cores/arduino/stm32/clock.c b/cores/arduino/stm32/clock.c index 9317f98c88..f5ee4d2de4 100644 --- a/cores/arduino/stm32/clock.c +++ b/cores/arduino/stm32/clock.c @@ -125,6 +125,11 @@ uint32_t GetCurrentMilli(void) return HAL_GetTick(); } +void noOsSystickHandler(){ + +} + +void osSystickHandler() __attribute__((weak, alias("noOsSystickHandler"))); /** * @brief Function called when t he tick interruption falls * @param None @@ -134,6 +139,7 @@ void SysTick_Handler(void) { HAL_IncTick(); HAL_SYSTICK_IRQHandler(); + osSystickHandler(); } /** From 62f4479fd5fd02af94853a593a066ea96708d21a Mon Sep 17 00:00:00 2001 From: "Frederic.Pillon" Date: Fri, 5 Jan 2018 10:07:42 +0100 Subject: [PATCH 2/5] Changes for FreeRTOS library Ensure all the priority bits are assigned to be preempt priority bits by calling NVIC_PriorityGroupConfig( NVIC_PriorityGroup_4 ); before the RTOS is started. See https://www.freertos.org/RTOS-Cortex-M3-M4.html Signed-off-by: Frederic.Pillon --- cores/arduino/main.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cores/arduino/main.cpp b/cores/arduino/main.cpp index 13e90f608c..3bf32a6616 100644 --- a/cores/arduino/main.cpp +++ b/cores/arduino/main.cpp @@ -29,7 +29,13 @@ void initVariant() { } // Force init to be called *first*, i.e. before static object allocation. // Otherwise, statically allocated objects that need HAL may fail. __attribute__(( constructor (101))) void premain() { - init(); + +// Required by FreeRTOS, see http://www.freertos.org/RTOS-Cortex-M3-M4.html +#ifdef NVIC_PRIORITYGROUP_4 + HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4); +#endif + + init(); } /* From 57585ac85a234a2fe05269437aa1788c7b671ebb Mon Sep 17 00:00:00 2001 From: "Frederic.Pillon" Date: Fri, 5 Jan 2018 10:11:18 +0100 Subject: [PATCH 3/5] Added Sketch source path to the include path This allow to check thanks '#if __has_include("xxxxx.h")' if user adds a specific header file. Ex: Used by STM32duino FreeRTOS to include user FreeRTOS configuration (named STM32FreeRTOSConfig.h) instead of the FreeRTOSConfig_Default.h Signed-off-by: Frederic.Pillon --- platform.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform.txt b/platform.txt index 351a52dead..94a3f44dc5 100644 --- a/platform.txt +++ b/platform.txt @@ -9,7 +9,7 @@ version=1.0.0 # STM compile variables # ---------------------- -compiler.stm.extra_include="-I{build.core.path}/avr" "-I{build.core.path}/stm32" "-I{build.system.path}/Drivers/{build.series}_HAL_Driver/Inc/" "-I{build.system.path}/Drivers/{build.series}_HAL_Driver/Src/" "-I{build.system.path}/{build.series}/" "-I{build.variant.path}/usb" "-I{build.variant.path}/Ethernet" "-I{build.system.path}/Middlewares/ST/STM32_USB_Device_Library/Core/Inc" "-I{build.system.path}/Middlewares/ST/STM32_USB_Device_Library/Core/Src" +compiler.stm.extra_include="-I{build.source.path}" "-I{build.core.path}/avr" "-I{build.core.path}/stm32" "-I{build.system.path}/Drivers/{build.series}_HAL_Driver/Inc/" "-I{build.system.path}/Drivers/{build.series}_HAL_Driver/Src/" "-I{build.system.path}/{build.series}/" "-I{build.variant.path}/usb" "-I{build.variant.path}/Ethernet" "-I{build.system.path}/Middlewares/ST/STM32_USB_Device_Library/Core/Inc" "-I{build.system.path}/Middlewares/ST/STM32_USB_Device_Library/Core/Src" # "-I{build.system.path}/Drivers/BSP/Components" "-I{build.system.path}/Middlewares/Third_Party/FatFs/src" "-I{build.system.path}/Middlewares/ST/STM32_USB_Device_Library/Core/Src" "-I{build.system.path}/Middlewares/ST/STM32_USB_Device_Library/Class/HID/Inc" From db1a7cb1ff6e204c9286f5bcaed684fb467a2eec Mon Sep 17 00:00:00 2001 From: "Frederic.Pillon" Date: Wed, 10 Jan 2018 15:05:27 +0100 Subject: [PATCH 4/5] Allow to redefine Exception handler By default, all Interruption and Exception Handlers are weaked and aliased to Default_Handler (Infinite Loop, See CMSIS device startup file) So, those defined handlers in the core doing a loop bring nothing except to not allow further redefinition. But this is what we want, be able to redefine those handler. Ex: FreeRTOS library requires to be able to redefine them. Signed-off-by: Frederic.Pillon --- cores/arduino/stm32/hw_config.c | 104 -------------------------------- 1 file changed, 104 deletions(-) diff --git a/cores/arduino/stm32/hw_config.c b/cores/arduino/stm32/hw_config.c index a337f699c9..8293e902a4 100644 --- a/cores/arduino/stm32/hw_config.c +++ b/cores/arduino/stm32/hw_config.c @@ -114,110 +114,6 @@ void hw_config_init(void) SystemClock_Config(); } -/******************************************************************************/ -/* Cortex-M4 Processor Interruption and Exception Handlers */ -/******************************************************************************/ - -/** -* @brief This function handles Non maskable interrupt. -*/ -void NMI_Handler(void) -{ - /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ - - /* USER CODE END NonMaskableInt_IRQn 0 */ - - /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ - - /* USER CODE END NonMaskableInt_IRQn 1 */ - -} - -/** -* @brief This function handles Hard fault interrupt. -*/ -void HardFault_Handler(void) -{ - /* USER CODE BEGIN HardFault_IRQn 0 */ - - /* USER CODE END HardFault_IRQn 0 */ - while (1) - { - } - /* USER CODE BEGIN HardFault_IRQn 1 */ - - /* USER CODE END HardFault_IRQn 1 */ -} - -/** -* @brief This function handles Memory management fault. -*/ -void MemManage_Handler(void) -{ - - /* USER CODE BEGIN MemoryManagement_IRQn 0 */ - - /* USER CODE END MemoryManagement_IRQn 0 */ - while (1) - { - } - /* USER CODE BEGIN MemoryManagement_IRQn 1 */ - - /* USER CODE END MemoryManagement_IRQn 1 */ -} - -/** -* @brief This function handles Pre-fetch fault, memory access fault. -*/ -void BusFault_Handler(void) -{ - - /* USER CODE BEGIN BusFault_IRQn 0 */ - - /* USER CODE END BusFault_IRQn 0 */ - while (1) - { - } - /* USER CODE BEGIN BusFault_IRQn 1 */ - - /* USER CODE END BusFault_IRQn 1 */ -} - -/** -* @brief This function handles Undefined instruction or illegal state. -*/ -void UsageFault_Handler(void) -{ - - /* USER CODE BEGIN UsageFault_IRQn 0 */ - - /* USER CODE END UsageFault_IRQn 0 */ - while (1) - { - } - /* USER CODE BEGIN UsageFault_IRQn 1 */ - - /* USER CODE END UsageFault_IRQn 1 */ -} - -/** -* @brief This function handles Debug monitor. -*/ -void DebugMon_Handler(void) -{ - - /* USER CODE BEGIN DebugMonitor_IRQn 0 */ - - /* USER CODE END DebugMonitor_IRQn 0 */ - while (1) - { - } - /* USER CODE BEGIN DebugMonitor_IRQn 1 */ - - /* USER CODE END DebugMonitor_IRQn 1 */ -} - - /** * @} */ From 37539b559c228131ceaa838551314a7389bfb9d2 Mon Sep 17 00:00:00 2001 From: "Frederic.Pillon" Date: Wed, 10 Jan 2018 15:05:49 +0100 Subject: [PATCH 5/5] Clean up comment in hw_config.c Signed-off-by: Frederic.Pillon --- cores/arduino/stm32/hw_config.c | 70 --------------------------------- 1 file changed, 70 deletions(-) diff --git a/cores/arduino/stm32/hw_config.c b/cores/arduino/stm32/hw_config.c index 8293e902a4..f5e9fc6d20 100644 --- a/cores/arduino/stm32/hw_config.c +++ b/cores/arduino/stm32/hw_config.c @@ -35,17 +35,6 @@ * ****************************************************************************** */ -/** @addtogroup CMSIS - * @{ - */ - -/** @addtogroup stm32f4xx_system - * @{ - */ - -/** @addtogroup STM32F4xx_System_Private_Includes - * @{ - */ #include "stm32_def.h" #include "hw_config.h" @@ -53,53 +42,6 @@ extern "C" { #endif -/** - * @} - */ - -/** @addtogroup STM32F4xx_System_Private_TypesDefinitions - * @{ - */ - -/** - * @} - */ - -/** @addtogroup STM32F4xx_System_Private_Defines - * @{ - */ -/** - * @} - */ - -/** @addtogroup STM32F4xx_System_Private_Macros - * @{ - */ - -/** - * @} - */ - -/** @addtogroup STM32F4xx_System_Private_Variables - * @{ - */ - -/** - * @} - */ - -/** @addtogroup STM32F4xx_System_Private_FunctionPrototypes - * @{ - */ - -/** - * @} - */ - -/** @addtogroup STM32F4xx_System_Private_Functions - * @{ - */ - /** * @brief This function performs the global init of the system (HAL, IOs...) * @param None @@ -113,18 +55,6 @@ void hw_config_init(void) // Configure the system clock SystemClock_Config(); } - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ #ifdef __cplusplus } #endif