Skip to main content
jg_spitfire
Senior
March 19, 2020
Question

Hardfault error in SPI slave - polling mode

  • March 19, 2020
  • 9 replies
  • 1343 views

Hi, I am using cubemx to configure a stm32f411ve board as slave in receive only, polling mode and sofware NSS, in the code generated I have only added a few lines of code, only which I consider neccesary

**the master sends 12 bytes

outside main function:

uint8_t rxbuffer[12];
 
void Timeout_Error_Handler()
{
	while(1){
		HAL_GPIO_TogglePin(GPIOD,GPIO_PIN_13); //led orange
		HAL_Delay(500);
	}
 
}
 
 
void Error_Handler2()
{
	HAL_GPIO_WritePin(GPIOD,GPIO_PIN_14,GPIO_PIN_SET); //led red
}
 

inside main function:

// I have commented the while (1) because for my test the master sends data just one time 
 //while (1)
 {
 /* USER CODE END WHILE */
 MX_USB_HOST_Process();
 
 /* USER CODE BEGIN 3 */
 
 
 switch (HAL_SPI_Receive(&hspi5,rxbuffer,12,5000))
 {
 case HAL_OK:
 /* Turn LED6 on: Transfer in reception process is correct */
 HAL_GPIO_WritePin(GPIOD,GPIO_PIN_15,GPIO_PIN_SET); //led blue
 break;
 
 case HAL_TIMEOUT:
 Timeout_Error_Handler();
 break;
 
 case HAL_ERROR:
 Error_Handler2();
 break;
 
 default:
 break;
 }

the issue is that in debug mode I can see after the HAL_SPI_Receive function the program goes to a hardfault handler function.

do you know what could be the problem?

thanks

This topic has been closed for replies.

9 replies

KnarfB
Super User
March 19, 2020

When you are in the hard fault handler, what is the call stack?

How is rxbuffer defined?

jg_spitfire
Senior
March 19, 2020

Hi, sorry but I dont know what is the call stack, how can I find it?

and this is the definition of rx buffer: uint8_t rxbuffer[12]; it is in the line 1 of the first code

KnarfB
Super User
March 19, 2020

Depends on your toolchain. In CubeIDE it could look like:

0693W000000UInfQAG.png

left. You can walk up the call stack and find out the cause. In the example this is the machine instruction

080001e7: str r2, [r3, #0]

generated from the C code line

*p = 42;