diff --git a/plan_manage_main/ewp/plan_manage_main.dep b/plan_manage_main/ewp/plan_manage_main.dep index d46baf7..1b11e30 100644 --- a/plan_manage_main/ewp/plan_manage_main.dep +++ b/plan_manage_main/ewp/plan_manage_main.dep @@ -2,7 +2,7 @@ 2 - 874752655 + 2489258447 Debug @@ -341,6 +341,8 @@ $PROJ_DIR$\..\Debug\Obj\debug.o $PROJ_DIR$\..\Debug\Obj\simulat_timer.o $PROJ_DIR$\..\Debug\Obj\display.o + $PROJ_DIR$\..\src\app\include\pm_flash_cfg.h + $PROJ_DIR$\..\src\app\include\pm_flash.h [ROOT_NODE] @@ -402,11 +404,11 @@ BICOMP - 199 196 201 194 123 108 204 200 124 211 172 173 197 198 3 291 301 290 292 293 294 114 174 298 297 327 316 309 299 303 295 302 310 319 314 311 326 312 313 304 315 318 324 307 308 + 199 196 201 194 123 108 204 200 124 211 172 173 197 198 335 291 301 290 292 293 294 114 174 298 297 327 316 309 299 303 295 302 310 319 314 311 326 312 313 304 315 318 324 307 308 ICCARM - 199 196 201 194 123 108 204 200 124 211 172 173 197 198 3 291 301 290 292 293 294 114 174 298 297 327 316 309 299 303 295 302 310 319 314 311 326 312 313 304 315 318 324 307 308 + 199 196 201 194 123 108 204 200 124 211 172 173 197 198 335 291 301 290 292 293 294 114 174 298 297 327 316 309 299 303 295 302 310 319 314 311 326 312 313 304 315 318 324 307 308 @@ -507,11 +509,11 @@ BICOMP - 203 108 204 200 124 211 172 173 174 175 114 291 301 123 290 292 293 294 298 297 327 316 309 299 303 295 302 310 319 314 311 326 312 313 304 315 318 324 307 308 183 12 6 7 13 0 10 9 + 203 108 204 200 124 211 172 173 174 175 114 291 301 123 290 292 293 294 298 297 327 316 309 299 303 295 302 310 319 314 311 326 312 313 304 315 318 324 307 308 183 12 6 7 13 0 10 9 336 ICCARM - 203 108 204 200 124 211 172 173 174 175 114 291 301 123 290 292 293 294 298 297 327 316 309 299 303 295 302 310 319 314 311 326 312 313 304 315 318 324 307 308 183 12 6 7 13 0 10 9 + 203 108 204 200 124 211 172 173 174 175 114 291 301 123 290 292 293 294 298 297 327 316 309 299 303 295 302 310 319 314 311 326 312 313 304 315 318 324 307 308 183 12 6 7 13 0 10 9 336 @@ -589,11 +591,11 @@ BICOMP - 12 123 108 204 200 124 211 172 173 6 7 299 303 1 13 0 10 9 + 12 123 108 204 200 124 211 172 173 6 7 299 303 1 13 0 10 9 336 ICCARM - 12 123 108 204 200 124 211 172 173 6 7 299 303 1 13 0 10 9 + 12 123 108 204 200 124 211 172 173 6 7 299 303 1 13 0 10 9 336 @@ -1767,7 +1769,7 @@ ILINK - 213 165 217 140 126 164 125 255 208 163 332 257 256 258 334 160 259 260 261 161 262 263 264 265 266 267 268 84 85 86 87 88 89 90 91 92 93 94 95 236 225 331 115 169 168 167 218 237 121 238 96 97 241 242 222 104 181 230 226 119 113 221 243 333 150 137 109 210 151 105 135 133 134 142 145 143 215 180 212 214 + 213 165 217 140 126 164 125 255 208 163 332 257 256 258 334 160 259 260 261 161 262 263 264 265 266 267 268 84 85 86 87 88 89 90 91 92 93 94 95 236 225 331 115 169 168 167 218 227 237 121 238 96 97 241 242 222 104 181 230 226 119 113 221 243 333 150 137 109 210 151 105 135 133 134 142 145 143 215 180 212 214 @@ -2231,10 +2233,6 @@ - - $PROJ_DIR$\..\src\app\main.c - ICCARM - Release diff --git a/plan_manage_main/ewp/plan_manage_main.ewp b/plan_manage_main/ewp/plan_manage_main.ewp index 66bd0b1..89385b5 100644 --- a/plan_manage_main/ewp/plan_manage_main.ewp +++ b/plan_manage_main/ewp/plan_manage_main.ewp @@ -1966,9 +1966,6 @@ $PROJ_DIR$\..\src\app\main.c - - Debug - $PROJ_DIR$\..\src\app\NormalDemo_Flash.c diff --git a/plan_manage_main/ewp/settings/plan_manage_main.dni b/plan_manage_main/ewp/settings/plan_manage_main.dni index 226db47..a2aa31f 100644 --- a/plan_manage_main/ewp/settings/plan_manage_main.dni +++ b/plan_manage_main/ewp/settings/plan_manage_main.dni @@ -9,7 +9,7 @@ TriggerName=main LimitSize=0 ByteLimit=50 [DebugChecksum] -Checksum=313747889 +Checksum=130347300 [CodeCoverage] Enabled=_ 0 [Exceptions] @@ -54,7 +54,7 @@ ShowSource=1 [Disassemble mode] mode=0 [Breakpoints2] -Bp0=_ 1 "EMUL_CODE" "{$PROJ_DIR$\..\src\app\flash.c}.143.5" 0 0 1 "" 0 "" 0 +Bp0=_ 0 "EMUL_CODE" "{$PROJ_DIR$\..\src\app\flash.c}.156.9" 0 0 1 "" 0 "" 0 Count=1 [Log file] LoggingEnabled=_ 0 diff --git a/plan_manage_main/src/app/flash.c b/plan_manage_main/src/app/flash.c index 6bd2e57..c2b0e4f 100644 --- a/plan_manage_main/src/app/flash.c +++ b/plan_manage_main/src/app/flash.c @@ -2,8 +2,9 @@ #include "SSD_FTFx.h" -#include "flash.h" +#include "pm_flash_cfg.h" +#define USED_SECTOR_NUM 0x01U FLASH_SSD_CONFIG flashSSDConfig = @@ -21,55 +22,49 @@ FLASH_SSD_CONFIG flashSSDConfig = #define LAUNCH_CMD_SIZE 0x80U -uint8_t buffer[BUFFER_SIZE_BYTE]; - - pFLASHCOMMANDSEQUENCE g_FlashLaunchCommand = (pFLASHCOMMANDSEQUENCE)0xFFFFFFFF; uint16_t __ram_func[LAUNCH_CMD_SIZE/2]; /* array to copy __Launch_Command func to RAM */ - -void main(void) +void pm_flash_init(void) { - uint32_t ret; /* Return code from each SSD function */ - uint32_t dest; /* Address of the target location */ - uint32_t size; - uint32_t FailAddr; - uint16_t number; /* Number of longword or phrase to be program or verify*/ - uint32_t sum; - uint32_t temp; - uint32_t i; - - - g_FlashLaunchCommand = (pFLASHCOMMANDSEQUENCE)RelocateFunction((uint32_t)__ram_func , LAUNCH_CMD_SIZE ,(uint32_t)FlashCommandSequence); + uint32_t ret; - - /************************************************************************** - * FlashInit() * - ***************************************************************************/ + g_FlashLaunchCommand = + (pFLASHCOMMANDSEQUENCE)RelocateFunction((uint32_t)__ram_func , + LAUNCH_CMD_SIZE ,(uint32_t)FlashCommandSequence); ret = FlashInit(&flashSSDConfig); if (FTFx_OK != ret) { ErrorTrap(ret); } - + return; +} + +/* + * flash_write() - 将数据写入flash + * @saddr: 要写入的数据的起始地址 + * @size: 写入数据的字节数 + * + * 这个函数的执行过程包括擦除和写入,默认的写入范围为flash的最后一个扇区,大小为 + * 1KB,如果要改变大小,改参数就可以了,注意不要覆盖了code,具体可看map文件。 + * 擦除是一次性擦除全部选择的扇区范围,所以在写入的时候要注意保存先前写入的数据 + */ +void flash_write(uint8_t *saddr, uint16_t nbyte) +{ + uint32_t ret; + uint32_t dest; + uint32_t size; + uint16_t number; + uint32_t temp; /* - * 撤销保护 + * 擦除扇区 */ - //ret = PFlashSetProtection(&flashSSDConfig, 1); - if (FTFx_OK != ret) - { - ErrorTrap(ret); - } - - - /************************************************************************** - * FlashEraseSector() and FlashVerifySection() * - ***************************************************************************/ - /* Erase several sectors on Pflash*/ - dest = flashSSDConfig.PFlashBlockBase + BYTE2WORD(flashSSDConfig.PFlashBlockSize - 0x3U * FTFx_PSECTOR_SIZE); - while ((dest + BYTE2WORD(FTFx_PSECTOR_SIZE)) <= (flashSSDConfig.PFlashBlockBase + BYTE2WORD(flashSSDConfig.PFlashBlockSize))) + dest = flashSSDConfig.PFlashBlockBase + BYTE2WORD(flashSSDConfig.PFlashBlockSize + - USED_SECTOR_NUM * FTFx_PSECTOR_SIZE); + while ((dest + BYTE2WORD(FTFx_PSECTOR_SIZE)) <= (flashSSDConfig.PFlashBlockBase + + BYTE2WORD(flashSSDConfig.PFlashBlockSize))) { size = FTFx_PSECTOR_SIZE; ret = FlashEraseSector(&flashSSDConfig, dest, size, g_FlashLaunchCommand); @@ -78,9 +73,9 @@ void main(void) ErrorTrap(ret); } - /* Verify section for several sector of PFLASH */ + /* 检验 */ number = FTFx_PSECTOR_SIZE / PRD1SEC_ALIGN_SIZE; - for(i = 0x0U; i < 0x2U; i++) + for(uint8_t i = 0x0U; i < 0x2U; i++) { ret = FlashVerifySection(&flashSSDConfig, dest, number, i, g_FlashLaunchCommand); if (FTFx_OK != ret) @@ -90,57 +85,60 @@ void main(void) } dest += BYTE2WORD(size); } - - /************************************************************************** - * FlashProgram() FlashCheckSum and FlashProgramCheck() * - ***************************************************************************/ - /* Initialize source buffer */ - for (i = 0x0U; i < BUFFER_SIZE_BYTE; i++) - { - /* Set source buffer */ - buffer[i] = 0x77; - } - - /* Program to the end location of PFLASH */ - size = BUFFER_SIZE_BYTE; - dest = flashSSDConfig.PFlashBlockBase + BYTE2WORD(flashSSDConfig.PFlashBlockSize - (uint32_t)(0x1U * FTFx_PSECTOR_SIZE)); - while ((dest + BYTE2WORD(size)) <= (flashSSDConfig.PFlashBlockBase + BYTE2WORD(flashSSDConfig.PFlashBlockSize))) + /* + * 写入数据 + */ + dest = flashSSDConfig.PFlashBlockBase + BYTE2WORD(flashSSDConfig.PFlashBlockSize + - (uint32_t)(USED_SECTOR_NUM * FTFx_PSECTOR_SIZE)); + + if ((dest + BYTE2WORD(size)) <= (flashSSDConfig.PFlashBlockBase + + BYTE2WORD(flashSSDConfig.PFlashBlockSize))) { - ret = FlashProgram(&flashSSDConfig, dest, size, \ - buffer, g_FlashLaunchCommand); + ret = FlashProgram(&flashSSDConfig, dest, nbyte, \ + saddr, g_FlashLaunchCommand); if (FTFx_OK != ret) { ErrorTrap(ret); } - /* Flash CheckSum */ - sum = temp = 0x0U; - for (i = 0x0U; i < size; i++) + /* 校验和检验 */ + uint32_t sum = temp = 0x0U; + for (uint8_t i = 0x0U; i < nbyte; i++) { - temp += buffer[i]; + temp += saddr[i]; } - ret = FlashCheckSum(&flashSSDConfig, dest, size, &sum); + ret = FlashCheckSum(&flashSSDConfig, dest, nbyte, &sum); if ((FTFx_OK != ret) || (temp != sum)) { ErrorTrap(ret); } - /* Program Check for normal and user margin levels*/ - for (i = 0x1U; i < 0x3U; i ++) + /* 正确测试 */ + uint32_t FailAddr; + for (uint8_t i = 0x1U; i < 0x3U; i ++) { - ret = FlashProgramCheck(&flashSSDConfig, dest, size, buffer, \ + ret = FlashProgramCheck(&flashSSDConfig, dest, nbyte, saddr, \ &FailAddr, i, g_FlashLaunchCommand); if (FTFx_OK != ret) { ErrorTrap(ret); } } - - dest += BYTE2WORD(BUFFER_SIZE_BYTE); } - - while(1); + return; +} + +void flash_read(uint8_t *daddr, uint8_t nbyte) +{ + uint8_t *saddr = (uint8_t *)(flashSSDConfig.PFlashBlockBase + BYTE2WORD(flashSSDConfig.PFlashBlockSize + - (uint32_t)(USED_SECTOR_NUM * FTFx_PSECTOR_SIZE))); + + for (uint16_t i = 0; i < nbyte; i++) + { + daddr[i] = saddr[i]; + } + return; } /********************************************************************* @@ -155,6 +153,7 @@ void ErrorTrap(uint32_t ret) { while (1) { - ; + printf("flash操作错误,返回码为 %d\n", ret); } -} \ No newline at end of file + return; +} diff --git a/plan_manage_main/src/app/include/pm_flash.h b/plan_manage_main/src/app/include/pm_flash.h new file mode 100644 index 0000000..048e7f5 --- /dev/null +++ b/plan_manage_main/src/app/include/pm_flash.h @@ -0,0 +1,26 @@ +/* + * pm_flash.h - flash搴旂敤妯″潡 + */ + +#ifndef PM_FLASH_H +#define PM_FLASH_H + + + +void pm_flash_init(void); + + + +void flash_write(uint8_t *saddr, uint16_t nbyte); + + +void flash_read(uint8_t *daddr, uint8_t nbyte); + + + + + + + + +#endif /* PM_FLASH_H */ diff --git a/plan_manage_main/src/app/include/flash.h b/plan_manage_main/src/app/include/pm_flash_cfg.h similarity index 100% rename from plan_manage_main/src/app/include/flash.h rename to plan_manage_main/src/app/include/pm_flash_cfg.h diff --git a/plan_manage_main/src/app/main.c b/plan_manage_main/src/app/main.c index f182a91..ff03c8d 100644 --- a/plan_manage_main/src/app/main.c +++ b/plan_manage_main/src/app/main.c @@ -12,6 +12,8 @@ #include "include/config.h" #include "include/pm_time.h" #include "include/plan_handle.h" +#include "include/pm_flash.h" + void main(void) @@ -72,10 +74,11 @@ void main(void) if (st_tcf(3) == 1) { calendar_info st = get_system_time(); + printf("%d 年 %d 月 %d 星期 %d 日 %d 时 %d 分 %d 秒\n", st.year, st.month, st.wday, st.mday, st.hour, st.min, st.sec); - printf("sec = %d\n", calendar_to_sec(&st)); + printf("sec = %d\n", calendar_to_sec(&st)); } /* diff --git a/plan_manage_main/src/app/pm_init.c b/plan_manage_main/src/app/pm_init.c index f7e5455..0be3dc7 100644 --- a/plan_manage_main/src/app/pm_init.c +++ b/plan_manage_main/src/app/pm_init.c @@ -10,6 +10,7 @@ #include "include/config.h" #include "include/pm_time.h" #include "include/plan_handle.h" +#include "include/pm_flash.h" /* @@ -24,5 +25,6 @@ void pm_init(void) tft_init(); ds1302_init(); plan_handle_init(); + pm_flash_init(); return; } diff --git a/settings/plan_manage.wsdt b/settings/plan_manage.wsdt index 57b95f3..b6e7c3c 100644 --- a/settings/plan_manage.wsdt +++ b/settings/plan_manage.wsdt @@ -49,14 +49,14 @@ - TextEditor$WS_DIR$\plan_manage_main\src\drivers\FTFx\source\CopyToRam.c000003837893789TextEditor$WS_DIR$\plan_manage_main\src\include\cpu\arm_cm0.h000005419131913TextEditor$WS_DIR$\plan_manage_main\src\drivers\FTFx\source\FlashCheckSum.c000007045954595TextEditor$WS_DIR$\plan_manage_main\src\include\drivers\FTFx\SSD_FTFx_Internal.h0000011784268426TextEditor$WS_DIR$\plan_manage_main\src\include\drivers\FTFx\user_cfg.h000000350350TextEditor$WS_DIR$\plan_manage_main\src\app\include\config.h0000018158158TextEditor$WS_DIR$\plan_manage_main\src\app\tft.c0000098400TextEditor$WS_DIR$\plan_manage_main\src\app\pm_init.c00000000TextEditor$WS_DIR$\plan_manage_main\src\include\drivers\FTFx\demo_cfg.h000003429892989TextEditor$WS_DIR$\plan_manage_main\src\drivers\uart.c0000029789758975TextEditor$WS_DIR$\plan_manage_main\src\common\io.c0000011715715TextEditor$WS_DIR$\plan_manage_main\src\common\printf.c000005721619616196TextEditor$WS_DIR$\plan_manage_main\src\cpu\vectors.c000008021472147TextEditor$WS_DIR$\plan_manage_main\src\cpu\start.c000000425425TextEditor$WS_DIR$\plan_manage_main\src\app\include\knob.h0000012341341TextEditor$WS_DIR$\plan_manage_main\src\app\knob.c000000246246TextEditor$WS_DIR$\plan_manage_main\src\app\plan_handle.c0000011916831683TextEditor$WS_DIR$\plan_manage_main\src\cpu\arm_cm0.c000003347764776TextEditor$WS_DIR$\plan_manage_main\src\cpu\crt0.s000002515515TextEditor$WS_DIR$\plan_manage_main\src\cpu\sysinit.c00000812481248TextEditor$WS_DIR$\plan_manage_main\src\include\drivers\FTFx\SSD_Types.h0000015049424942TextEditor$WS_DIR$\plan_manage_main\src\app\NormalDemo_Flash.c0000201951089410894TextEditor$WS_DIR$\plan_manage_main\src\common\uif.c0000005858TextEditor$WS_DIR$\plan_manage_main\src\drivers\FTFx\source\FlashProgramOnce.c000005035383538TextEditor$WS_DIR$\plan_manage_main\src\drivers\FTFx\source\FlashReadResource.c000003732853285TextEditor$WS_DIR$\plan_manage_main\src\drivers\FTFx\source\PFlashSwap.c000008450485048TextEditor$WS_DIR$\plan_manage_main\src\app\flash.c00000602310231026TextEditor$WS_DIR$\plan_manage_main\src\app\include\flash.h000004829872987TextEditor$WS_DIR$\plan_manage_main\src\drivers\FTFx\source\PFlashSetProtection.c000007137313731TextEditor$WS_DIR$\plan_manage_main\src\drivers\FTFx\source\FlashEraseSector.c00000110566756670100000010000001 + TextEditor$WS_DIR$\plan_manage_main\src\drivers\FTFx\source\CopyToRam.c000002537893789TextEditor$WS_DIR$\plan_manage_main\src\include\cpu\arm_cm0.h000005419131913TextEditor$WS_DIR$\plan_manage_main\src\drivers\FTFx\source\FlashCheckSum.c000007045954595TextEditor$WS_DIR$\plan_manage_main\src\include\drivers\FTFx\SSD_FTFx_Internal.h0000011784268426TextEditor$WS_DIR$\plan_manage_main\src\include\drivers\FTFx\user_cfg.h000000350350TextEditor$WS_DIR$\plan_manage_main\src\app\include\config.h0000018158158TextEditor$WS_DIR$\plan_manage_main\src\app\tft.c0000098400TextEditor$WS_DIR$\plan_manage_main\src\include\drivers\FTFx\demo_cfg.h000003429892989TextEditor$WS_DIR$\plan_manage_main\src\drivers\uart.c0000029789758975TextEditor$WS_DIR$\plan_manage_main\src\common\io.c0000011715715TextEditor$WS_DIR$\plan_manage_main\src\common\printf.c000005721619616196TextEditor$WS_DIR$\plan_manage_main\src\cpu\vectors.c000008021472147TextEditor$WS_DIR$\plan_manage_main\src\cpu\start.c000000425425TextEditor$WS_DIR$\plan_manage_main\src\app\include\knob.h0000012341341TextEditor$WS_DIR$\plan_manage_main\src\app\knob.c000000246246TextEditor$WS_DIR$\plan_manage_main\src\app\plan_handle.c0000011916831683TextEditor$WS_DIR$\plan_manage_main\src\cpu\arm_cm0.c000003347764776TextEditor$WS_DIR$\plan_manage_main\src\cpu\crt0.s000002515515TextEditor$WS_DIR$\plan_manage_main\src\cpu\sysinit.c00000812481248TextEditor$WS_DIR$\plan_manage_main\src\include\drivers\FTFx\SSD_Types.h0000015049424942TextEditor$WS_DIR$\plan_manage_main\src\app\NormalDemo_Flash.c0000201951089410894TextEditor$WS_DIR$\plan_manage_main\src\common\uif.c0000005858TextEditor$WS_DIR$\plan_manage_main\src\drivers\FTFx\source\FlashProgramOnce.c000005035383538TextEditor$WS_DIR$\plan_manage_main\src\drivers\FTFx\source\FlashReadResource.c000003732853285TextEditor$WS_DIR$\plan_manage_main\src\drivers\FTFx\source\PFlashSwap.c000008450485048TextEditor$WS_DIR$\plan_manage_main\src\app\flash.c0000011140334033TextEditor$WS_DIR$\plan_manage_main\src\app\pm_init.c000000286317TextEditor$WS_DIR$\plan_manage_main\src\app\main.c00000551777177727TextEditor$WS_DIR$\plan_manage_main\src\app\key.c00000269805980590100000010000001 - iaridepm.enu1-2-2513280-2-2200199153492274105216424709366-2-21681305-2-213071701003070234160153492275482 + iaridepm.enu1-2-2638280-2-2200199156250202648220313651731-2-22991282-2-212843011003125306517156250203666