Skip to content

Commit cb3b6ce

Browse files
committed
Merge git://github.com/stevie67/micropython into stevie67-master
2 parents 597bb2f + 2c62e26 commit cb3b6ce

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

stm/storage.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ static uint8_t *cache_get_addr_for_write(uint32_t flash_addr) {
4949
return (uint8_t*)CACHE_MEM_START_ADDR + flash_addr - flash_sector_start;
5050
}
5151

52+
static uint8_t *cache_get_addr_for_read(uint32_t flash_addr) {
53+
uint32_t flash_sector_start;
54+
uint32_t flash_sector_size;
55+
uint32_t flash_sector_id = flash_get_sector_info(flash_addr, &flash_sector_start, &flash_sector_size);
56+
if (cache_flash_sector_id == flash_sector_id)
57+
return (uint8_t*)CACHE_MEM_START_ADDR + flash_addr - flash_sector_start;
58+
// not in cache, copy straight from flash
59+
return (uint8_t*)flash_addr;
60+
}
61+
5262
void storage_init(void) {
5363
if (!is_initialised) {
5464
cache_flash_sector_id = 0;
@@ -131,8 +141,8 @@ bool storage_read_block(uint8_t *dest, uint32_t block) {
131141
return true;
132142

133143
} else if (FLASH_PART1_START_BLOCK <= block && block < FLASH_PART1_START_BLOCK + FLASH_PART1_NUM_BLOCKS) {
134-
// non-MBR block, just copy straight from flash
135-
uint8_t *src = (uint8_t*)FLASH_MEM_START_ADDR + (block - FLASH_PART1_START_BLOCK) * BLOCK_SIZE;
144+
uint32_t flash_addr = FLASH_MEM_START_ADDR + (block - FLASH_PART1_START_BLOCK) * BLOCK_SIZE;
145+
uint8_t *src = cache_get_addr_for_read(flash_addr);
136146
memcpy(dest, src, BLOCK_SIZE);
137147
return true;
138148

0 commit comments

Comments
 (0)