STM32L431RCT Hard Fault on SPI at HAL library
- June 24, 2021
- 3 replies
- 984 views
Hi,
I keep on getting hard fault on HAL_SPI_Transmit_IT.
I am trying to communicate to SX1276.
The circuit is designed by another experienced hardware engineer.
I use the similar code on STM32L431CBT without issue.
However, I face random hard fault on STM32L431RCT.
The problem only occurs after a few minutes of normal running.
The hard fault sometimes point to HAL_SPI_Transmit_IT, sometimes to HAL_SPI_TransmitReceive_IT and always point to the following line at HAL_SPI_Transmit_IT
if ((hspi->Instance->CR1 & SPI_CR1_SPE) != SPI_CR1_SPE)0xE000ED28 = 00000000
0xE000ED2C = 00000000
0xE000ED30 = 01000000
0xE000ED34 = F8ED00E0
0xE000ED38 = F8ED00E0
0xE000ED3C = 00000000
I don't get the Mem Manage fault that mentioned in Joseph Yiu's book.
The problem code is in LORA.cpp as follows:
// SPI read register
uint8_t LORA::SPIReadReg(uint8_t addr)
{
uint8_t data __attribute__((aligned (16)));
uint8_t SendNull __attribute__((aligned (16)));
SendNull = 0x00;
HAL_GPIO_WritePin(LORA_NSS_GPIO_Port, LORA_NSS_Pin, GPIO_PIN_RESET);
while(HAL_SPI_GetState(&hspi1) != HAL_SPI_STATE_READY);
HAL_SPI_Transmit_IT(&hspi1, (uint8_t *)&addr, sizeof(uint8_t));
// read register value
while(HAL_SPI_GetState(&hspi1) != HAL_SPI_STATE_READY);
HAL_SPI_TransmitReceive_IT (&hspi1, (uint8_t *)&SendNull, (uint8_t *)&data, sizeof(uint8_t));
while(HAL_SPI_GetState(&hspi1) != HAL_SPI_STATE_READY);
HAL_GPIO_WritePin(LORA_NSS_GPIO_Port, LORA_NSS_Pin, GPIO_PIN_SET);
return((uint8_t)data);
}Really need some help from experts here.
Attached is all the project related file.