AnsweredAssumed Answered

STM32F0 hardfault error with HAL Library

Question asked by vugs.michel.001 on Oct 9, 2015
Latest reply on Oct 9, 2015 by vugs.michel.001
Hello

We are currently switching from the STD library to the HAL library. Personally I'm not very pleased with that, but due to upcoming projects with F7 MCU we are mandatory to learn to use the HAL Library.

We are designing a driver for the RFM69 Radio module. To set the RFM69 to our needs we need to send a lot of commands trough SPI. This is the point where strange things happen. Sometimes the Microcontroller sends the data right, the other times we get a hardfault error. 

This is the part where the problems begin:

void Rfm69_Write_Reg(uint8_t address, uint8_t value)
{
  reg[0] = value;
  reg[1] = address | 0x80;
     
  HAL_SPI_Transmit(&hspi1, (uint8_t *)reg, 1, 1000);
}

The value 1 is because of the fact we set the SPI to 16 bit. 

The function Rfm69_write_Reg() is called multiple times at initialization of the RFM69 module:

void Rfm69_Init(void)
{
    uint8_t i;
     
  Rfm69_Reset();
    for( i = 0; i < sizeof(rfm69_base_config) / 2; i++)
    {
        Rfm69_Write_Reg(rfm69_base_config[i][0], rfm69_base_config[i][1]);
//      check = Rfm69_Read_Reg(rfm69_base_config[i][0]);
 
    }
}

But most of the times we get a Hardfault Handler. The strange thing is that when we uncomment the: check = Rfm69_Read_reg(rfm69_base_config[i][0]); line 
The program is working correctly. 

Does somebody sees the problem or has encountered the same problem?

My sincerly

Outcomes