Skip to content

Commit

Permalink
Add PICO_FLASH_BANK_FIXED_OFFSET
Browse files Browse the repository at this point in the history
Defaults to true. Can be set to false if the flash bank offset is
dynamically generated, e.g. to be inside the binary itself.

Fixes #1278
  • Loading branch information
peterharperuk committed Mar 1, 2023
1 parent 18479e0 commit ad7d3fb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/rp2_common/pico_btstack/btstack_flash_bank.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
#include "hardware/sync.h"
#include <string.h>

#if PICO_FLASH_BANK_FIXED_OFFSET
// 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");
#endif

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

const hal_flash_bank_t *pico_flash_bank_instance(void) {

#ifndef NDEBUG
#if !defined NDEBUG && PICO_FLASH_BANK_FIXED_OFFSET
// 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);
Expand Down
5 changes: 5 additions & 0 deletions src/rp2_common/pico_btstack/include/pico/btstack_flash_bank.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ extern "C" {
#define PICO_FLASH_BANK_STORAGE_OFFSET (PICO_FLASH_SIZE_BYTES - PICO_FLASH_BANK_TOTAL_SIZE)
#endif

// PICO_CONFIG: PICO_FLASH_BANK_FIXED_OFFSET, Indicates if the flash bank is at a fixed address, or else it's dynamically generated e.g. to be inside the binary itself, type=bool, default=1, group=pico_btstack
#ifndef PICO_FLASH_BANK_FIXED_OFFSET
#define PICO_FLASH_BANK_FIXED_OFFSET 1
#endif

/**
* \brief Return the singleton BTstack HAL flash instance, used for non-volatile storage
* \ingroup pico_btstack
Expand Down

0 comments on commit ad7d3fb

Please sign in to comment.