2013-12-06 12:36 PM
I have a STM8S207 board and I'm using STVD version 4.3.3 with the Cosmic compiler. I am trying to use the @eeprom directive for writing/reading the data EEPROM and my system hangs when I try to write the data. Here's what I've been trying so far.
#include <string.h> #include ''stm8s.h'' #include ''stm8s_flash.h'' @eeprom s16 eeData; s16 localData; /* Read the data */ localData = eeData; // Works /* Write the data, scenario 1 */ eeData = localData; /* Write the data, scenario 2 */ eecpy(&eeData, &localData, 2); In both cases, the system hangs on the instruction in which I attempt to write to eeData. When stopping with the debugger I see that it is stopped inside function c_eewrw (library function?) at the following instruction: BTJF 0x505f, #2, 0xb155 Is there something else I need to do to get the system ready to write to data EEPROM? Thanks, Bryan2013-12-08 11:25 PM
I work with STM8L, but it is probably equivalent.
I have to unlock the eeprom before writing it, but on 8L writing to a protected memory don't hang the CPU.2013-12-09 02:45 AM
Bryan,
the instruction where your program hangs waits for the EEPROM programming end. As Argail told you, if you don't unlock EEPROM by writing the sequence: 0xAE 0x56 in FLASH_DUKR, your code will wait forever. Regards, EtaPhi2013-12-09 10:52 AM
All,
Thanks for the help. Turns out I was doing a few things wrong. First, I had a typo in my call to _fctcpy, so the flash programming routines of mine were not loaded into RAM. Then, as mentioned, I had also forgotten to unlock EEPROM. Also, I am using an external osciallator that operates above 16 MHz, so I set OPT7 to add a wait state as suggested by the datasheet. I also discovered that the data EEPROM gets cleared upon loading the program with the debugger. Makes sense, but I thought the debugger just re-wrote program flash, not the data EEPROM. Just restarting the debugger without stopping/starting the debugger does not re-write data EEPROM. Once I got all that straight I was able to write to data EEPROM and see my data still there upon a power cycle. Thanks, Bryan