File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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+
5262void 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
You can’t perform that action at this time.
0 commit comments