Report
4 months ago.

DISCO_L072CZ_LRWAN1: EEPROM write failed

EEPROM write snippet

HAL_StatusTypeDef writeEEPROMByte(uint32_t address, uint8_t data)
 {
    HAL_StatusTypeDef  status;
    address = address + 0x08080000;
    HAL_FLASHEx_DATAEEPROM_Unlock();  //Unprotect the EEPROM to allow writing
    status = HAL_FLASHEx_DATAEEPROM_Program(TYPEPROGRAMDATA_BYTE, address, data);
    HAL_FLASHEx_DATAEEPROM_Lock();  // Reprotect the EEPROM
    return status;
}

The above snippet leads to hard-fault handler.

Source code: mbed import mbed-os-example-lorawan

I edited main.cpp and add below lines before calling the lorawan initialization function,

EEPROM write call from main.cpp

int main (void)
{
    writeEEPROMByte(0, 0x05);
    /*followed by lorawan apis*/
}

When I compiled and flashed the binary to the MCU, it entered in hard-fault handler.

hard-fault handler line

*(__IO uint8_t *)Address = (uint8_t) Data;

How do I resolve the hard-fault problem?

Note: EEPROM is working good with I-CUBE-LRWAN firmware (I mean without MBED OS). I don't see any problem with the snippet.

Comment on this question
Be the first to answer this question.

To post an answer, please log in.