AnsweredAssumed Answered

Hardfault with simple method call

Question asked by Luke on Feb 26, 2016
Latest reply on Feb 26, 2016 by Luke
Hi all,
I am having an odd hard-fault crash on my STM32F030 board when I attempt to use USART. The calls are pretty standard, which leads me to believe its a linker issue. I have simplified to the minimal program that generates the fault, which is:

#include "stm32f0xx.h"
#include "stm32f0xx_rcc.h"
#include "stm32f0xx_gpio.h"
#include "stm32f0xx_usart.h"

void test(char* s) {
int main(void)
     USART_InitTypeDef USART_InitStructure;
    USART_InitStructure.USART_BaudRate = 57600;//9600;
    USART_InitStructure.USART_WordLength = USART_WordLength_8b;
    USART_InitStructure.USART_StopBits = USART_StopBits_1;
    USART_InitStructure.USART_Parity = USART_Parity_No;
    USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
    USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
    USART_Init(USART1, &USART_InitStructure);



Simply by calling test() with a literal string after calling USART_Init() generates the fault, which makes no sense to me. In debug the trace shows WWDG_IrqHandler() in the call stack, but I presume this just the last weak handler defined - the fault code is given as a hard-fault. This seems to be a linker issue but I cannot see what it may be, since the compile/link calls were auto-generated by CooCox and have always worked fine in the past. The compile/linker calls are:
arm-none-eabi-gcc -mcpu=cortex-m0 -mthumb -Wall -ffunction-sections -g -O0 -c -DSTM32F030R8T6 -DSTM32F030X8 -DUSE_STDPERIPH_DRIVER -D__ASSEMBLY__ -IC:\Test\stm32_lib\inc -IC:\ -IC:\Test -IC:\Test\cmsis_boot -IC:\Test\stm32_lib -IC:\Test\cmsis_core C:\Test\stm32_lib\src\stm32f0xx_rcc.c C:\Test\main.c C:\Test\cmsis_boot\startup\startup_stm32f0xx.s C:\Test\cmsis_boot\system_stm32f0xx_temp.c C:\Test\stm32_lib\src\stm32f0xx_gpio.c C:\Test\stm32_lib\src\stm32f0xx_usart.c C:\Test\stm32_lib\src\stm32f0xx_misc.c

arm-none-eabi-gcc -mcpu=cortex-m0 -mthumb -g -nostartfiles -Wl, -O0 -Wl,--gc-sections -LC:\CooCox\CoIDE\configuration\ProgramData\test -Wl,-TC:\CooCox\CoIDE\configuration\ProgramData\test/arm-gcc-link.ld -g -o test.elf ..\obj\stm32f0xx_rcc.o ..\obj\main.o ..\obj\startup_stm32f0xx.o ..\obj\system_stm32f0xx_temp.o ..\obj\stm32f0xx_gpio.o ..\obj\stm32f0xx_usart.o ..\obj\stm32f0xx_misc.o

Any ideas?