完成flash读写以及测试

This commit is contained in:
forbelief 2016-04-22 16:13:24 +08:00
parent 168e97ebe8
commit 07f28f3331
9 changed files with 114 additions and 89 deletions

View file

@ -2,7 +2,7 @@
<project> <project>
<fileVersion>2</fileVersion> <fileVersion>2</fileVersion>
<fileChecksum>874752655</fileChecksum> <fileChecksum>2489258447</fileChecksum>
<configuration> <configuration>
<name>Debug</name> <name>Debug</name>
<outputs> <outputs>
@ -341,6 +341,8 @@
<file>$PROJ_DIR$\..\Debug\Obj\debug.o</file> <file>$PROJ_DIR$\..\Debug\Obj\debug.o</file>
<file>$PROJ_DIR$\..\Debug\Obj\simulat_timer.o</file> <file>$PROJ_DIR$\..\Debug\Obj\simulat_timer.o</file>
<file>$PROJ_DIR$\..\Debug\Obj\display.o</file> <file>$PROJ_DIR$\..\Debug\Obj\display.o</file>
<file>$PROJ_DIR$\..\src\app\include\pm_flash_cfg.h</file>
<file>$PROJ_DIR$\..\src\app\include\pm_flash.h</file>
</outputs> </outputs>
<file> <file>
<name>[ROOT_NODE]</name> <name>[ROOT_NODE]</name>
@ -402,11 +404,11 @@
<inputs> <inputs>
<tool> <tool>
<name>BICOMP</name> <name>BICOMP</name>
<file> 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</file> <file> 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</file>
</tool> </tool>
<tool> <tool>
<name>ICCARM</name> <name>ICCARM</name>
<file> 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</file> <file> 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</file>
</tool> </tool>
</inputs> </inputs>
</file> </file>
@ -507,11 +509,11 @@
<inputs> <inputs>
<tool> <tool>
<name>BICOMP</name> <name>BICOMP</name>
<file> 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</file> <file> 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</file>
</tool> </tool>
<tool> <tool>
<name>ICCARM</name> <name>ICCARM</name>
<file> 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</file> <file> 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</file>
</tool> </tool>
</inputs> </inputs>
</file> </file>
@ -589,11 +591,11 @@
<inputs> <inputs>
<tool> <tool>
<name>BICOMP</name> <name>BICOMP</name>
<file> 12 123 108 204 200 124 211 172 173 6 7 299 303 1 13 0 10 9</file> <file> 12 123 108 204 200 124 211 172 173 6 7 299 303 1 13 0 10 9 336</file>
</tool> </tool>
<tool> <tool>
<name>ICCARM</name> <name>ICCARM</name>
<file> 12 123 108 204 200 124 211 172 173 6 7 299 303 1 13 0 10 9</file> <file> 12 123 108 204 200 124 211 172 173 6 7 299 303 1 13 0 10 9 336</file>
</tool> </tool>
</inputs> </inputs>
</file> </file>
@ -1767,7 +1769,7 @@
<inputs> <inputs>
<tool> <tool>
<name>ILINK</name> <name>ILINK</name>
<file> 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</file> <file> 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</file>
</tool> </tool>
</inputs> </inputs>
</file> </file>
@ -2231,10 +2233,6 @@
</tool> </tool>
</inputs> </inputs>
</file> </file>
<forcedrebuild>
<name>$PROJ_DIR$\..\src\app\main.c</name>
<tool>ICCARM</tool>
</forcedrebuild>
</configuration> </configuration>
<configuration> <configuration>
<name>Release</name> <name>Release</name>

View file

@ -1966,9 +1966,6 @@
</file> </file>
<file> <file>
<name>$PROJ_DIR$\..\src\app\main.c</name> <name>$PROJ_DIR$\..\src\app\main.c</name>
<excluded>
<configuration>Debug</configuration>
</excluded>
</file> </file>
<file> <file>
<name>$PROJ_DIR$\..\src\app\NormalDemo_Flash.c</name> <name>$PROJ_DIR$\..\src\app\NormalDemo_Flash.c</name>

View file

@ -9,7 +9,7 @@ TriggerName=main
LimitSize=0 LimitSize=0
ByteLimit=50 ByteLimit=50
[DebugChecksum] [DebugChecksum]
Checksum=313747889 Checksum=130347300
[CodeCoverage] [CodeCoverage]
Enabled=_ 0 Enabled=_ 0
[Exceptions] [Exceptions]
@ -54,7 +54,7 @@ ShowSource=1
[Disassemble mode] [Disassemble mode]
mode=0 mode=0
[Breakpoints2] [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 Count=1
[Log file] [Log file]
LoggingEnabled=_ 0 LoggingEnabled=_ 0

View file

@ -2,8 +2,9 @@
#include "SSD_FTFx.h" #include "SSD_FTFx.h"
#include "flash.h" #include "pm_flash_cfg.h"
#define USED_SECTOR_NUM 0x01U
FLASH_SSD_CONFIG flashSSDConfig = FLASH_SSD_CONFIG flashSSDConfig =
@ -21,55 +22,49 @@ FLASH_SSD_CONFIG flashSSDConfig =
#define LAUNCH_CMD_SIZE 0x80U #define LAUNCH_CMD_SIZE 0x80U
uint8_t buffer[BUFFER_SIZE_BYTE];
pFLASHCOMMANDSEQUENCE g_FlashLaunchCommand = (pFLASHCOMMANDSEQUENCE)0xFFFFFFFF; pFLASHCOMMANDSEQUENCE g_FlashLaunchCommand = (pFLASHCOMMANDSEQUENCE)0xFFFFFFFF;
uint16_t __ram_func[LAUNCH_CMD_SIZE/2]; /* array to copy __Launch_Command func to RAM */ uint16_t __ram_func[LAUNCH_CMD_SIZE/2]; /* array to copy __Launch_Command func to RAM */
void pm_flash_init(void)
void main(void)
{ {
uint32_t ret; /* Return code from each SSD function */ uint32_t ret;
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 =
g_FlashLaunchCommand = (pFLASHCOMMANDSEQUENCE)RelocateFunction((uint32_t)__ram_func , LAUNCH_CMD_SIZE ,(uint32_t)FlashCommandSequence); (pFLASHCOMMANDSEQUENCE)RelocateFunction((uint32_t)__ram_func ,
LAUNCH_CMD_SIZE ,(uint32_t)FlashCommandSequence);
/**************************************************************************
* FlashInit() *
***************************************************************************/
ret = FlashInit(&flashSSDConfig); ret = FlashInit(&flashSSDConfig);
if (FTFx_OK != ret) if (FTFx_OK != ret)
{ {
ErrorTrap(ret); ErrorTrap(ret);
} }
return;
}
/*
* flash_write() - flash
* @saddr:
* @size:
*
* flash的最后一个扇区
* 1KBcodemap文件
*
*/
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); dest = flashSSDConfig.PFlashBlockBase + BYTE2WORD(flashSSDConfig.PFlashBlockSize
if (FTFx_OK != ret) - USED_SECTOR_NUM * FTFx_PSECTOR_SIZE);
{ while ((dest + BYTE2WORD(FTFx_PSECTOR_SIZE)) <= (flashSSDConfig.PFlashBlockBase
ErrorTrap(ret); + BYTE2WORD(flashSSDConfig.PFlashBlockSize)))
}
/**************************************************************************
* 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)))
{ {
size = FTFx_PSECTOR_SIZE; size = FTFx_PSECTOR_SIZE;
ret = FlashEraseSector(&flashSSDConfig, dest, size, g_FlashLaunchCommand); ret = FlashEraseSector(&flashSSDConfig, dest, size, g_FlashLaunchCommand);
@ -78,9 +73,9 @@ void main(void)
ErrorTrap(ret); ErrorTrap(ret);
} }
/* Verify section for several sector of PFLASH */ /* 检验 */
number = FTFx_PSECTOR_SIZE / PRD1SEC_ALIGN_SIZE; 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); ret = FlashVerifySection(&flashSSDConfig, dest, number, i, g_FlashLaunchCommand);
if (FTFx_OK != ret) if (FTFx_OK != ret)
@ -91,56 +86,59 @@ void main(void)
dest += BYTE2WORD(size); dest += BYTE2WORD(size);
} }
/************************************************************************** /*
* FlashProgram() FlashCheckSum and FlashProgramCheck() * *
***************************************************************************/ */
/* Initialize source buffer */ dest = flashSSDConfig.PFlashBlockBase + BYTE2WORD(flashSSDConfig.PFlashBlockSize
for (i = 0x0U; i < BUFFER_SIZE_BYTE; i++) - (uint32_t)(USED_SECTOR_NUM * FTFx_PSECTOR_SIZE));
{
/* Set source buffer */
buffer[i] = 0x77;
}
/* Program to the end location of PFLASH */ if ((dest + BYTE2WORD(size)) <= (flashSSDConfig.PFlashBlockBase
size = BUFFER_SIZE_BYTE; + BYTE2WORD(flashSSDConfig.PFlashBlockSize)))
dest = flashSSDConfig.PFlashBlockBase + BYTE2WORD(flashSSDConfig.PFlashBlockSize - (uint32_t)(0x1U * FTFx_PSECTOR_SIZE));
while ((dest + BYTE2WORD(size)) <= (flashSSDConfig.PFlashBlockBase + BYTE2WORD(flashSSDConfig.PFlashBlockSize)))
{ {
ret = FlashProgram(&flashSSDConfig, dest, size, \ ret = FlashProgram(&flashSSDConfig, dest, nbyte, \
buffer, g_FlashLaunchCommand); saddr, g_FlashLaunchCommand);
if (FTFx_OK != ret) if (FTFx_OK != ret)
{ {
ErrorTrap(ret); ErrorTrap(ret);
} }
/* Flash CheckSum */ /* 校验和检验 */
sum = temp = 0x0U; uint32_t sum = temp = 0x0U;
for (i = 0x0U; i < size; i++) 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)) if ((FTFx_OK != ret) || (temp != sum))
{ {
ErrorTrap(ret); 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); &FailAddr, i, g_FlashLaunchCommand);
if (FTFx_OK != ret) if (FTFx_OK != ret)
{ {
ErrorTrap(ret); ErrorTrap(ret);
} }
} }
dest += BYTE2WORD(BUFFER_SIZE_BYTE);
} }
return;
}
while(1); 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) while (1)
{ {
; printf("flash操作错误返回码为 %d\n", ret);
} }
return;
} }

View file

@ -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 */

View file

@ -12,6 +12,8 @@
#include "include/config.h" #include "include/config.h"
#include "include/pm_time.h" #include "include/pm_time.h"
#include "include/plan_handle.h" #include "include/plan_handle.h"
#include "include/pm_flash.h"
void main(void) void main(void)
@ -72,6 +74,7 @@ void main(void)
if (st_tcf(3) == 1) if (st_tcf(3) == 1)
{ {
calendar_info st = get_system_time(); calendar_info st = get_system_time();
printf("%d 年 %d 月 %d 星期 %d 日 %d 时 %d 分 %d 秒\n", printf("%d 年 %d 月 %d 星期 %d 日 %d 时 %d 分 %d 秒\n",
st.year, st.month, st.wday, st.mday, st.year, st.month, st.wday, st.mday,
st.hour, st.min, st.sec); st.hour, st.min, st.sec);

View file

@ -10,6 +10,7 @@
#include "include/config.h" #include "include/config.h"
#include "include/pm_time.h" #include "include/pm_time.h"
#include "include/plan_handle.h" #include "include/plan_handle.h"
#include "include/pm_flash.h"
/* /*
@ -24,5 +25,6 @@ void pm_init(void)
tft_init(); tft_init();
ds1302_init(); ds1302_init();
plan_handle_init(); plan_handle_init();
pm_flash_init();
return; return;
} }

File diff suppressed because one or more lines are too long