Skip to content

Commit

Permalink
Merge pull request #2449 from fanoush/f-dfu-trim-extreme
Browse files Browse the repository at this point in the history
trim DFU bootloader, enable BANGLE1 SPI flashing
  • Loading branch information
gfwilliams authored Jan 15, 2024
2 parents 149bbb7 + d3501ab commit 57ae5ee
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 26 deletions.
9 changes: 8 additions & 1 deletion boards/BANGLEJS.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,14 @@
'JSMODULESOURCES += libs/js/banglejs/locale.min.js',
'NRF_BL_DFU_INSECURE=1',
'LINKER_BOOTLOADER=targetlibs/nrf5x_12/nrf5x_linkers/banglejs_dfu.ld',
'LINKER_ESPRUINO=targetlibs/nrf5x_12/nrf5x_linkers/banglejs_espruino.ld'
'LINKER_ESPRUINO=targetlibs/nrf5x_12/nrf5x_linkers/banglejs_espruino.ld',
# Uncomment these lines to allow the Bangle.js 1 bootloader to check external flash for firmware and
# update from there. We do this by default on Bangle.js 2 but on Bangle.js 1 it's bit tight to get it into
# available flash memory. See #2449
# 'DEFINES += -DESPR_BOOTLOADER_SPIFLASH', # Allow bootloader to flash direct from SPI flash
# 'BOOTLOADER_DEFINES += -DNRF_BL_DFU_TRIM_EXTREME',
# 'BOOTLOADER_LDFLAGS += -nostartfiles',
# 'BOOTLOADER_ASFLAGS += -D__STARTUP_CLEAR_BSS -D__START=main',
]
}
};
Expand Down
7 changes: 7 additions & 0 deletions make/common/NRF5X.make
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,13 @@ endif
ifdef USE_BOOTLOADER
ifdef BOOTLOADER
DEFINES += -DBOOTLOADER -DNRF_DFU_SETTINGS_VERSION=1
DEFINES += $(BOOTLOADER_DEFINES)
ifdef BOOTLOADER_ASFLAGS
ASFLAGS += $(BOOTLOADER_ASFLAGS)
endif
ifdef BOOTLOADER_LDFLAGS
LDFLAGS += $(BOOTLOADER_LDFLAGS)
endif
TARGETSOURCES =
ifdef NRF5X_SDK_12
DEFINES += -DuECC_ENABLE_VLI_API -DuECC_VLI_NATIVE_LITTLE_ENDIAN=1 -DuECC_SQUARE_FUNC=1 -DuECC_SUPPORTS_secp256r1=1 -DuECC_SUPPORT_COMPRESSED_POINT=0 -DuECC_OPTIMIZATION_LEVEL=3
Expand Down
60 changes: 38 additions & 22 deletions targetlibs/nrf5x_12/components/toolchain/system_nrf52.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,13 @@ void SystemInit(void)
*(volatile uint32_t *)0x4000053C = ((*(volatile uint32_t *)0x10000244) & 0x0000E000) >> 13;
}

#if !(defined(BOOTLOADER) && defined(NRF_BL_DFU_TRIM_EXTREME))
/* Workaround for Errata 32 "DIF: Debug session automatically enables TracePort pins" found at the Errata document
for your device located at https://infocenter.nordicsemi.com/ */
if (errata_32()){
CoreDebug->DEMCR &= ~CoreDebug_DEMCR_TRCENA_Msk;
}
#endif

/* Workaround for Errata 36 "CLOCK: Some registers are not reset when expected" found at the Errata document
for your device located at https://infocenter.nordicsemi.com/ */
Expand All @@ -94,6 +96,7 @@ void SystemInit(void)
*(volatile uint32_t *)0x400005A0 = 0x3;
}

#if !(defined(BOOTLOADER) && defined(NRF_BL_DFU_TRIM_EXTREME)) // not critical for bootloader
/* Workaround for Errata 57 "NFCT: NFC Modulation amplitude" found at the Errata document
for your device located at https://infocenter.nordicsemi.com/ */
if (errata_57()){
Expand Down Expand Up @@ -124,6 +127,7 @@ void SystemInit(void)
NRF_TEMP->T3 = NRF_FICR->TEMP.T3;
NRF_TEMP->T4 = NRF_FICR->TEMP.T4;
}
#endif

/* Workaround for Errata 108 "RAM: RAM content cannot be trusted upon waking up from System ON Idle or System OFF mode" found at the Errata document
for your device located at https://infocenter.nordicsemi.com/ */
Expand Down Expand Up @@ -196,11 +200,23 @@ void SystemInit(void)
SystemCoreClockUpdate();
}

// ARM Peripheral ID registers
// ID0, ID1 - 12 bits of manufacturer part number
// ID2 - 4 bits of revision
static const uint32_t const *PID_REGS = (uint32_t *)0xF0000FE0;

static const bool is_partno_006(){
return ((PID_REGS[0] & 0x000000FF) == 0x6) && ((PID_REGS[1] & 0x0000000F) == 0x0);
}

static const uint8_t part_rev(){
return (PID_REGS[2] & 0x000000F0);
}

static bool errata_16(void)
{
if ((((*(uint32_t *)0xF0000FE0) & 0x000000FF) == 0x6) && (((*(uint32_t *)0xF0000FE4) & 0x0000000F) == 0x0)){
if (((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x30){
if (is_partno_006()){
if (part_rev() == 0x30){
return true;
}
}
Expand All @@ -210,14 +226,14 @@ static bool errata_16(void)

static bool errata_31(void)
{
if ((((*(uint32_t *)0xF0000FE0) & 0x000000FF) == 0x6) && (((*(uint32_t *)0xF0000FE4) & 0x0000000F) == 0x0)){
if (((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x30){
if (is_partno_006()){
if (part_rev() == 0x30){
return true;
}
if (((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x40){
if (part_rev() == 0x40){
return true;
}
if (((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x50){
if (part_rev() == 0x50){
return true;
}
}
Expand All @@ -227,8 +243,8 @@ static bool errata_31(void)

static bool errata_32(void)
{
if ((((*(uint32_t *)0xF0000FE0) & 0x000000FF) == 0x6) && (((*(uint32_t *)0xF0000FE4) & 0x0000000F) == 0x0)){
if (((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x30){
if (is_partno_006()){
if (part_rev() == 0x30){
return true;
}
}
Expand All @@ -238,14 +254,14 @@ static bool errata_32(void)

static bool errata_36(void)
{
if ((((*(uint32_t *)0xF0000FE0) & 0x000000FF) == 0x6) && (((*(uint32_t *)0xF0000FE4) & 0x0000000F) == 0x0)){
if (((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x30){
if (is_partno_006()){
if (part_rev() == 0x30){
return true;
}
if (((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x40){
if (part_rev() == 0x40){
return true;
}
if (((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x50){
if (part_rev() == 0x50){
return true;
}
}
Expand All @@ -255,8 +271,8 @@ static bool errata_36(void)

static bool errata_37(void)
{
if ((((*(uint32_t *)0xF0000FE0) & 0x000000FF) == 0x6) && (((*(uint32_t *)0xF0000FE4) & 0x0000000F) == 0x0)){
if (((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x30){
if (is_partno_006()){
if (part_rev() == 0x30){
return true;
}
}
Expand All @@ -266,8 +282,8 @@ static bool errata_37(void)

static bool errata_57(void)
{
if ((((*(uint32_t *)0xF0000FE0) & 0x000000FF) == 0x6) && (((*(uint32_t *)0xF0000FE4) & 0x0000000F) == 0x0)){
if (((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x30){
if (is_partno_006()){
if (part_rev() == 0x30){
return true;
}
}
Expand All @@ -277,8 +293,8 @@ static bool errata_57(void)

static bool errata_66(void)
{
if ((((*(uint32_t *)0xF0000FE0) & 0x000000FF) == 0x6) && (((*(uint32_t *)0xF0000FE4) & 0x0000000F) == 0x0)){
if (((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x50){
if (is_partno_006()){
if (part_rev() == 0x50){
return true;
}
}
Expand All @@ -289,14 +305,14 @@ static bool errata_66(void)

static bool errata_108(void)
{
if ((((*(uint32_t *)0xF0000FE0) & 0x000000FF) == 0x6) && (((*(uint32_t *)0xF0000FE4) & 0x0000000F) == 0x0)){
if (((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x30){
if (is_partno_006()){
if (part_rev() == 0x30){
return true;
}
if (((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x40){
if (part_rev() == 0x40){
return true;
}
if (((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x50){
if (part_rev() == 0x50){
return true;
}
}
Expand Down
14 changes: 11 additions & 3 deletions targetlibs/nrf5x_12/external/nano-pb/pb_decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,21 @@ static void pb_release_single_field(const pb_field_iter_t *iter);
static const pb_decoder_t PB_DECODERS[PB_LTYPES_COUNT] = {
&pb_dec_varint,
&pb_dec_uvarint,
#if (defined(BOOTLOADER) && defined(NRF_BL_DFU_TRIM_EXTREME))
NULL, //&pb_dec_svarint,
NULL, //&pb_dec_fixed32,
NULL, //&pb_dec_fixed64,

&pb_dec_bytes,
NULL, //&pb_dec_string,
#else
&pb_dec_svarint,
&pb_dec_fixed32,
&pb_dec_fixed64,

&pb_dec_bytes,
&pb_dec_string,
#endif
&pb_dec_submessage,
NULL /* extensions */
};
Expand Down Expand Up @@ -354,7 +363,7 @@ static bool checkreturn decode_static_field(pb_istream_t *stream, pb_wire_type_t
type = iter->pos->type;
func = PB_DECODERS[PB_LTYPE(type)];

switch (PB_HTYPE(type))
if (func != NULL) switch (PB_HTYPE(type))
{
case PB_HTYPE_REQUIRED:
return func(stream, iter->pos, iter->pData);
Expand Down Expand Up @@ -414,9 +423,8 @@ static bool checkreturn decode_static_field(pb_istream_t *stream, pb_wire_type_t
}
return func(stream, iter->pos, iter->pData);

default:
PB_RETURN_ERROR(stream, "invalid field type");
}
PB_RETURN_ERROR(stream, "invalid field type");
}

#ifdef PB_ENABLE_MALLOC
Expand Down

0 comments on commit 57ae5ee

Please sign in to comment.