ST意法半导体
直播中

h1654155275.5950

7年用户 206经验值
私信 关注
[问答]

使用eeprom写入数据EEPROM时出错

我有一个STM8S207板,我正在使用带有Cosmic编译器的STVD版本4.3.3。我正在尝试使用@eeprom指令来写入/读取数据EEPROM,当我尝试写入数据时系统挂起。这是我到目前为止所尝试的内容。


#include< string.h>
#include''stm8s.h''
#include''stm8s_flash.h''

@eeprom s16 eeData;
s16 localData;

/ *读取数据* /
localData = eeData; //工作

/ *写入数据,方案1 * /
eeData = localData;

/ *写入数据,方案2 * /
eecpy(& eeData,& localData,2);

在这两种情况下,系统都会挂起我尝试写入eeData的指令。当使用调试器停止时,我看到它在函数c_eewrw(库函数?)中停止在以下指令:

BTJF 0x505f,#2,0xb155

为了让系统准备好写入数据EEPROM,我还需要做些什么吗?

谢谢,
布赖恩

以上来自于谷歌翻译


以下为原文




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
#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,
Bryan

回帖(3)

李雷

2019-2-25 11:00:17
我使用STM8L,但它可能是等效的。
 
 
我必须在写入之前解锁eeprom,但是在8L写入受保护的内存时不要挂起CPU。

以上来自于谷歌翻译


以下为原文





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.
举报

王明

2019-2-25 11:09:59
布莱恩,
 
 程序挂起的指令等待EEPROM编程结束。
 正如Argail告诉你的那样,如果你没有通过在FLASH_DUKR中写入序列:0xAE 0x56来解锁EEPROM,那么你的代码将永远等待。
 问候,
 EtaPhi

以上来自于谷歌翻译


以下为原文





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,
EtaPhi
举报

h1654155275.5950

2019-2-25 11:23:05
所有,
 
 
 谢谢您的帮助。事实证明我做错了一些事情。首先,我在调用_fctcpy时输入了一个拼写错误,因此我的flash编程例程没有加载到RAM中。然后,如上所述,我也忘了解锁EEPROM。此外,我正在使用一个工作在16 MHz以上的外部振荡器,所以我设置OPT7以添加数据表建议的等待状态。
 
 我还发现在使用调试器加载程序时数据EEPROM会被清除。有道理,但我认为调试器只是重写程序闪存,而不是数据EEPROM。只需在不停止/启动调试器的情况下重新启动调试器,就不会重写数据EEPROM。一旦我完成了所有这一切,我就能够写入数据EEPROM并在电源循环时看到我的数据。
 
 谢谢,
 布赖恩

以上来自于谷歌翻译


以下为原文





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
举报

更多回帖

发帖
×
20
完善资料,
赚取积分