在上一节介绍了自制OSBDM,本节介绍如何使用内部flash存储数据,对于S08来说,往往我们做产品时需要存储部分参数,为了节约成本,我们喜欢使用内部flash来替代外部的spi flash和eeprom,对于NXP S08P-Lite的驱动demo中并没有给出相应的flash驱动代码,对于新手来说,感觉自己编写是有些难度,那么我们改怎么做呢?不要担心,当然有方法,对于S08PT60来说,其flash的驱动代码是有的,后面再附件中下载即可,我介绍如何使用flash驱动例子。
我们只需要把这个驱动拷贝到我们之前的demo框架即可。 对于这个flash驱动demo,是一个驱动测试框架,我们可以测试各个功能。 - #define MAX_NO_DATA (UIF_MAX_ARGS-2)
- #define FLASH_USER_PARAM_ADDR 0xFC00
- #define EEPROM_USER_PARAM_ADDR 0x3100
- const char BANNER0[] = "\n*********************************\n";
- const char BANNER1[] = "\nWelcome to PT60 Flash/EEPROM Lab!\n";
- const char BANNER2[] = "\n*********************************\n";
- const char BANNER3[] = "Please use recommended address to play with:\n" \
- " flash address = %#04.4x\n EEPROM address = %#04.4x\n";
-
- const char PROMPT[] = "CMD> ";
- UIF_CMD UIF_CMDTAB[] =
- {
- UIF_CMD_HELP
- {"ev_fb",0,1,0,cmd_eraseverify_flash_block, "EraseVerify flash block","<address in hex>"},
- {"ev_eep",0,1,0,cmd_eraseverify_eeprom_block,"EraseVerify EEPROM block","<address in hex>"},
- {"ev_fs",0,2,0,cmd_eraseverify_flash_section,"EraseVerify flash section","<address in hex> <# of longwords>"},
- {"ev_eeps",0,2,0,cmd_eraseverify_eeprom_section, "EraseVerify EEPROM section","<address in hex> <# of bytes>"},
- {"ev_all",0,0,0,cmd_eraseverify_all, "EraseVerify all blocks",""},
- {"pg_eep",0,MAX_NO_DATA+1,0,cmd_program_eeprom, "Program EEPROM","<address in hex> <data1> [... <data100>]"},
- {"pg_f",0,MAX_NO_DATA+1,0,cmd_program_flash, "Program flash","<address in hex> <data1> [... <data100>]"},
- {"ers_eeps",0,1,0,cmd_erase_eeprom_sector, "Erase EEPROM sector","<address in hex>"},
- {"ers_fs",0,1,0,cmd_erase_flash_sector, "Erase flash sector","<address in hex>"},
- {"ers_eep",0,1,0,cmd_erase_eeprom_block, "Erase EEPROM block","<address in hex>"},
- {"ers_fb",0,1,0,cmd_erase_flash_block, "Erase flash block","<address in hex>"},
- {"ers_all",0,0,0,cmd_erase_all, "Erase all blocks",""},
- };
- UIF_SETCMD UIF_SETCMDTAB[] =
- {
- {NULL, 0,1,NULL,""},
- };
复制代码如上代码,是命令和调用对应的函数。 - void
- run_cmd (void)
- {
- /*
- * Global array of pointers to emulate C argc,argv interface
- */
- int argc;
- char *argv[UIF_MAX_ARGS + 1]; /* one extra for null terminator */
- int cmpResult;
- get_line(cmdline1);
- if (!(argc = make_argv(cmdline1,argv)))
- {
- /* no command entered, just a blank line */
- strcpy(cmdline1,cmdline2);
- argc = make_argv(cmdline1,argv);
- }
- cmdline2[0] = '\0';
- if (argc)
- {
- int i;
- for (i = 0; i < UIF_NUM_CMD; i++)
- {
- cmpResult = strcasecmp(UIF_CMDTAB[i].cmd,argv[0]);
- if (!cmpResult)
- {
- if (((argc-1) >= UIF_CMDTAB[i].min_args) &&
- ((argc-1) <= UIF_CMDTAB[i].max_args))
- {
- if (UIF_CMDTAB[i].flags & UIF_CMD_FLAG_REPEAT)
- {
- strcpy(cmdline2,argv[0]);
- }
- UIF_CMDTAB[i].func(argc,argv);
- return;
- }
- else
- {
- printf(SYNTAX,argv[0]);
- return;
- }
- }
- }
- printf(INVCMD,argv[0]);
- printf(HELPMSG);
- }
- }
复制代码run_cmd 是读取命令和解析命令运行,完成flash操作。 以上就是flash驱动的底层,具体大家看源码即可。
|