Skip to content

Commit

Permalink
Support dynamic location for flash bank offset
Browse files Browse the repository at this point in the history
Fix static asserts so they don't fail to compile if the flash bank
location is inside the binary itself.

Fixes #1278
  • Loading branch information
peterharperuk committed Mar 2, 2023
1 parent 18479e0 commit dbb5bd9
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/rp2_common/pico_btstack/btstack_flash_bank.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// Check sizes
static_assert(PICO_FLASH_BANK_TOTAL_SIZE % (FLASH_SECTOR_SIZE * 2) == 0, "PICO_FLASH_BANK_TOTAL_SIZE invalid");
static_assert(PICO_FLASH_BANK_TOTAL_SIZE <= PICO_FLASH_SIZE_BYTES, "PICO_FLASH_BANK_TOTAL_SIZE too big");
static_assert(PICO_FLASH_BANK_STORAGE_OFFSET + PICO_FLASH_BANK_TOTAL_SIZE <= PICO_FLASH_SIZE_BYTES, "PICO_FLASH_BANK_TOTAL_SIZE too big");
static_assert(__builtin_constant_p(PICO_FLASH_BANK_STORAGE_OFFSET) ? PICO_FLASH_BANK_STORAGE_OFFSET + PICO_FLASH_BANK_TOTAL_SIZE <= PICO_FLASH_SIZE_BYTES : 1, "PICO_FLASH_BANK_TOTAL_SIZE too big");

// Size of one bank
#define PICO_FLASH_BANK_SIZE (PICO_FLASH_BANK_TOTAL_SIZE / 2)
Expand Down Expand Up @@ -133,11 +133,10 @@ static const hal_flash_bank_t pico_flash_bank_instance_obj = {
};

const hal_flash_bank_t *pico_flash_bank_instance(void) {

#ifndef NDEBUG
// Check we're not overlapping the binary in flash
extern char __flash_binary_end;
assert((uintptr_t)&__flash_binary_end - XIP_BASE <= PICO_FLASH_BANK_STORAGE_OFFSET);
assert(__builtin_constant_p(PICO_FLASH_BANK_STORAGE_OFFSET) ? ((uintptr_t)&__flash_binary_end - XIP_BASE <= PICO_FLASH_BANK_STORAGE_OFFSET) : true);
#endif

return &pico_flash_bank_instance_obj;
Expand Down

0 comments on commit dbb5bd9

Please sign in to comment.