9S12XDT512,BANKED模式。 prm文件的主要设置参数是这样的: SEGMENTS /* here all RAM/ROM areas of the device are listed. Used in PLACEMENT below. All addresses are 'logical' */ /* Register space */ /* IO_SEG = PAGED 0x0000 TO 0x07FF; intentionally not defined */ /* non-paged EEPROM */ EEPROM = READ_ONLY 0x0C00 TO 0x0FFB; /* non-paged RAM */ RAM = READ_WRITE 0x2000 TO 0x3FFF; /* non-banked FLASH */ ROM_4000 = READ_ONLY 0x4000 TO 0x7FFF; ROM_C000 = READ_ONLY 0xC000 TO 0xFEFF; /* VECTORS = READ_ONLY 0xFF00 TO 0xFFFF; intentionally not defined: used for VECTOR commands below */ //OSVECTORS = READ_ONLY 0xFF10 TO 0xFFFF; /* OSEK interrupt vectors (use your vector.o) */ /* paged EEPROM 0x0800 TO 0x0BFF; addressed through EPAGE */ EEPROM_FC = READ_ONLY 0xFC0800 TO 0xFC0BFF; EEPROM_FD = READ_ONLY 0xFD0800 TO 0xFD0BFF; EEPROM_FE = READ_ONLY 0xFE0800 TO 0xFE0BFF; /* EEPROM_FF = READ_ONLY 0xFF0800 TO 0xFF0BFF; intentionally not defined: equivalent to EEPROM */ /* paged RAM: 0x1000 TO 0x1FFF; addressed through RPAGE */ RAM_FB = READ_WRITE 0xFB1000 TO 0xFB1FFF; RAM_FC = READ_WRITE 0xFC1000 TO 0xFC1FFF; RAM_FD = READ_WRITE 0xFD1000 TO 0xFD1FFF; /* RAM_FE = READ_WRITE 0xFE1000 TO 0xFE1FFF; intentionally not defined: equivalent to RAM: 0x2000..0x2FFF */ /* RAM_FF = READ_WRITE 0xFF1000 TO 0xFF1FFF; intentionally not defined: equivalent to RAM: 0x3000..0x3FFF */ /* paged FLASH: 0x8000 TO 0xBFFF; addressed through PPAGE */ PAGE_E0 = READ_ONLY 0xE08000 TO 0xE0BFFF; PAGE_E1 = READ_ONLY 0xE18000 TO 0xE1BFFF; PAGE_E2 = READ_ONLY 0xE28000 TO 0xE2BFFF; PAGE_E3 = READ_ONLY 0xE38000 TO 0xE3BFFF; PAGE_E4 = READ_ONLY 0xE48000 TO 0xE4BFFF; PAGE_E5 = READ_ONLY 0xE58000 TO 0xE5BFFF; PAGE_E6 = READ_ONLY 0xE68000 TO 0xE6BFFF; PAGE_E7 = READ_ONLY 0xE78000 TO 0xE7BFFF; PAGE_E8 = READ_ONLY 0xE88000 TO 0xE8BFFF; PAGE_E9 = READ_ONLY 0xE98000 TO 0xE9BFFF; PAGE_EA = READ_ONLY 0xEA8000 TO 0xEABFFF; PAGE_EB = READ_ONLY 0xEB8000 TO 0xEBBFFF; PAGE_EC = READ_ONLY 0xEC8000 TO 0xECBFFF; PAGE_ED = READ_ONLY 0xED8000 TO 0xEDBFFF; PAGE_EE = READ_ONLY 0xEE8000 TO 0xEEBFFF; PAGE_EF = READ_ONLY 0xEF8000 TO 0xEFBFFF; PAGE_F0 = READ_ONLY 0xF08000 TO 0xF0BFFF; PAGE_F1 = READ_ONLY 0xF18000 TO 0xF1BFFF; PAGE_F2 = READ_ONLY 0xF28000 TO 0xF2BFFF; PAGE_F3 = READ_ONLY 0xF38000 TO 0xF3BFFF; PAGE_F4 = READ_ONLY 0xF48000 TO 0xF4BFFF; PAGE_F5 = READ_ONLY 0xF58000 TO 0xF5BFFF; PAGE_F6 = READ_ONLY 0xF68000 TO 0xF6BFFF; PAGE_F7 = READ_ONLY 0xF78000 TO 0xF7BFFF; PAGE_F8 = READ_ONLY 0xF88000 TO 0xF8BFFF; PAGE_F9 = READ_ONLY 0xF98000 TO 0xF9BFFF; PAGE_FA = READ_ONLY 0xFA8000 TO 0xFABFFF; PAGE_FB = READ_ONLY 0xFB8000 TO 0xFBBFFF; PAGE_FC = READ_ONLY 0xFC8000 TO 0xFCBFFF; /* PAGE_FD = READ_ONLY 0xFD8000 TO 0xFDBFFF; intentionally not defined: equivalent to ROM_4000 */ PAGE_FE = READ_ONLY 0xFE8000 TO 0xFEBFFF; /* PAGE_FF = READ_ONLY 0xFF8000 TO 0xFFBFFF; intentionally not defined: equivalent to ROM_C000 */ END PLACEMENT /* here all predefined and user segments are placed into the SEGMENTS defined above. */ _PRESTART, /* Used in HIWARE format: jump to _Startup at the code start */ STARTUP, /* startup data structures */ ROM_VAR, /* constant variables */ STRINGS, /* string literals */ VIRTUAL_TABLE_SEGMENT, /* C++ virtual table segment */ //.ostext, /* eventually OSEK code */ NON_BANKED, /* runtime routines which must not be banked */ COPY /* copy down information: how to initialize variables */ /* in case you want to use ROM_4000 here as well, make sure that all files (incl. library files) are compiled with the option: -OnB=b */ INTO ROM_C000/*, ROM_4000*/; DEFAULT_ROM INTO PAGE_FE, PAGE_FB, PAGE_FA, PAGE_F9, PAGE_F8, PAGE_F7, PAGE_F6, PAGE_F5, PAGE_F4, PAGE_F3, PAGE_F2, PAGE_F1, PAGE_F0, PAGE_EF, PAGE_EE, PAGE_ED, PAGE_EC, PAGE_EB, PAGE_EA, PAGE_E9, PAGE_E8, PAGE_E7, PAGE_E6, PAGE_E5, PAGE_E4, PAGE_E3, PAGE_E2, PAGE_E1, PAGE_E0; //.stackstart, /* eventually used for OSEK kernel awareness: Main-Stack Start */ SSTACK, /* allocate stack first to avoid overwriting variables on overflow */ //.stackend, /* eventually used for OSEK kernel awareness: Main-Stack End */ DEFAULT_RAM /* all variables, the default RAM location */ INTO RAM; PAGED_RAM INTO /* when using banked addressing for variable data, make sure to specify the option -D__FAR_DATA on the compiler command line */ RAM_FB, RAM_FC;
MyRAMSection INTO RAM_FD ; //自定义一个RAM空间 MyFLASHSection INTO PAGE_FC; //自定义一个FLASH空间 //.vectors INTO OSVECTORS; /* OSEK vector table */ END 我的FLASH操作代码如下: /*************************************************
Flash初始化程序
*************************************************/ void Flash_init(void) { FCLKDIV=0x15; // 不采用8分频,因为OSCLK=4M,又为了使FCLK // 达到190KHZ,所以FDIV=21,即FCLK=4M/21=190.5KHZ FCNFG=0x00; // 禁止FLASH相关操作的中断 while(FCLKDIV_FDIVLD == 0); // 等待时钟设置成功 FPROT_FPOPEN=1; // 允许对FLASH进行编程与擦除 FPROT_FPHDIS=1; // FLASH保护禁止 FPROT_FPLDIS=1; // FLASH保护禁止 } #pragma CODE_SEG NON_BANKED /*************************************************
将指定FLASH页面的指定地址的数据擦除 page:页地址 addr:页中的指定地址
*************************************************/ void flash_erase_word(byte page,word addr) { while(!(FCLKDIV & 0x80)); //复位后时钟分频是否做出修改 while(!(FSTAT & 0x80)); //命令缓冲区是否为空 while(FSTAT & 0x30) //判断ACCERR/PVIOL是否为1 FSTAT |= 0x30; //如果是,则写1清标志位 while(!(FPROT & 0x80)); //FLASH是否允许进行编程
PPAGE = page; page=page&0x0C; page=page>>2; FCNFG = 3-page;
*((volatile word *)(addr))=Dump;//写入0xFF,擦除FLASH FCMD = 0x40; //置擦除命令 FSTAT|=0x80; while(!(FSTAT & 0x80));
while(!(FSTAT & 0x40)); //命令是否执行完毕 }
/*************************************************
向指定FLASH页面的指定地址写入一个字的数据 page:页地址 addr:页中的指定地址 data:要写入的数据
*************************************************/ void flash_write_word(byte page,word addr,word data) { while(!(FCLKDIV & 0x80)); //复位后时钟分频是否做出修改 while(!(FSTAT & 0x80)); //命令缓冲区是否为空 while(FSTAT & 0x30) //判断ACCERR/PVIOL是否为1 FSTAT |= 0x30; //如果是,则写1清标志位 while(!(FPROT & 0x80)); //FLASH是否允许进行编程
PPAGE = page; page=page&0x0C; page=page>>2; FCNFG = 3-page;
*((volatile word *)(addr))=data;//写入0xFF,擦除FLASH FCMD = 0x20; //置编程命令 FSTAT|=0x80; while(!(FSTAT & 0x80));
while(!(FSTAT & 0x40)); //命令是否执行完毕 } #pragma CODE_SEG DEFAULT 但是我调用了 flash_erase_word(0xFA,0x0000); flash_write_word(0xFA,0x0000,0xaabb); 运行之后,在BDM下,调看memory区,发现0xFA8000地址的数据还是0xFF!
[此贴子已经被作者于2008-9-19 10:52:26编辑过] |