cancel
Showing results for 
Search instead for 
Did you mean: 

stm32l eeprom erase problem

speed89
Associate
Posted on May 17, 2012 at 16:54

Hi,

I tried to make an erase of a valid address of data eeprom available on my stm32l151.

When I try to write 0x00000000 for instance to address 0x0808001B Keil uVision stops the debug mode give me a message of error.The error is something like ''device disconnected while debug is executing.Please check the JTAG connection.'' while the device stops itself and don't keeps on perform the execution of the program.I must reset it pulling down the reset pin in order to start the debug again.

The code I used is the following:

void write_eeprom(uint32_t address,uint32_t data){

if(IS_FLASH_DATA_ADDRESS(address)){

DATA_EEPROM_Unlock();

while(FLASH_GetStatus()!=FLASH_COMPLETE); 

FLASHStatus = DATA_EEPROM_ProgramWord (address, data);

if(FLASHStatus==FLASH_COMPLETE)

printf(''eeprom write ok!\n'');

DATA_EEPROM_Lock();

}

}

uint32_t read_eeprom(uint32_t address){

uint32_t tmp=0;

if(IS_FLASH_DATA_ADDRESS(address)){

DATA_EEPROM_Unlock();

while(FLASH_GetStatus()==FLASH_BUSY);

tmp=*(__IO uint32_t*)address;

DATA_EEPROM_Lock();

}

return tmp;

}

Going step by step in debug mode, I discovered that when the Data=0x00000000 is the line 13 of the following code to make the disaster:

1 FLASH_Status DATA_EEPROM_ProgramWord(uint32_t Address, uint32_t Data)

2 {

3   FLASH_Status status = FLASH_COMPLETE;

4   

5   /* Check the parameters */

6   assert_param(IS_FLASH_DATA_ADDRESS(Address));

7   

8   /* Wait for last operation to be completed */

9   status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);

10   

11   if(status == FLASH_COMPLETE)

12   {

13     *(__IO uint32_t *)Address = Data;

14 

15     /* Wait for last operation to be completed */

16     status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);        

17   }

18   /* Return the Write Status */

19   return status;

20 }

The only idea that I have is that the code is writing to a wrong address that is not pat of the eeprom.Anyway it happens only when I try to write 0 while it's ok when there is any other value.

Please do you have any idea?

Thanks

#stm32l-eeprom-flash-erase #stm32l-eeprom-erase-solved
4 REPLIES 4
Posted on May 17, 2012 at 17:32

Well I suspect if you are writing a 32-bit WORD, that you need to do so at an aligned address (ie divisable by 4, 0x0808001C). Odds are you're dumping into the Hard Fault routine for violating the bus.

I also doubt you need to unlock the memory to just read it, the data is in linear memory.

uint32_t read_eeprom(uint32_t address){
uint32_t tmp=0;
imp=*(__IO uint32_t*)address;
return tmp;
}

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
alok472
Associate II
Posted on May 18, 2012 at 03:42

''The only idea that I have is that the code is writing to a wrong address that is not pat of the eeprom.Anyway it happens only when I try to write 0 while it's ok when there is any other value''

 

When you say that the data i correctly written for non-zero values, you can pls verify the address at which the data is written ? Since you have the debugger, open the memory window and see the actual address on which this is written

These 2 lines are verifying if the address you are writing is eeprom address or not

5   /* Check the parameters */

6   assert_param(IS_FLASH_DATA_ADDRESS(Address));

Another wild guess... try using DATA_EEPROM_FixedTimeProgramCmd(), which is mentioned in the function header of DATA_EEPROM_ProgramByte. (i didnt use it though !!)

Nickname12657_O
Associate III
Posted on May 19, 2012 at 10:52

Dear Gentlemen,

Can you have a look on our Errata , Section 2.1 :

http://www.st.com/internet/com/TECHNICAL_RESOURCES/TECHNICAL_LITERATURE/ERRATA_SHEET/CD00278726.pdf

and check your device revision as mentioned in Table 4.

Cheers,

STOne-32.

speed89
Associate
Posted on May 30, 2012 at 11:04

Hi,

I tried to erase only the block with the address multiple of 4.Now it works.

I just don't understand how while I was writing something different from 0x00000000 it worked even in the odd addresses.What difference there is in the hardware programming when I write 0x00000000 instead of 0x00001111 (for instance).

I read the errata doc but none of whose problems are connected with mine.

Anyway the stmlib provided has an erase procedure called DATA_EEPROM_EraseWord that is the following:

/**

  * @brief  Erase a word in data memory.

  * @param  Address: specifies the address to be erased

  * @note1  - A data memory word is erased in the data memory only if the address 

  *         to load is the start address of a word (multiple of a word).

  * @note2   - To correctly run this function, the DATA_EEPROM_Unlock() function

  *           must be called before.

  *          - Call the DATA_EEPROM_Lock() to he data EEPROM access

  *            and Flash program erase control register access(recommended to protect 

  *            the DATA_EEPROM against possible unwanted operation)    

  * @retval FLASH Status: The returned value can be: 

  *   FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.

  */

FLASH_Status DATA_EEPROM_EraseWord(uint32_t Address)

{

  FLASH_Status status = FLASH_COMPLETE;

  

  /* Check the parameters */

  assert_param(IS_FLASH_DATA_ADDRESS(Address));

  

  /* Wait for last operation to be completed */

  status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);

  

  if(status == FLASH_COMPLETE)

  {

    /* Write ''00000000h'' to valid address in the data memory'' */

    *(__IO uint32_t *) Address = 0x00000000;

  }

   

  /* Return the erase status */

  return status;

}

It suggests:A data memory word is erased in the data memory only if the address 

  *         to load is the start address of a word (multiple of a word).

but in my opinion for the next revision of the lib you should insert something like

if(Address%0x04!=0)

return FLASH_ERROR_PROGRAM;

and off course to verify in the other procedures if the data is 0x00000000 and call the erase function above.

Thanks for you help!