Associate III
August 3, 2016
Question
STM32F051K6T6 hardfault with HAL and SPI
- August 3, 2016
- 6 replies
- 2714 views
Posted on August 03, 2016 at 15:18
This is my first HardFault ever, so I don't really know how to handle it. I've google it alot, tried tochange stack size and played with other SPI settings, but with no success. The same NRF24L01 board works with Arduino, so there must be an error somewhere in my code/pcb.
Let me know what additional informations are needed.
Thanks!
#hal #spi #cubemx #hardfault
Hello,
I've got a project build on custom PCB around STM32F051K6T6. There are a couple of other things on this PCB: ULN2003 driver, CD4511B driver , TLV73333 3.3V regulator and the main ''problem'' NRF24L01+ module, connected through SPI1. Board peripherals and init code are generated with CubeMX software. So far everything worked just well: PWM on gpio, timer 6 for some periodic interrupts, CD4511 7 segment driver... When I tried to connect NRF24L01+ through SPI with custom library (modified tm_nrf library) using SPI HAL drivers, strange things happen. uC halts in Hard Fault Handler after a few SPI transmit and/or receive commands. It halts at in stm32fxx_hal_spi.c file in functionHAL_SPI_Transmit()
at specific line ():
HAL_StatusTypeDef HAL_SPI_Transmit(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size, uint32_t Timeout){
/*
...other code...
*/
/* Transmit data in 8 Bit mode */
else
{
while
(hspi->TxXferCount > 0){
/* Wait until TXE flag is set to send data */
if
((hspi->Instance->SR & SPI_FLAG_TXE) == SPI_FLAG_TXE){
if
(hspi->TxXferCount > 1){
/* write on the data register in packing mode */
hspi->Instance->DR = *((uint16_t*)hspi->pTxBuffPtr);
hspi->pTxBuffPtr +=
sizeof
(uint16_t);
hspi->TxXferCount -= 2;
}
else
{
*((__IO uint8_t*)&hspi->Instance->DR) = (*hspi->pTxBuffPtr++);
hspi->TxXferCount--;
}
}
else
{
/* Timeout management */
if
((Timeout == 0) || ((Timeout != HAL_MAX_DELAY) && ((HAL_GetTick()-tickstart) >= Timeout))){
errorcode = HAL_TIMEOUT;
goto
error;
}
}
}
}
/*
...other code...
*/
} ... and than halts at HarFault_Handler.
This is my first HardFault ever, so I don't really know how to handle it. I've google it alot, tried tochange stack size and played with other SPI settings, but with no success. The same NRF24L01 board works with Arduino, so there must be an error somewhere in my code/pcb.
Let me know what additional informations are needed.
Thanks!
#hal #spi #cubemx #hardfault