cancel
Showing results for 
Search instead for 
Did you mean: 

EEPROM write problems (STM32L071KB vs STM32L071CB)

MK?�h
Associate

Hi,

 Writing to EEPROM worked fine like that on our KB but since we switched to STM32L071CB the Problems started.

bool eeprom_interface_write_init(void)
 
{
 
        if(HAL_OK == HAL_FLASHEx_DATAEEPROM_Unlock())   //unlock DATAEEPROM
 
        {
 
            __debug_messageLn(LOGLEVEL_DEBUG1, "succesfully unlocked");
 
            return true;
 
        }else __debug_messageLn(LOGLEVEL_WARNING, "EEPunlock failed");
 
 
 
    return false;
 
}
 
 
 
bool eeprom_interface_write_deInit(void)
 
{
 
    if(HAL_FLASHEx_DATAEEPROM_Lock() == HAL_OK){
 
        return true;
 
    }else return false;    //relock afterwards 
 
}
 
 
 
bool eeprom_interface_writeWords(uint32_t Address, uint32_t* Data, int count)
 
{
 
    
 
    if(eeprom_interface_write_init()){    //prepare EEPROM Write
 
 
 
        for(int i=0;i<count;i++){
 
            
 
            HAL_StatusTypeDef result = HAL_FLASHEx_DATAEEPROM_Program(FLASH_TYPEPROGRAMDATA_WORD,Address + (i * 4),Data[i]);
 
            switch(result){
 
                case HAL_OK:{
 
                    __debug_messageLn(LOGLEVEL_DEBUG1, "wrote 1 word");
 
                    break;
 
                }
 
                case HAL_BUSY:{
 
                    __debug_messageLn(LOGLEVEL_WARNING, "interface busy");
 
                    return false;
 
                    break;
 
                }
 
                case HAL_TIMEOUT:{
 
                    __debug_messageLn(LOGLEVEL_WARNING, "write timeout");
 
                    return false;
 
                    break;
 
                }
 
                case HAL_ERROR:{
 
                    __debug_messageLn(LOGLEVEL_ERROR, "write error");
 
                    return false;
 
                    break;
 
                }
 
            };
 
        }
 
        if(eeprom_interface_write_deInit()){
 
            __debug_messageLn(LOGLEVEL_DEBUG1, "successfully relocked");
 
            return true;
 
        }
 
        __debug_messageLn(LOGLEVEL_WARNING, "left wo locking");
 
        return true;
 
    }
 
    __debug_messageLn(LOGLEVEL_ERROR, "init failed");
 
    return false;
 
}

1:

the first EEPROM action after reboot always failed -> so we started to waste one in the begining as dirty fix do you know what could cause this?

HAL_FLASHEx_DATAEEPROM_Erase(0x080817FB); 

2:

After an successfull unlock (HAL_OK) it sometime hangs at the write operation and not even the Watchdog interrupt triggers after that and it doesnt end in the Hardfault Handler.

Since im Pretty Clueless about the second one it would be very cool if you find a bug in the above code or could post the code you used to successfully access the STM32L071CBs EEPROM

0 REPLIES 0