2013-06-09 04:01 AM
Hi,
I've been using an STM32F4 Discovery board with uVision4 for around 10 months now, and have learnt how to use the basic features (ADC, LCD, USART etc) and I'm now tackling the accelerometer (LIS302DL). I've looked at various examples from the net including the one(s) supplied by ST, however I always seem to get a HardFault Exception before main code is even reached! I've researched this HardFault error and tried to work my way around it, to no success. The Fault Report has NOCP ticked in the Usage Faults box and FORCED in the Hard Faults box.I've reloaded previous projects and they work fine. So it seems to be a problem whenever I try to write code relating to the accelerometer.Could someone please help me out? All I want to do is read from the accelerometer, and not encounter the HardFault Exception.ThanksTom #accelerometer #lis302dl #stm32f42013-06-09 04:41 AM
What tool chain is this with? Are you using floating point code that might be using the FPU without enabling it?
There are a couple of things which will cause a Hard Fault, most are read/write access to memory that isn't present, or attempts to execute 32-bit ARM instructions. You need to make a determination about what assembler instruction is faulting.[DEAD LINK /public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/How%20to%20debug%20hard%20fault%20handler%20exceptions&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B¤tviews=617]https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2Fcortex_mx_stm32%2FHow%20to%20debug%20hard%20fault%20handler%20exceptions&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B¤tviews=6172013-06-09 05:32 AM
Hi clive1,
Thanks for your reply. I went through the assembly code and the compiler may have been generating floating point code without me knowing. In any case, I seem to have now solved the issue by enabling the FPU in the startup_stm32f4xx.s file, as done so at the beginning of this thread : [DEAD LINK /public/STe2ecommunities/mcu/Lists/STM32Discovery/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/STM32Discovery/stm32f4%20random%20hard%20faults%20%28solved%29&FolderCTID=0x01200200770978C69A1141439FE559EB459D75800084C20D8867EAD444A5987D47BE638E0F¤tviews=1610]https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Discovery/Flat.aspx?RootFolder=%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2FSTM32Discovery%2Fstm32f4%20random%20hard%20faults%20(solved)&FolderCTID=0x01200200770978C69A1141439FE559EB459D75800084C20D8867EAD444A5987D47BE638E0F¤tviews=1610Many thanks againTom