cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F372 first project

Maddi.Mike
Associate II
Posted on November 28, 2013 at 18:44

I am new to ARM and am trying to create my very first project using an STM32F372CC micro. I have a prototype board connected to a STM32L discovery board. I am using Keil uVision V4.70.0.0. I can compile and download to the prototype board. But when I run, it goes to the hardfault handler in startup_stm32f37x.s which I obtained from the ST library. I searched this forum for everything I could find for hardfault but nothing addresses my problem. The problem must something very basic maybe in the setup or maybe I'm not using the correct startup file because the error occurs before it ever gets to any of my code. I can trace through the code from Reset_Handler in the startup file. In Reset_Handler it calls SystemInit and returns ok. Then there is a LDR R0, =__main instruction followed by a BX R0. When I step through the BX R0 instruction, it goes to __user_initial_stackheap in the startup file. That eventually leads to a BX LR instruction which, when executed, goes right to the HardFault_Handler also in startup.

Am I using the wrong startup file (startup_stmf37x.s)? I don't know where to go from here. I would greatly appreciate some help. Thank you very much.

#stm32f37-hardfault
6 REPLIES 6
Posted on November 28, 2013 at 23:17

Use a proper Hard Fault handler and it might point you at a specific instruction.

Make sure you have the FPU enabled in SystemInit(). Be conscious of  the PLL settings, and external HSE crystal, and the HSE_VALUE definition. Make sure the stack is of an adequate size.

When it calls __main this is the static initialization code for the C run time, which later calls your main() function. Make sure Keil has selected the right target processor, and the correct FLASH and RAM sizes for that processor.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Maddi.Mike
Associate II
Posted on November 29, 2013 at 16:12

Thanks for your response. I really appreciate it. I don't know if you use Keil uVision but I used all their default settings which include enabling the hardware FPU, an 8MHz external crystal (which there is on the prototype board) and the address assignments it set for the STM32F372CC. The linker setting defaults are set to 0x0800000 for the R/O memory and 0x20000000 for the R/W memory. In the target settings, it has ROM at  0x0800000 with a size of 0x40000 and RAM set at 0x20000000 with a size of 0x8000.

Posted on November 29, 2013 at 16:46

Yes, I use Keil a lot, but also use things like GNU/GCC, IAR and others as required. Just trying to suggest a number of failure mechanisms I encounter the most.

Memory allocation looks fine.

Check HSE_VALUE and the PLL settings in system_stm32f3xx.c, and how the wait states in the flash controller are configured.

If the hard fault crashes because it jumps to LR, what is the value in LR, and what code is situated there?

The default stacks in Keil also tend to be on the smaller size, especially when people are used to PC's and have huge local/automatic allocations in their subroutines.

Review Joseph Yiu's Hard Fault handler suggestions, implement something that dumps stack, processor and register states. This will address the how/why of the fault.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Maddi.Mike
Associate II
Posted on November 29, 2013 at 17:14

Did you meant system_stm32f3xx.[s] because I don't see the .c file.

Maddi.Mike
Associate II
Posted on November 29, 2013 at 17:24

I don't see any system_stm32f3xx.c file. Am I missing a library?

Maddi.Mike
Associate II
Posted on November 29, 2013 at 17:35

Ok now I feel like an idiot! I found ''system_stm32f37x.c'' and when I added that file and removed my dopey SystemInit function, the problem went away. So problem solved. Thank you very much clive1.