Recently I bought a NUCLEO-F334R8 board.
This board was officially supported by Mbed OS 5, but the support was dropped in Mbed OS 6.
I want to use this board with the new Mbed OS 6 API, so I tried to port it as a custom target.
I did the following steps:
add an entry in custom_target.json which simply inherits MCU_STM32F334x8.
2.copy system_clock.c, PinNames.h, PeripheralPins.c, PeripheralNames.h from the latest 5.15 branch, place them into the TARGET_NUCLEO_F334R8 folder.
3.modify PinNames.h to comply with the Mbed OS 6 conventions.
4.make the SystemInit function in system_stm32f3xx.c __weak, since it’s redefined in system_clock.c of NUCLEO_F334R8 target.
5.change MBED_RAM_SIZE to 0x3000(12KB) in mbed-os\targets\TARGET_STM\TARGET_STM32F3\TARGET_STM32F334x8.
After applying these changes I was able to compile a simple blinky app with Mbed OS 6, but the app crashes before entering main function.
I set a breakpoint in SystemInit function and step through the function, then the Segment Fault occurs at the exit of SystemInit.
I had successfully ported many F1, F4, H7, L0, G0 boards to Mbed OS 6, this is the first time to encounter such problem.
The same blinky app runs without a problem when compiled with Mbed OS 5.
I examined the generated .map file, and found ARM_LIB_STACK was placed at 0x20003000, which is beyond the 12KB SRAM size. It seems changing MBED_RAM_SIZE in cmsis_nvic.h has no effect.
Adding a mbed_ram_size entry in the custom_targets.json fixed the problem.
I was just curious, so I did a quick search through my mbedOS folder and it threw up a bunch of cmsis_nvic.h files in the target folders. I see inside there is this (note this is an example from a random cmsis_nvic.h file found within folder TARGET_STM32L496xG):