cancel
Showing results for 
Search instead for 
Did you mean: 

STORAGE_Read_FS triggers HardFault_Handler() when trying to read from SPI

duesentrieb
Associate II

Hello everyone,

I've a project where I'm trying to emulate a mass storage device (MSC) using the STM32F103C8T6. The data itself should be stored on the Serial NOR-Flash (Winbound W25Q64...), operations are done with this library. Using the library in the main()-function, everything works (the library just translates the read/write calls into underlying spi hal). But accessing the flash chip via spi inside the STORAGE_Read_FS or STORAGE_Write_FS functions from the provided mass storage class (MSC), every function call to msc functions causes the HardFault handler to be triggered. Most of the time it's triggered somewhere in the HAL_SPI_TransmitReceive function, sometimes also in the HAL_GPIO_WritePin function. I increased both stack and heap size to 0x1000 bytes, but nothing changed. My guess is that there's memory corruption happening somewhere, but I couldn't find it even after days of research.

I would be very grateful if someone could help me to solve this problem.

duesentrieb_0-1718292040089.pngduesentrieb_1-1718292084729.png

2 REPLIES 2
Saket_Om
ST Employee

Hello @duesentrieb 

 

Although you've increased the stack and heap, ensure that they are correctly configured in your linker script or system file and that the increase is sufficient for your application's needs.

Please ensure to check if the stack is overflowing.

If your question is answered, please close this topic by clicking "Accept as Solution".

Thanks
Omar

>>My guess is that there's memory corruption happening somewhere, but I couldn't find it even after days of research. I would be very grateful if someone could help me to solve this problem.

Look at what's actually faulting, the registers, the memory, the stack, or whatever. Establish a way to test for that condition earlier, so you can determine where it starts happening and work backward to the source of the failure.

Put patterns on the stack so you can determine depth/usage.

Use the FPB/DWT to set watch points

>>I increased both stack and heap size to 0x1000 bytes, but nothing changed. 

So probably not those then, if you can quickly identify what it's not, you won't waste days on the problem by looking in the wrong place..

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..