回复
Highlighted
发帖数: 7
注册日期: ‎06-12-2016

EFM8BB31F6​4G在应用程序中存数据到FLASH的问

把厂家提供的范例串口程序bootloader写进EFM8BB31F6​4G中,再用串口命令

efm8load.exe -t -p COM6 -b 57600 pwmapp.efm8 进行升级,没问题,可以反复断电重新启动升级,都可以,但是我一旦在应用程序执行 了save,也就是对flash地址为0x8000的一页,先进行擦除,再对其写数据后,然后再 执行升级命令,发现程序再 也不能进入bootloader程序了,对其flash进行读取,发现在flash地址0xfa00的程序没有了,感觉是擦除了,再查看了写数据之前的擦除page程序,里面有对flash地址0xfa00的擦除的程序,不知道为什么做这个擦除flash地址0xfa00的动作?把擦除flash地址0xfa00的程序注释掉,经测试还是会擦除flash地址0xfa00的程序,请大侠帮忙看看,谢谢!!

发帖数: 1,584
注册日期: ‎10-14-2014

回复: EFM8BB31F6​4G在应用程序中存数据到FLASH的问

----------------------

对其flash进行读取,发现在flash地址0xfa00的程序​没有了,感觉是擦除了,再查看了写数据之前的擦除page程序,里面有对flash地址0xfa00的擦除​的程序,不知道为什么做这个擦除flash地址0xfa00的动作?把擦除flash地址0xfa00的程​序注释掉,经测试还是会擦除flash地址0xfa00的程序,请大侠帮忙看看,谢谢

------------------------

这个很奇怪,可能还是要仔细查看为什么会把这个地址的程序擦除,能否把你们的完整程序放上来,大家看看哪里的代码值得怀疑。

 

WeiguoLu
发帖数: 7
注册日期: ‎06-12-2016

回复: EFM8BB31F6​4G在应用程序中存数据到FLASH的问

//这个源程序是从simplicity里的事例程序,对flash进行读写

 

不知道为什么要FLASH_PageErase (FLASH_TEMP);对0xfa00进行擦除!

 

void FLASH_Update (FLADDR dest, uint8_t *src, uint16_t numbytes)
{
// 1. Erase <numbytes> starting from <dest>
FLASH_Clear (dest, numbytes);

// 2. Write <numbytes> from <src> to <dest>
FLASH_Write (dest, src, numbytes);
}

 

 

#define FLASH_TEMP 0xFA00L             // For 64 kB Flash devices

 

 

void FLASH_Clear (FLADDR dest, uint16_t numbytes)
{
FLADDR dest_1_page_start; // First address in 1st page
// containing <dest>
FLADDR dest_1_page_end; // Last address in 1st page
// containing <dest>
FLADDR dest_2_page_start; // First address in 2nd page
// containing <dest>
FLADDR dest_2_page_end; // Last address in 2nd page
// containing <dest>
unsigned numbytes_remainder; // When crossing page boundary,
// number of <src> bytes on 2nd page
unsigned FLASH_pagesize; // Size of flash page to update

FLADDR wptr; // Write address
FLADDR rptr; // Read address

unsigned length;

FLASH_pagesize = FLASH_PAGESIZE;

// FLASH_PageErase (dest);
dest_1_page_start = dest & ~(FLASH_pagesize - 1);
dest_1_page_end = dest_1_page_start + FLASH_pagesize - 1;
dest_2_page_start = (dest + numbytes) & ~(FLASH_pagesize - 1);
dest_2_page_end = dest_2_page_start + FLASH_pagesize - 1;

if (dest_1_page_end == dest_2_page_end) {

// 1. Erase Scratch page
FLASH_PageErase (FLASH_TEMP);

// 2. Copy bytes from first byte of dest page to dest-1 to Scratch page

wptr = FLASH_TEMP;
rptr = dest_1_page_start;
length = dest - dest_1_page_start;
FLASH_Copy (wptr, rptr, length);

// 3. Copy from (dest+numbytes) to dest_page_end to Scratch page

wptr = FLASH_TEMP + dest - dest_1_page_start + numbytes;
rptr = dest + numbytes;
length = dest_1_page_end - dest - numbytes + 1;
FLASH_Copy (wptr, rptr, length);

// 4. Erase destination page
FLASH_PageErase (dest_1_page_start);

// 5. Copy Scratch page to destination page
wptr = dest_1_page_start;
rptr = FLASH_TEMP;
length = FLASH_pagesize;
FLASH_Copy (wptr, rptr, length);

} else { // value crosses page boundary
// 1. Erase Scratch page
FLASH_PageErase (FLASH_TEMP);

// 2. Copy bytes from first byte of dest page to dest-1 to Scratch page

wptr = FLASH_TEMP;
rptr = dest_1_page_start;
length = dest - dest_1_page_start;
FLASH_Copy (wptr, rptr, length);

// 3. Erase destination page 1
FLASH_PageErase (dest_1_page_start);

// 4. Copy Scratch page to destination page 1
wptr = dest_1_page_start;
rptr = FLASH_TEMP;
length = FLASH_pagesize;
FLASH_Copy (wptr, rptr, length);

// now handle 2nd page

// 5. Erase Scratch page
FLASH_PageErase (FLASH_TEMP);

// 6. Copy bytes from numbytes remaining to dest-2_page_end to Scratch page

numbytes_remainder = numbytes - (dest_1_page_end - dest + 1);
wptr = FLASH_TEMP + numbytes_remainder;
rptr = dest_2_page_start + numbytes_remainder;
length = FLASH_pagesize - numbytes_remainder;
FLASH_Copy (wptr, rptr, length);

// 7. Erase destination page 2
FLASH_PageErase (dest_2_page_start);

// 8. Copy Scratch page to destination page 2
wptr = dest_2_page_start;
rptr = FLASH_TEMP;
length = FLASH_pagesize;
FLASH_Copy (wptr, rptr, length);
}
}