STM8L151 在IAR中实现Flash/EEPROM的擦写
2016-05-16 23:46
369 查看
在 STM8L151G6U6中可支持字节擦写和块擦写,块擦写可一次擦写很所字节。字节擦写比较简单,需要注意的是块擦写,在块擦写中,需要配置一个地方。
对于IAR来说,
Uncomment the line “#define RAM_EXECUTION (1)” in the stm8l15x.h file to enable the FLASH functions execution from RAM through the specific __ramfunc keyword.
之后可在程序中调用Flash_BlockProgram();来进行块擦写。
在main函数前要做以下声明:
之后可使用下面函数来进行擦写到epprom中,
之后编译即可,不知道是否要将工程设置为支持C标准库,可能要,测试成功的工程是做了这个设置的,大家也可以自己做一下测试
对于IAR来说,
Uncomment the line “#define RAM_EXECUTION (1)” in the stm8l15x.h file to enable the FLASH functions execution from RAM through the specific __ramfunc keyword.
之后可在程序中调用Flash_BlockProgram();来进行块擦写。
在main函数前要做以下声明:
#ifdef _RAISONANCE_ /* needed by memcpy for raisonance */ #include <string.h> extern int __address__FLASH_EraseBlock; extern int __size__FLASH_EraseBlock; extern int __address__FLASH_ProgramBlock; extern int __size__FLASH_ProgramBlock; #endif /*_RAISONANCE_*/ /* Private function prototypes -----------------------------------------------*/ /* Declare _fctcpy function prototype as it is packaged by default in the Cosmic machine library */ #ifdef _COSMIC_ int _fctcpy(char name); #endif /*_COSMIC_*/
之后可使用下面函数来进行擦写到epprom中,
void Flash_WriteDataBlock(uint8_t block_count, uint8_t *Buffer) { FLASH_Unlock(FLASH_MemType_Data);//可以擦写EEPROM或Flash:FLASH_Unlock(FLASH_MemType_Program); while (FLASH_GetFlagStatus(FLASH_FLAG_DUL) == RESET) {} FLASH_ProgramBlock(block_count, FLASH_MemType_Data, FLASH_ProgramMode_Standard, Buffer); while (FLASH_GetFlagStatus(FLASH_FLAG_HVOFF) == RESET) {} //FLASH_WaitForLastOperation(); FLASH_Lock(FLASH_MemType_Data); }
之后编译即可,不知道是否要将工程设置为支持C标准库,可能要,测试成功的工程是做了这个设置的,大家也可以自己做一下测试
相关文章推荐
- 欢迎使用CSDN-markdown编辑器
- 展开与收起效果
- 栈的链接存储——链栈
- pythonchallenge 解谜 Level 1
- 你不努力,谁也给不了你想要的生活
- 单元测试练习
- Using AngularJS with .NET MVC 5
- HTML5标签绘制渐变图形的一些总结
- 2006浙大火星A+B
- projectne10向ZedBoard移植
- 使用win2d实现萤火虫粒子效果
- http://www.doc88.com/p-7374285513754.html
- Android Studio 常用快捷键
- Add Two Numbers
- hdu_2224_The shortest path(dp)
- ZOJ 2412 Farm Irrigation
- tomcat session复制
- ZOJ 2412 Farm Irrigation
- hdu_2224_The shortest path(dp)
- 利用组合控件实现布局文件抽取复用