2020-03-19 03:49 AM
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
2020-03-19 04:48 AM
When you are in the hard fault handler, what is the call stack?
How is rxbuffer defined?
2020-03-19 05:21 AM
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
2020-03-19 06:11 AM
Depends on your toolchain. In CubeIDE it could look like:
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;
2020-03-19 06:22 AM
ok, this is my debug window , what should I do now?
2020-03-19 06:32 AM
sorry but how do you kow that the cause is this?
080001e7: str r2, [r3, #0]
and the c code line is this?
*p = 42;
2020-03-19 07:11 AM
In the debug view click on main(). This will put you to the source code line.
2020-03-19 07:28 AM
The fault analyzer window says its an data access fault. So I'm looking fo the last load or store instruction before the current (fault handler) instruction.
Its also an imprecise fault, so it is caused by the write buffer (store).
2020-03-19 07:53 AM
I select main indebug view and shows me this line
but that line is the end of this part of the code, there is nothing declared there
I am using SW4STM32 and it seems that it does not have a fault analyzer window
2020-03-19 08:06 AM
Go single step by single step though your code and watch when its crashing. Can even go single step at instruction level if you dare to.