I've been migrating all my STM32 projects to Codeblocks IDE and GCC compiler (arm-none-eabi). The process is using STM's CubeMX to generate the base code, then merge everything to a proper folder with codeblocks project file, .s, .ld, etc.
Noted that my projects using cortexM0 are building and running fine, however for a cortexM4 project (STM32F401RE), lot of wild things are happening when running the built executable, hence my question here.
My guess is that I'm not calling GCC properly or some misconfiguration somewhere.
As "Defines"
STM32F401xE
As "Compiler Options":
-mcpu=cortex-m0 (note: should be -mcpu=cortex-m4) -ffunction-sections -fdata-sections -fno-common -s
As "Linker Options":
-Wl,--gc-sections -Wl,-Map,default/ggmeg.map -T ./STM32F401RETx_FLASH.ld -Wl,--print-memory-usage,--gc-sections,--relax
Any help appreciated. Thank you,
Please note I don't have live debug as I'm using a old segger Jlink as SWD interface. My first debug step is - after HAL_Init(); SystemClock_Config(); MX_GPIO_Init(); - to set a GPIO to 1 then do a while(1){} so I know my code has executed up to this point.
Now the wild things:
- Compile with -mcpu=cortex-m4, the code crashes before reaching my point.
- Compile with -mcpu=cortex-m0 (note: the STM32 i'm using is a M4), works better but...
- If I setup the GPIO to 1 at the end of -and within- MX_GPIO_Init(); the GPIO is set to 1, great.
- If I setup the GPIO to 1 after MX_GPIO_Init(); it crashes before reaching my section.
My conclusion is that MX_GPIO_Init(); crashes upon return indicating a severe problem.