-
- #include "stm8l10x.h"
- #include "periph_io.h"
- #include "delay.h"
- extern __no_init volatile __eeprom char eep_u8;
- extern __no_init volatile __eeprom short eep_u16;
- extern __no_init volatile __eeprom long eep_u32;
- volatile char ram_u8;
- volatile short ram_u16;
- volatile long ram_u32;
- void main( void )
- {
- ram_u8=eep_u8;
- ram_u16=eep_u16;
- ram_u32=eep_u32;
-
- eep_u8=1;
- eep_u16=2;
- eep_u32=3;
-
- ram_u8=eep_u8;
- ram_u16=eep_u16;
- ram_u32=eep_u32;
-
- while(1);
- }
- #include "stm8l10x_conf.h"
- void __eeprom_write_8(unsigned short addr_eep,unsigned char data)
- {
- FLASH_WaitForLastOperation();
- FLASH_Unlock(FLASH_MemType_Data);
-
- FLASH_ProgramByte(addr_eep, data);
-
- FLASH_WaitForLastOperation();
- FLASH_Lock(FLASH_MemType_Data);
- }
- void __eeprom_write_16(unsigned short addr_eep,unsigned short data)
- {
- FLASH_WaitForLastOperation();
- FLASH_Unlock(FLASH_MemType_Data);
-
- FLASH_ProgramByte(addr_eep, data/256);
- FLASH_WaitForLastOperation();
-
- FLASH_ProgramByte(addr_eep+1, data%256);
- FLASH_WaitForLastOperation();
-
- FLASH_Lock(FLASH_MemType_Data);
- }
- void __eeprom_write_32(unsigned short addr_eep,unsigned long data)
- {
- FLASH_WaitForLastOperation();
- FLASH_Unlock(FLASH_MemType_Data);
-
- FLASH_ProgramByte(addr_eep, (unsigned char)(data>>24));
- FLASH_WaitForLastOperation();
-
- FLASH_ProgramByte(addr_eep+1, (unsigned char)(data>>16));
- FLASH_WaitForLastOperation();
-
- FLASH_ProgramByte(addr_eep+2, (unsigned char)(data>>8));
- FLASH_WaitForLastOperation();
-
- FLASH_ProgramByte(addr_eep+3, (unsigned char)(data>>0));
- FLASH_WaitForLastOperation();
-
- FLASH_Lock(FLASH_MemType_Data);
- }
- void __eeprom_write_many(unsigned short addr_eep,unsigned short size,unsigned short dummy,unsigned short addr_ram)
- {
- FLASH_WaitForLastOperation();
- FLASH_Unlock(FLASH_MemType_Data);
-
- for(unsigned short i=0;i<size;i++)
- {
- FLASH_ProgramByte(addr_eep+i, *((unsigned char *)(addr_ram)+i));
- FLASH_WaitForLastOperation();
- }
-
- FLASH_Lock(FLASH_MemType_Data);
- }
- public eep_u8
- public eep_u16
- public eep_u32
-
- SECTION `.eeprom.text`:CONST:REORDER:ROOT(0)
- eep_u8:
- DC8 0x12
-
- SECTION `.eeprom.text`:CONST:REORDER:ROOT(0)
- eep_u16:
- DC16 0x3456
- SECTION `.eeprom.text`:CONST:REORDER:ROOT(0)
- eep_u32:
- DC32 0x789ABCEE
- END
- /////////////////////////////////////////////////////////////////
- // Example ILINK command file for
- // STM8 IAR C/C++ Compiler and Assembler.
- //
- // Copyright 2010 IAR Systems AB.
- //
- // $Revision$
- //
- /////////////////////////////////////////////////////////////////
- define memory with size = 16M;
- define region TinyData = [from 0x00 to 0xFF];
- define region NearData = [from 0x0000 to 0x05FF];
- define region NearFuncCode = [from 0x8000 to 0x9FFF];
- define region FarFuncCode = [from 0x8000 to 0x9FFF];
- define region HugeFuncCode = [from 0x8000 to 0x9FFF];
- define region Eeprom = [from 0x9800 to 0x9FFF];
- /////////////////////////////////////////////////////////////////
- define block CSTACK with size = _CSTACK_SIZE {};
- define block HEAP with size = _HEAP_SIZE {};
- define block INTVEC with size = 0x80 { ro section .intvec };
- // Initialization
- initialize by copy { rw section .far.bss,
- rw section .far.data,
- rw section .far_func.textrw,
- rw section .huge.bss,
- rw section .huge.data,
- rw section .huge_func.textrw,
- rw section .iar.dynexit,
- rw section .near.bss,
- rw section .near.data,
- rw section .near_func.textrw,
- rw section .tiny.bss,
- rw section .tiny.data,
- ro section .tiny.rodata };
- do not initialize { rw section .far.noinit,
- rw section .huge.noinit,
- rw section .near.noinit,
- rw section .tiny.noinit,
- rw section .vregs };
- // Placement
- place at start of TinyData { rw section .vregs };
- place in TinyData { rw section .tiny.bss,
- rw section .tiny.data,
- rw section .tiny.noinit,
- rw section .tiny.rodata };
- place at end of NearData { block CSTACK };
- place in NearData { block HEAP,
- rw section .far.bss,
- rw section .far.data,
- rw section .far.noinit,
- rw section .far_func.textrw,
- rw section .huge.bss,
- rw section .huge.data,
- rw section .huge.noinit,
- rw section .huge_func.textrw,
- rw section .iar.dynexit,
- rw section .near.bss,
- rw section .near.data,
- rw section .near.noinit,
- rw section .near_func.textrw };
- place at start of NearFuncCode { block INTVEC };
- place in NearFuncCode { ro section .far.data_init,
- ro section .far_func.textrw_init,
- ro section .huge.data_init,
- ro section .huge_func.textrw_init,
- ro section .iar.init_table,
- ro section .init_array,
- ro section .near.data_init,
- ro section .near.rodata,
- ro section .near_func.text,
- ro section .near_func.textrw_init,
- ro section .tiny.data_init,
- ro section .tiny.rodata_init };
- place in FarFuncCode { ro section .far.rodata,
- ro section .far_func.text };
- place in HugeFuncCode { ro section .huge.rodata,
- ro section .huge_func.text };
-
- place at end of Eeprom { rw section .eeprom.noinit ,
- ro section .eeprom.text,
- ro section .eeprom.textrw_init };