本帖最后由 sj0611002269 于 2012-3-28 13:56 编辑
写了个stm8l52c6 的block读写代码,用的是IAR.按照官方提示步骤更改过RAM方面的配置:
- For IAR Compiler:
1- Define a location FLASH_CODE before each code function by the mean of
" #pragma location = "FLASH_CODE"".
This location is defined in the stm8l15x_flash.c file, and it's conditionned
by IAR_RAM_EXECUTION definifition.
2- Uncomment the "#define IAR_RAM_EXECUTION (1)" line in the stm8l15x.h file,
or define it in IAR compiler preprocessor to enable the FLASH_CODE location
definition.
3- Edit the linker file lnkstm8l15xxx.icf available under
"$\IAR Systems\Embedded Workbench 6.0\stm8\config\lnkstm8l15xxx.icf"
by updating the line "initialize by copy { rw, ro section .tiny.rodata };"
with the the following one:
"initialize by copy { rw, ro section .tiny.rodata, section FLASH_CODE};".
4- The speed optimization is required to ensure proper execution from RAM.
-> In IAR Embedded workbench IDE Select Project\Options\C/C++ Compiler\Optimizations
select speed optimization
下面是代码:
#include "stm8l15x.h"
#define Flash_Block_Size 128
void Clock_Init(void);
void Flash_Eeprom_Rradwrite_Init(void);
void Flash_Eeprom_Readwrite_Test(void);
void main(void)
{
/*设置内部时钟16M为主时钟*/
Clock_Init();
Flash_Eeprom_Rradwrite_Init();
Flash_Eeprom_Readwrite_Test();
enableInterrupts();
FLASH_Lock(FLASH_MemType_Data);
}
void Clock_Init(void)
{
CLK_HSICmd(ENABLE);
CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_HSI);
CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_1);
}
void Flash_Eeprom_Rradwrite_Init(void)
{
FLASH_SetProgrammingTime(FLASH_ProgramTime_Standard);
FLASH_Unlock(FLASH_MemType_Data);
}
void Flash_Eeprom_Readwrite_Test(void)
{
ErrorStatus OperationStatus;
u32 add,start_add=0,stop_add=0;
u16 block;
u8 i=0;
u8 WriteBuffer[Flash_Block_Size];
/*Flash_EEprom write and read */
/*fill the buffer in RAM */
for (i=0;i<Flash_Block_Size;i++)WriteBuffer=0x12;
/*block 0 is the first block of Data memor :address is 0x1000*/
block=0;
FLASH_ProgramBlock(block,FLASH_MemType_Data,FLASH_ProgramMode_Standard, WriteBuffer);
FLASH_WaitForLastOperation(FLASH_MemType_Data);
/*check the programed block*/
start_add = FLASH_DATA_EEPROM_START_PHYSICAL_ADDRESS;
stop_add= FLASH_DATA_EEPROM_START_PHYSICAL_ADDRESS + (u32)Flash_Block_Size;
for (add = start_add;add<stop_add;add++)
{
if(FLASH_ReadByte(add) != 0x12)
/*error*/
OperationStatus = ERROR;
else
OperationStatus = SUCCESS;
}
}
问题:make 时出现error
Error[Lc036]: no block or place matches the pattern "ro code section FLASH_CODE_init in stm8l15x_flash.o"
Error[Lc036]: no block or place matches the pattern "rw code section FLASH_CODE in stm8l15x_flash.o"
哪位大侠能帮助解决呀!搞了一上午了。。。 |