mirror of
https://github.com/logicog/RTLPlayground.git
synced 2026-08-30 14:52:51 +08:00
Merge pull request #214 from feelfree69/flash_erase
Erase flash before writing upload image
This commit is contained in:
+9
-8
@@ -14,9 +14,6 @@
|
|||||||
#define SESSION_ID_LENGTH 12
|
#define SESSION_ID_LENGTH 12
|
||||||
#define SESSION_TIMEOUT 200
|
#define SESSION_TIMEOUT 200
|
||||||
|
|
||||||
// SPI FLASH MEMORY PAGE SIZE.
|
|
||||||
#define FLASHMEM_PAGE_SIZE 0x100
|
|
||||||
|
|
||||||
#define CMARK_S 6
|
#define CMARK_S 6
|
||||||
|
|
||||||
#pragma codeseg BANK1
|
#pragma codeseg BANK1
|
||||||
@@ -330,18 +327,22 @@ uint8_t stream_upload(uint16_t bptr)
|
|||||||
}
|
}
|
||||||
crc16(p + bptr);
|
crc16(p + bptr);
|
||||||
flash_buf[write_len++] = p[bptr++];
|
flash_buf[write_len++] = p[bptr++];
|
||||||
if (write_len >= FLASHMEM_PAGE_SIZE) {
|
if (write_len >= FLASH_PAGE_SIZE) {
|
||||||
dbg_string("len: "); dbg_short(write_len); dbg_char(' ');
|
dbg_string("len: "); dbg_short(write_len); dbg_char(' ');
|
||||||
dbg_string("CRC16: "); dbg_short(crc_value); dbg_char('\n');
|
dbg_string("CRC16: "); dbg_short(crc_value); dbg_char('\n');
|
||||||
|
if (uptr % FLASH_SECTOR_SIZE == 0) {
|
||||||
flash_region.addr = uptr;
|
flash_region.addr = uptr;
|
||||||
flash_region.len = FLASHMEM_PAGE_SIZE;
|
flash_sector_erase();
|
||||||
|
}
|
||||||
|
flash_region.addr = uptr;
|
||||||
|
flash_region.len = FLASH_PAGE_SIZE;
|
||||||
flash_write_bytes(flash_buf);
|
flash_write_bytes(flash_buf);
|
||||||
uptr += FLASHMEM_PAGE_SIZE;
|
uptr += FLASH_PAGE_SIZE;
|
||||||
write_len -= FLASHMEM_PAGE_SIZE;
|
write_len -= FLASH_PAGE_SIZE;
|
||||||
|
|
||||||
// Copy the remaining byte for the next page to the beginning of the buffer.
|
// Copy the remaining byte for the next page to the beginning of the buffer.
|
||||||
if (write_len > 0) {
|
if (write_len > 0) {
|
||||||
memcpy(flash_buf, flash_buf + FLASHMEM_PAGE_SIZE, write_len);
|
memcpy(flash_buf, flash_buf + FLASH_PAGE_SIZE, write_len);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bindex = 0;
|
bindex = 0;
|
||||||
|
|||||||
@@ -1,6 +1,16 @@
|
|||||||
#ifndef _RTL837X_FLASH_H_
|
#ifndef _RTL837X_FLASH_H_
|
||||||
#define _RTL837X_FLASH_H_
|
#define _RTL837X_FLASH_H_
|
||||||
|
|
||||||
|
// SPI FLASH MEMORY PAGE SIZE.
|
||||||
|
#define FLASH_PAGE_SIZE 0x100
|
||||||
|
// SPI FLASH MEMORY SECTOR SIZE = ERASE SIZE.
|
||||||
|
#define FLASH_SECTOR_SIZE 0x1000
|
||||||
|
|
||||||
|
#if (FLASH_SECTOR_SIZE % FLASH_PAGE_SIZE) != 0
|
||||||
|
#error "FLASH_SECTOR_SIZE must be a multiple of FLASH_PAGE_SIZE"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
void flash_init(uint8_t enable_dio);
|
void flash_init(uint8_t enable_dio);
|
||||||
void flash_read_uid(void);
|
void flash_read_uid(void);
|
||||||
void flash_write_enable(void);
|
void flash_write_enable(void);
|
||||||
|
|||||||
Reference in New Issue
Block a user