完成flash读写以及测试
This commit is contained in:
parent
168e97ebe8
commit
07f28f3331
9 changed files with 114 additions and 89 deletions
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
<project>
|
||||
<fileVersion>2</fileVersion>
|
||||
<fileChecksum>874752655</fileChecksum>
|
||||
<fileChecksum>2489258447</fileChecksum>
|
||||
<configuration>
|
||||
<name>Debug</name>
|
||||
<outputs>
|
||||
|
|
@ -341,6 +341,8 @@
|
|||
<file>$PROJ_DIR$\..\Debug\Obj\debug.o</file>
|
||||
<file>$PROJ_DIR$\..\Debug\Obj\simulat_timer.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>
|
||||
<file>
|
||||
<name>[ROOT_NODE]</name>
|
||||
|
|
@ -402,11 +404,11 @@
|
|||
<inputs>
|
||||
<tool>
|
||||
<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>
|
||||
<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>
|
||||
</inputs>
|
||||
</file>
|
||||
|
|
@ -507,11 +509,11 @@
|
|||
<inputs>
|
||||
<tool>
|
||||
<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>
|
||||
<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>
|
||||
</inputs>
|
||||
</file>
|
||||
|
|
@ -589,11 +591,11 @@
|
|||
<inputs>
|
||||
<tool>
|
||||
<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>
|
||||
<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>
|
||||
</inputs>
|
||||
</file>
|
||||
|
|
@ -1767,7 +1769,7 @@
|
|||
<inputs>
|
||||
<tool>
|
||||
<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>
|
||||
</inputs>
|
||||
</file>
|
||||
|
|
@ -2231,10 +2233,6 @@
|
|||
</tool>
|
||||
</inputs>
|
||||
</file>
|
||||
<forcedrebuild>
|
||||
<name>$PROJ_DIR$\..\src\app\main.c</name>
|
||||
<tool>ICCARM</tool>
|
||||
</forcedrebuild>
|
||||
</configuration>
|
||||
<configuration>
|
||||
<name>Release</name>
|
||||
|
|
|
|||
|
|
@ -1966,9 +1966,6 @@
|
|||
</file>
|
||||
<file>
|
||||
<name>$PROJ_DIR$\..\src\app\main.c</name>
|
||||
<excluded>
|
||||
<configuration>Debug</configuration>
|
||||
</excluded>
|
||||
</file>
|
||||
<file>
|
||||
<name>$PROJ_DIR$\..\src\app\NormalDemo_Flash.c</name>
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
26
plan_manage_main/src/app/include/pm_flash.h
Normal file
26
plan_manage_main/src/app/include/pm_flash.h
Normal 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 */
|
||||
|
|
@ -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));
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue