Author Topic: STM8 - write 2 bytes to EEPROM?  (Read 225 times)

0 Members and 1 Guest are viewing this topic.

Offline simonlasnier

  • Frequent Contributor
  • **
  • Posts: 282
  • Country: dk
STM8 - write 2 bytes to EEPROM?
« on: March 08, 2021, 01:38:49 pm »
Hi  ;D


Quick version: how to write 2 bytes (not in the same word) to the EEPROM in STM8? Should I write 1 byte and then wait for the EOP flag to be set before writing the second one?
 
Long version: for now I am simply doing:
* unlock EEPROM
* write byte 1 (EEPROM->data1 = xx;)
* write byte 2 (EEPROM->data2 = xx;) right after
* FLASH interrupt is called when finished (byte 1 or 2? I don't know), there I lock the EEPROM again
 

I imagine this is strange since with the RWW (read-while-write) fonctionality, the "write byte 2" instruction is executed while the first one is still running.

Anyways funny enough this works perfectly fine, except that it gives me problems with a silicon bug listed in the STM8AL3xx6/8 STM8Lx5xx4/6 Errata sheet (https://www.st.com/resource/en/errata_sheet/cd00237242-stm8al31xx-stm8al3lxx-stm8l052c6-stm8l151xx46-and-stm8l152xx46-device-limitations-stmicroelectronics.pdf)

The bug basically says that if the DMA requests access to the bus while an EEPROM write is starting (during the first 11 cycles) the CPU might stay in stall mode.

I have implemented the workaround 2, which is a high DMA timeout (I left it at the default value of 63 cycles) and no high priority DMA (I am only using Channel2 which is at the default = low). It works great with all my other EEPROM writes but not with this double write - hence my question: maybe I am just doing it wrong and I should wait for the first write to be finished?

Thank you

Simon
 

Offline simonlasnier

  • Frequent Contributor
  • **
  • Posts: 282
  • Country: dk
Re: STM8 - write 2 bytes to EEPROM?
« Reply #1 on: March 08, 2021, 01:59:55 pm »
Ok maybe I did not need to ask  ::)

I basically changed the code to make sure I was always done writing a byte when I start writing a second byte and it did seem to solve the problem (at least intense monky testing of 5 minutes cannot get the silicon bug to appear - the CPU does not stall).
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf