12
12
// Check sizes
13
13
static_assert (PICO_FLASH_BANK_TOTAL_SIZE % (FLASH_SECTOR_SIZE * 2 ) == 0 , "PICO_FLASH_BANK_TOTAL_SIZE invalid" );
14
14
static_assert (PICO_FLASH_BANK_TOTAL_SIZE <= PICO_FLASH_SIZE_BYTES , "PICO_FLASH_BANK_TOTAL_SIZE too big" );
15
- static_assert (PICO_FLASH_BANK_STORAGE_OFFSET + PICO_FLASH_BANK_TOTAL_SIZE <= PICO_FLASH_SIZE_BYTES , "PICO_FLASH_BANK_TOTAL_SIZE too big" );
16
15
17
16
// Size of one bank
18
17
#define PICO_FLASH_BANK_SIZE (PICO_FLASH_BANK_TOTAL_SIZE / 2)
@@ -48,12 +47,27 @@ static void pico_flash_bank_perform_flash_mutation_operation(void *param) {
48
47
}
49
48
}
50
49
50
+ #ifndef pico_flash_bank_get_storage_offset_func
51
+ static inline uint32_t pico_flash_bank_get_fixed_storage_offset (void ) {
52
+ static_assert (PICO_FLASH_BANK_STORAGE_OFFSET + PICO_FLASH_BANK_TOTAL_SIZE <= PICO_FLASH_SIZE_BYTES , "PICO_FLASH_BANK_TOTAL_SIZE too big" );
53
+ #ifndef NDEBUG
54
+ // Check we're not overlapping the binary in flash
55
+ extern char __flash_binary_end ;
56
+ assert (((uintptr_t )& __flash_binary_end - XIP_BASE <= PICO_FLASH_BANK_STORAGE_OFFSET ));
57
+ #endif
58
+ return PICO_FLASH_BANK_STORAGE_OFFSET ;
59
+ }
60
+ #define pico_flash_bank_get_storage_offset_func pico_flash_bank_get_fixed_storage_offset
61
+ #else
62
+ extern uint32_t pico_flash_bank_get_storage_offset_func (void );
63
+ #endif
64
+
51
65
static void pico_flash_bank_erase (void * context , int bank ) {
52
66
(void )(context );
53
67
DEBUG_PRINT ("erase: bank %d\n" , bank );
54
68
mutation_operation_t mop = {
55
69
.op_is_erase = true,
56
- .p0 = PICO_FLASH_BANK_STORAGE_OFFSET + (PICO_FLASH_BANK_SIZE * bank ),
70
+ .p0 = pico_flash_bank_get_storage_offset_func () + (PICO_FLASH_BANK_SIZE * bank ),
57
71
};
58
72
// todo choice of timeout and check return code... currently we have no way to return an error
59
73
// to the caller anyway. flash_safe_execute asserts by default on problem other than timeout,
@@ -75,7 +89,7 @@ static void pico_flash_bank_read(void *context, int bank, uint32_t offset, uint8
75
89
if ((offset + size ) > PICO_FLASH_BANK_SIZE ) return ;
76
90
77
91
// Flash is xip
78
- memcpy (buffer , (void * )(XIP_BASE + PICO_FLASH_BANK_STORAGE_OFFSET + (PICO_FLASH_BANK_SIZE * bank ) + offset ), size );
92
+ memcpy (buffer , (void * )(XIP_BASE + pico_flash_bank_get_storage_offset_func () + (PICO_FLASH_BANK_SIZE * bank ) + offset ), size );
79
93
}
80
94
81
95
static void pico_flash_bank_write (void * context , int bank , uint32_t offset , const uint8_t * data , uint32_t size ) {
@@ -94,7 +108,7 @@ static void pico_flash_bank_write(void * context, int bank, uint32_t offset, con
94
108
if (size == 0 ) return ;
95
109
96
110
// calc bank start position
97
- const uint32_t bank_start_pos = PICO_FLASH_BANK_STORAGE_OFFSET + (PICO_FLASH_BANK_SIZE * bank );
111
+ const uint32_t bank_start_pos = pico_flash_bank_get_storage_offset_func () + (PICO_FLASH_BANK_SIZE * bank );
98
112
99
113
// Calculate first and last page in the bank
100
114
const uint32_t first_page = offset / FLASH_PAGE_SIZE ;
@@ -159,12 +173,5 @@ static const hal_flash_bank_t pico_flash_bank_instance_obj = {
159
173
};
160
174
161
175
const hal_flash_bank_t * pico_flash_bank_instance (void ) {
162
-
163
- #ifndef NDEBUG
164
- // Check we're not overlapping the binary in flash
165
- extern char __flash_binary_end ;
166
- assert ((uintptr_t )& __flash_binary_end - XIP_BASE <= PICO_FLASH_BANK_STORAGE_OFFSET );
167
- #endif
168
-
169
176
return & pico_flash_bank_instance_obj ;
170
177
}
0 commit comments