Skip to content

Commit dedbb74

Browse files
committed
increase app reserved size to 40KB to match circuitpython for 840
along with other clean up
1 parent eae1980 commit dedbb74

File tree

5 files changed

+30
-29
lines changed

5 files changed

+30
-29
lines changed

Makefile

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,17 @@ ifeq ($(MCU_SUB_VARIANT),nrf52)
104104
SD_NAME = s132
105105
DFU_DEV_REV = 0xADAF
106106
CFLAGS += -DNRF52 -DNRF52832_XXAA -DS132
107+
CFLAGS += -DDFU_APP_DATA_RESERVED=7*4096
107108
else ifeq ($(MCU_SUB_VARIANT),nrf52833)
108109
SD_NAME = s140
109110
DFU_DEV_REV = 52840
110111
CFLAGS += -DNRF52833_XXAA -DS140
112+
CFLAGS += -DDFU_APP_DATA_RESERVED=7*4096
111113
else ifeq ($(MCU_SUB_VARIANT),nrf52840)
112114
SD_NAME = s140
113115
DFU_DEV_REV = 52840
114116
CFLAGS += -DNRF52840_XXAA -DS140
117+
CFLAGS += -DDFU_APP_DATA_RESERVED=10*4096
115118
else
116119
$(error Sub Variant $(MCU_SUB_VARIANT) is unknown)
117120
endif
@@ -232,15 +235,6 @@ IPATH += $(SD_PATH)/$(SD_FILENAME)_API/include/nrf52
232235
# Compiler Flags
233236
#------------------------------------------------------------------------------
234237

235-
# Debug option use RTT for printf
236-
ifeq ($(DEBUG), 1)
237-
RTT_SRC = lib/SEGGER_RTT
238-
239-
CFLAGS += -DCFG_DEBUG -DSEGGER_RTT_MODE_DEFAULT=SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL
240-
IPATH += $(RTT_SRC)/RTT
241-
C_SRC += $(RTT_SRC)/RTT/SEGGER_RTT.c
242-
endif
243-
244238
#flags common to all targets
245239
CFLAGS += \
246240
-mthumb \
@@ -286,14 +280,21 @@ ifneq ($(USE_NFCT),yes)
286280
endif
287281

288282
CFLAGS += -DSOFTDEVICE_PRESENT
289-
CFLAGS += -DDFU_APP_DATA_RESERVED=7*4096
290-
291283
CFLAGS += -DUF2_VERSION='"$(GIT_VERSION) $(GIT_SUBMODULE_VERSIONS)"'
292284
CFLAGS += -DBLEDIS_FW_VERSION='"$(GIT_VERSION) $(SD_NAME) $(SD_VERSION)"'
293285

294286
_VER = $(subst ., ,$(word 1, $(subst -, ,$(GIT_VERSION))))
295287
CFLAGS += -DMK_BOOTLOADER_VERSION='($(word 1,$(_VER)) << 16) + ($(word 2,$(_VER)) << 8) + $(word 3,$(_VER))'
296288

289+
# Debug option use RTT for printf
290+
ifeq ($(DEBUG), 1)
291+
RTT_SRC = lib/SEGGER_RTT
292+
293+
CFLAGS += -DCFG_DEBUG -DCFG_TUSB_DEBUG=1 -DSEGGER_RTT_MODE_DEFAULT=SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL
294+
IPATH += $(RTT_SRC)/RTT
295+
C_SRC += $(RTT_SRC)/RTT/SEGGER_RTT.c
296+
endif
297+
297298
#------------------------------------------------------------------------------
298299
# Linker Flags
299300
#------------------------------------------------------------------------------

lib/sdk11/components/libraries/bootloader_dfu/dfu_types.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ static inline bool is_sd_existed(void)
4747
#define SOFTDEVICE_REGION_START MBR_SIZE /**< This field should correspond to start address of the bootloader, found in UICR.RESERVED, 0x10001014, register. This value is used for sanity check, so the bootloader will fail immediately if this value differs from runtime value. The value is used to determine max application size for updating. */
4848
#define CODE_PAGE_SIZE 0x1000 /**< Size of a flash codepage. Used for size of the reserved flash space in the bootloader region. Will be runtime checked against NRF_UICR->CODEPAGESIZE to ensure the region is correct. */
4949

50-
// Flash = 512 KB
5150
#if defined(NRF52832_XXAA) || defined(NRF52833_XXAA)
51+
// Flash = 512 KB
5252
#define BOOTLOADER_REGION_START 0x00074000 /**< This field should correspond to start address of the bootloader, found in UICR.RESERVED, 0x10001014, register. This value is used for sanity check, so the bootloader will fail immediately if this value differs from runtime value. The value is used to determine max application size for updating. */
5353
#define BOOTLOADER_MBR_PARAMS_PAGE_ADDRESS 0x0007E000 /**< The field specifies the page location of the mbr params page address. */
5454
#define BOOTLOADER_SETTINGS_ADDRESS 0x0007F000 /**< The field specifies the page location of the bootloader settings address. */
5555

56-
// Flash = 1024 KB
5756
#elif defined(NRF52840_XXAA)
57+
// Flash = 1024 KB
5858
#define BOOTLOADER_REGION_START 0x000F4000 /**< This field should correspond to start address of the bootloader, found in UICR.RESERVED, 0x10001014, register. This value is used for sanity check, so the bootloader will fail immediately if this value differs from runtime value. The value is used to determine max application size for updating. */
5959
#define BOOTLOADER_MBR_PARAMS_PAGE_ADDRESS 0x000FE000 /**< The field specifies the page location of the mbr params page address. */
6060
#define BOOTLOADER_SETTINGS_ADDRESS 0x000FF000 /**< The field specifies the page location of the bootloader settings address. */
@@ -66,7 +66,7 @@ static inline bool is_sd_existed(void)
6666
#define DFU_REGION_TOTAL_SIZE (BOOTLOADER_REGION_START - CODE_REGION_1_START) /**< Total size of the region between SD and Bootloader. */
6767

6868
#ifndef DFU_APP_DATA_RESERVED
69-
#define DFU_APP_DATA_RESERVED CODE_PAGE_SIZE*7 /**< Size of Application Data that must be preserved between application updates. This value must be a multiple of page size. Page size is 0x400 (1024d) bytes, thus this value must be 0x0000, 0x0400, 0x0800, 0x0C00, 0x1000, etc. */
69+
#error "DFU_APP_DATA_RESERVED is not defined"
7070
#endif
7171

7272
#define DFU_IMAGE_MAX_SIZE_FULL (DFU_REGION_TOTAL_SIZE - DFU_APP_DATA_RESERVED) /**< Maximum size of an application, excluding save data from the application. */

linker/nrf52840.ld

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ MEMORY
1111
* those values do not match. The check is performed in main.c, see
1212
* APP_ERROR_CHECK_BOOL(*((uint32_t *)NRF_UICR_BOOT_START_ADDRESS) == BOOTLOADER_REGION_START);
1313
*/
14-
FLASH (rx) : ORIGIN = 0xF4000, LENGTH = 0xFE000-0xF4000-2048 /* 38 KB */
14+
FLASH (rx) : ORIGIN = 0xF4000, LENGTH = 0xFE000-0xF4000 - 2K /* 38 KB */
1515

16-
BOOTLOADER_CONFIG (r): ORIGIN = 0xFE000 - 2048, LENGTH = 2048
16+
BOOTLOADER_CONFIG (r): ORIGIN = 0xFE000 - 2K, LENGTH = 2K
1717

1818
/** Location of mbr params page in flash. */
1919
MBR_PARAMS_PAGE (rw) : ORIGIN = 0xFE000, LENGTH = 0x1000

src/main.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,8 @@ int main(void)
197197
{
198198
led_state(STATE_WRITING_STARTED);
199199

200-
APP_ERROR_CHECK( bootloader_dfu_sd_update_continue() );
201-
APP_ERROR_CHECK( bootloader_dfu_sd_update_finalize() );
200+
bootloader_dfu_sd_update_continue();
201+
bootloader_dfu_sd_update_finalize();
202202

203203
led_state(STATE_WRITING_FINISHED);
204204
}
@@ -264,12 +264,12 @@ int main(void)
264264
if (APP_ASKS_FOR_SINGLE_TAP_RESET() || uf2_dfu || serial_only_dfu)
265265
{
266266
// If USB is not enumerated in 3s (eg. because we're running on battery), we restart into app.
267-
APP_ERROR_CHECK( bootloader_dfu_start(_ota_dfu, 3000, true) );
267+
bootloader_dfu_start(_ota_dfu, 3000, true);
268268
}
269269
else
270270
{
271271
// No timeout if bootloader requires user action (double-reset).
272-
APP_ERROR_CHECK( bootloader_dfu_start(_ota_dfu, 0, false) );
272+
bootloader_dfu_start(_ota_dfu, 0, false);
273273
}
274274

275275
if ( _ota_dfu )
@@ -328,7 +328,7 @@ static uint32_t softdev_init(bool init_softdevice)
328328
if (init_softdevice) softdev_mbr_init();
329329

330330
// Forward vector table to bootloader address so that we can handle BLE events
331-
APP_ERROR_CHECK( sd_softdevice_vector_table_base_set(BOOTLOADER_REGION_START) );
331+
sd_softdevice_vector_table_base_set(BOOTLOADER_REGION_START);
332332

333333
// Enable Softdevice, Use Internal OSC to compatible with all boards
334334
nrf_clock_lf_cfg_t clock_cfg =
@@ -339,7 +339,7 @@ static uint32_t softdev_init(bool init_softdevice)
339339
.accuracy = NRF_CLOCK_LF_ACCURACY_250_PPM
340340
};
341341

342-
APP_ERROR_CHECK( sd_softdevice_enable(&clock_cfg, app_error_fault_handler) );
342+
sd_softdevice_enable(&clock_cfg, app_error_fault_handler);
343343
sd_nvic_EnableIRQ(SD_EVT_IRQn);
344344

345345
/*------------- Configure BLE params -------------*/
@@ -354,35 +354,35 @@ static uint32_t softdev_init(bool init_softdevice)
354354
blecfg.gap_cfg.role_count_cfg.periph_role_count = 1;
355355
blecfg.gap_cfg.role_count_cfg.central_role_count = 0;
356356
blecfg.gap_cfg.role_count_cfg.central_sec_count = 0;
357-
APP_ERROR_CHECK( sd_ble_cfg_set(BLE_GAP_CFG_ROLE_COUNT, &blecfg, ram_start) );
357+
sd_ble_cfg_set(BLE_GAP_CFG_ROLE_COUNT, &blecfg, ram_start);
358358

359359
// NRF_DFU_BLE_REQUIRES_BONDS
360360
varclr(&blecfg);
361361
blecfg.gatts_cfg.service_changed.service_changed = 1;
362-
APP_ERROR_CHECK( sd_ble_cfg_set(BLE_GATTS_CFG_SERVICE_CHANGED, &blecfg, ram_start) );
362+
sd_ble_cfg_set(BLE_GATTS_CFG_SERVICE_CHANGED, &blecfg, ram_start) ;
363363

364364
// ATT MTU
365365
varclr(&blecfg);
366366
blecfg.conn_cfg.conn_cfg_tag = BLE_CONN_CFG_HIGH_BANDWIDTH;
367367
blecfg.conn_cfg.params.gatt_conn_cfg.att_mtu = BLEGATT_ATT_MTU_MAX;
368-
APP_ERROR_CHECK( sd_ble_cfg_set(BLE_CONN_CFG_GATT, &blecfg, ram_start) );
368+
sd_ble_cfg_set(BLE_CONN_CFG_GATT, &blecfg, ram_start);
369369

370370
// Event Length + HVN queue + WRITE CMD queue setting affecting bandwidth
371371
varclr(&blecfg);
372372
blecfg.conn_cfg.conn_cfg_tag = BLE_CONN_CFG_HIGH_BANDWIDTH;
373373
blecfg.conn_cfg.params.gap_conn_cfg.conn_count = 1;
374374
blecfg.conn_cfg.params.gap_conn_cfg.event_length = BLEGAP_EVENT_LENGTH;
375-
APP_ERROR_CHECK( sd_ble_cfg_set(BLE_CONN_CFG_GAP, &blecfg, ram_start) );
375+
sd_ble_cfg_set(BLE_CONN_CFG_GAP, &blecfg, ram_start);
376376

377377
// Enable BLE stack.
378378
// Note: Interrupt state (enabled, forwarding) is not work properly if not enable ble
379-
APP_ERROR_CHECK( sd_ble_enable(&ram_start) );
379+
sd_ble_enable(&ram_start);
380380

381381
#if 0
382382
ble_opt_t opt;
383383
varclr(&opt);
384384
opt.common_opt.conn_evt_ext.enable = 1; // enable Data Length Extension
385-
APP_ERROR_CHECK( sd_ble_opt_set(BLE_COMMON_OPT_CONN_EVT_EXT, &opt) );
385+
sd_ble_opt_set(BLE_COMMON_OPT_CONN_EVT_EXT, &opt);
386386
#endif
387387

388388
return NRF_SUCCESS;

src/usb/uf2/uf2cfg.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
// Application Address Space
2020
#define USER_FLASH_START MBR_SIZE // skip MBR included in SD hex
21-
#define USER_FLASH_END 0xAD000
21+
#define USER_FLASH_END (BOOTLOADER_REGION_START - DFU_APP_DATA_RESERVED)
2222

2323
// Bootloader start address
2424
#define BOOTLOADER_ADDR_START BOOTLOADER_REGION_START

0 commit comments

Comments
 (0)