29
29
#endif
30
30
31
31
//--------------------------------------------------------------------+
32
- //
32
+ // MACRO TYPEDEF CONSTANT ENUM
33
33
//--------------------------------------------------------------------+
34
34
35
- // no caching
36
- //#define FLASH_CACHE_SIZE 4096
37
- //#define FLASH_CACHE_INVALID_ADDR 0xffffffff
38
-
39
35
#define FLASH_BASE_ADDR 0x08000000UL
40
36
41
37
// TinyUF2 resides in the first 2 flash sectors on STM32F4s, therefore these are write protected
84
80
static uint8_t erased_sectors [SECTOR_COUNT ] = { 0 };
85
81
86
82
//--------------------------------------------------------------------+
87
- //
83
+ // Internal Helper
88
84
//--------------------------------------------------------------------+
89
85
86
+ static inline uint32_t flash_sector_size (uint32_t sector )
87
+ {
88
+ return sector_size [sector ];
89
+ }
90
+
90
91
static bool is_blank (uint32_t addr , uint32_t size )
91
92
{
92
93
for ( uint32_t i = 0 ; i < size ; i += sizeof (uint32_t ) )
@@ -112,7 +113,7 @@ static bool flash_erase(uint32_t addr)
112
113
{
113
114
TUF2_ASSERT (sector_addr < FLASH_BASE_ADDR + BOARD_FLASH_SIZE );
114
115
115
- size = sector_size [ i ] ;
116
+ size = flash_sector_size ( i ) ;
116
117
if ( sector_addr + size > addr )
117
118
{
118
119
sector = i ;
@@ -170,7 +171,7 @@ static void flash_write(uint32_t dst, const uint8_t *src, int len)
170
171
}
171
172
172
173
//--------------------------------------------------------------------+
173
- //
174
+ // Board API
174
175
//--------------------------------------------------------------------+
175
176
void board_flash_init (void )
176
177
{
@@ -285,7 +286,7 @@ void board_self_update(const uint8_t * bootloader_bin, uint32_t bootloader_len)
285
286
286
287
for ( uint32_t i = 0 ; i < 4 && len > 0 ; i ++ )
287
288
{
288
- uint32_t const size = (sector_size [ i ] < len ? sector_size [ i ] : len );
289
+ uint32_t const size = (flash_sector_size ( i ) < len ? flash_sector_size ( i ) : len );
289
290
board_flash_write (sector_addr , data , size );
290
291
291
292
sector_addr += size ;
0 commit comments