cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_SPI_Init() needs some delay or will result in hard fault

Strooom
Senior

Some strange behaviour that I can't explain but like to understand :

I am using an e-paper display via SPI, and to conserve power during sleep, I power down the display via a FET.

After waking up, I enable the power to the display, then initialize the SPI to talk to it.

 

 

gpio::enableGpio(gpio::group::enableDisplayPower);
MX_SPI2_Init();
gpio::enableGpio(gpio::group::spiDisplay);

 

 However, this triggers a hard fault inside MX_SPI2_Init();

If I add a 1ms delay between turning on the power to the display and enabling the SPI, then the hard fault never appears..

 

gpio::enableGpio(gpio::group::enableDisplayPower);
HAL_Delay(1);
MX_SPI2_Init();
gpio::enableGpio(gpio::group::spiDisplay);

 

Of course, if I debug/step through MX_SPI2_Init(); the hard fault doesn't appear as this is also adding delays..

Any idea what is going wrong or how I could further investigate ?

1 ACCEPTED SOLUTION

Accepted Solutions
Strooom
Senior

This is apparently due to a power glitch caused by the inrush current of the display. 

I can't really see it on the scope, but if I enable the power slowly (avoiding the inrush current), then the hard fault does not occur.

View solution in original post

3 REPLIES 3
Strooom
Senior

This is apparently due to a power glitch caused by the inrush current of the display. 

I can't really see it on the scope, but if I enable the power slowly (avoiding the inrush current), then the hard fault does not occur.

Strooom
Senior

Maybe one more question here :

is it possibe to somehow 'see' trace in the MCU that a brown-out happened ? If possible, I could add that to the NMI / HardFault handlers and confirm my assumptions.

I've found there is a BOR_RSTF (BrownOut Reset Flag) in the RCC_CSR, however, I'm not experiencing a reset but rather a NMI or Hard Fault...