Skip to content

Commit a78d555

Browse files
authored
Merge pull request #88 from adafruit/develop
adding support for nrf52833
2 parents c4cf262 + 16e7af4 commit a78d555

File tree

42 files changed

+481
-494
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+481
-494
lines changed

Makefile

Lines changed: 28 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ SD_FILENAME = $(SD_NAME)_nrf52_$(SD_VERSION)
2121
SD_API_PATH = $(SD_PATH)/$(SD_FILENAME)_API
2222
SD_HEX = $(SD_PATH)/$(SD_FILENAME)_softdevice.hex
2323

24-
LD_FILE = $(SRC_PATH)/linker/$(SD_NAME)_v$(word 1, $(subst ., ,$(SD_VERSION))).ld
24+
LD_FILE = $(SRC_PATH)/linker/$(MCU_SUB_VARIANT)_$(SD_NAME)_v$(word 1, $(subst ., ,$(SD_VERSION))).ld
2525

2626
MERGED_FNAME = $(OUTPUT_FILENAME)_$(SD_NAME)_$(SD_VERSION)
2727

@@ -76,23 +76,33 @@ remduplicates = $(strip $(if $1,$(firstword $1) $(call remduplicates,$(filter-ou
7676
#*********************************
7777
BOARD_LIST = $(sort $(subst .h,,$(subst src/boards/,,$(wildcard src/boards/*))))
7878

79-
NRF52832_BOARDLIST = feather_nrf52832
80-
IS_52832 = $(filter $(BOARD),$(NRF52832_BOARDLIST))
81-
8279
ifeq ($(filter $(BOARD),$(BOARD_LIST)),)
8380
$(info You must provide a BOARD parameter with 'BOARD='. Supported boards are:)
8481
$(info $(BOARD_LIST))
8582
$(error Invalid BOARD specified)
8683
endif
8784

85+
# Build directory
8886
BUILD = _build-$(BOARD)
8987

90-
ifneq ($(IS_52832),)
91-
SD_NAME = s132
92-
DFU_DEV_REV = 0xADAF
88+
# Board specific
89+
-include src/boards/$(BOARD)/board.mk
90+
91+
# MCU_SUB_VARIANT can be nrf52 (nrf52832), nrf52833, nrf52840
92+
ifeq ($(MCU_SUB_VARIANT),nrf52)
93+
SD_NAME = s132
94+
DFU_DEV_REV = 0xADAF
95+
MCU_FLAGS = -DNRF52 -DNRF52832_XXAA -DS132
96+
else ifeq ($(MCU_SUB_VARIANT),nrf52833)
97+
SD_NAME = s140
98+
DFU_DEV_REV = 52840
99+
MCU_FLAGS = -DNRF52833_XXAA -DS140
100+
else ifeq ($(MCU_SUB_VARIANT),nrf52840)
101+
SD_NAME = s140
102+
DFU_DEV_REV = 52840
103+
MCU_FLAGS = -DNRF52840_XXAA -DS140
93104
else
94-
SD_NAME = s140
95-
DFU_DEV_REV = 52840
105+
$(error Sub Variant $(MCU_SUB_VARIANT) is unknown)
96106
endif
97107

98108
#******************************************************************************
@@ -108,7 +118,8 @@ C_SOURCE_FILES += $(SRC_PATH)/dfu_init.c
108118

109119
# nrfx
110120
C_SOURCE_FILES += $(NRFX_PATH)/drivers/src/nrfx_power.c
111-
C_SOURCE_FILES += $(NRFX_PATH)/hal/nrf_nvmc.c
121+
C_SOURCE_FILES += $(NRFX_PATH)/drivers/src/nrfx_nvmc.c
122+
C_SOURCE_FILES += $(NRFX_PATH)/mdk/system_$(MCU_SUB_VARIANT).c
112123

113124
# SDK 11 files
114125
C_SOURCE_FILES += $(SDK11_PATH)/libraries/bootloader_dfu/bootloader.c
@@ -134,10 +145,8 @@ C_SOURCE_FILES += $(SDK_PATH)/libraries/hci/hci_slip.c
134145
C_SOURCE_FILES += $(SDK_PATH)/libraries/hci/hci_transport.c
135146
C_SOURCE_FILES += $(SDK_PATH)/libraries/util/nrf_assert.c
136147

137-
ifneq ($(IS_52832),)
138-
139-
C_SOURCE_FILES += $(NRFX_PATH)/mdk/system_nrf52.c
140-
148+
# UART or USB Serial
149+
ifeq ($(MCU_SUB_VARIANT),nrf52)
141150
C_SOURCE_FILES += $(SDK_PATH)/libraries/uart/app_uart.c
142151
C_SOURCE_FILES += $(SDK_PATH)/drivers_nrf/uart/nrf_drv_uart.c
143152
C_SOURCE_FILES += $(SDK_PATH)/drivers_nrf/common/nrf_drv_common.c
@@ -147,25 +156,19 @@ IPATH += $(SDK_PATH)/drivers_nrf/common
147156
IPATH += $(SDK_PATH)/drivers_nrf/uart
148157

149158
else
150-
151159
# src
152160
C_SOURCE_FILES += $(SRC_PATH)/usb/usb_desc.c
153161
C_SOURCE_FILES += $(SRC_PATH)/usb/usb.c
154162
C_SOURCE_FILES += $(SRC_PATH)/usb/msc_uf2.c
155163
C_SOURCE_FILES += $(SRC_PATH)/usb/uf2/ghostfat.c
156164

157-
# nrfx
158-
C_SOURCE_FILES += $(NRFX_PATH)/mdk/system_nrf52840.c
159-
160-
# Tinyusb stack
165+
# TinyUSB stack
161166
C_SOURCE_FILES += $(TUSB_PATH)/portable/nordic/nrf5x/dcd_nrf5x.c
162-
C_SOURCE_FILES += $(TUSB_PATH)/portable/nordic/nrf5x/hal_nrf5x.c
163167
C_SOURCE_FILES += $(TUSB_PATH)/common/tusb_fifo.c
164168
C_SOURCE_FILES += $(TUSB_PATH)/device/usbd.c
165169
C_SOURCE_FILES += $(TUSB_PATH)/device/usbd_control.c
166170
C_SOURCE_FILES += $(TUSB_PATH)/class/cdc/cdc_device.c
167171
C_SOURCE_FILES += $(TUSB_PATH)/class/msc/msc_device.c
168-
C_SOURCE_FILES += $(TUSB_PATH)/class/custom/custom_device.c
169172
C_SOURCE_FILES += $(TUSB_PATH)/tusb.c
170173

171174
endif
@@ -174,11 +177,7 @@ endif
174177
#******************************************************************************
175178
# Assembly Files
176179
#******************************************************************************
177-
ifneq ($(IS_52832),)
178-
ASM_SOURCE_FILES = $(NRFX_PATH)/mdk/gcc_startup_nrf52.S
179-
else
180-
ASM_SOURCE_FILES = $(NRFX_PATH)/mdk/gcc_startup_nrf52840.S
181-
endif
180+
ASM_SOURCE_FILES = $(NRFX_PATH)/mdk/gcc_startup_$(MCU_SUB_VARIANT).S
182181

183182
#******************************************************************************
184183
# INCLUDE PATH
@@ -198,6 +197,7 @@ IPATH += $(NRFX_PATH)
198197
IPATH += $(NRFX_PATH)/mdk
199198
IPATH += $(NRFX_PATH)/hal
200199
IPATH += $(NRFX_PATH)/drivers/include
200+
IPATH += $(NRFX_PATH)/drivers/src
201201

202202
IPATH += $(SDK11_PATH)/libraries/bootloader_dfu/hci_transport
203203
IPATH += $(SDK11_PATH)/libraries/bootloader_dfu
@@ -245,22 +245,14 @@ CFLAGS += -DSWI_DISABLE0
245245
CFLAGS += -DSOFTDEVICE_PRESENT
246246
CFLAGS += -DFLOAT_ABI_HARD
247247
CFLAGS += -DDFU_APP_DATA_RESERVED=7*4096
248+
CFLAGS += $(MCU_FLAGS)
248249

249250
CFLAGS += -DUF2_VERSION='"$(GIT_VERSION) $(GIT_SUBMODULE_VERSIONS) $(SD_NAME) $(SD_VERSION)"'
250251
CFLAGS += -DBLEDIS_FW_VERSION='"$(GIT_VERSION) $(SD_NAME) $(SD_VERSION)"'
251252

252253
_VER = $(subst ., ,$(word 1, $(subst -, ,$(GIT_VERSION))))
253254
CFLAGS += -DMK_BOOTLOADER_VERSION='($(word 1,$(_VER)) << 16) + ($(word 2,$(_VER)) << 8) + $(word 3,$(_VER))'
254255

255-
ifneq ($(IS_52832),)
256-
CFLAGS += -DNRF52
257-
CFLAGS += -DNRF52832_XXAA
258-
CFLAGS += -DS132
259-
else
260-
CFLAGS += -DNRF52840_XXAA
261-
CFLAGS += -DS140
262-
endif
263-
264256

265257
#******************************************************************************
266258
# Linker Flags
@@ -289,14 +281,7 @@ ASMFLAGS += -DBLE_STACK_SUPPORT_REQD
289281
ASMFLAGS += -DSWI_DISABLE0
290282
ASMFLAGS += -DSOFTDEVICE_PRESENT
291283
ASMFLAGS += -DFLOAT_ABI_HARD
292-
293-
ifneq ($(IS_52832),)
294-
ASMFLAGS += -DNRF52
295-
ASMFLAGS += -DS132
296-
else
297-
ASMFLAGS += -DNRF52840_XXAA
298-
ASMFLAGS += -DS140
299-
endif
284+
ASMFLAGS += $(MCU_FLAGS)
300285

301286
C_SOURCE_FILE_NAMES = $(notdir $(C_SOURCE_FILES))
302287
C_PATHS = $(call remduplicates, $(dir $(C_SOURCE_FILES) ) )

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ You must have have a J-Link available to "unbrick" your device.
109109
Prerequisites
110110

111111
- ARM GCC
112-
- Nordic's [nRF5x Command Line Tools](http://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.tools%2Fdita%2Ftools%2Fnrf5x_command_line_tools%2Fnrf5x_installation.html)
112+
- Nordic's [nRF5x Command Line Tools](https://www.nordicsemi.com/Software-and-Tools/Development-Tools/nRF-Command-Line-Tools)
113113

114114
To build:
115115

lib/nrfx

Submodule nrfx updated 339 files

lib/sdk/components/drivers_nrf/uart/nrf_drv_uart.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,23 @@ __STATIC_INLINE void apply_config(nrf_drv_uart_t const * p_instance, nrf_drv_uar
119119
nrf_gpio_cfg_input(p_config->pselrxd, NRF_GPIO_PIN_NOPULL);
120120
}
121121

122+
nrf_uarte_config_t uarte_cfg =
123+
{
124+
.hwfc = (nrf_uarte_hwfc_t) p_config->hwfc,
125+
.parity = (nrf_uarte_parity_t) p_config->parity
126+
};
127+
128+
nrf_uart_config_t uart_cfg =
129+
{
130+
.hwfc = (nrf_uart_hwfc_t) p_config->hwfc,
131+
.parity = (nrf_uart_parity_t) p_config->parity
132+
};
133+
122134
CODE_FOR_UARTE
123135
(
124136
nrf_uarte_baudrate_set(p_instance->reg.p_uarte, (nrf_uarte_baudrate_t)p_config->baudrate);
125-
nrf_uarte_configure(p_instance->reg.p_uarte, (nrf_uarte_parity_t)p_config->parity,
126-
(nrf_uarte_hwfc_t)p_config->hwfc);
137+
// nrf_uarte_configure(p_instance->reg.p_uarte, (nrf_uarte_parity_t)p_config->parity, (nrf_uarte_hwfc_t)p_config->hwfc);
138+
nrf_uarte_configure(p_instance->reg.p_uarte, &uarte_cfg);
127139
nrf_uarte_txrx_pins_set(p_instance->reg.p_uarte, p_config->pseltxd, p_config->pselrxd);
128140
if (p_config->hwfc == NRF_UART_HWFC_ENABLED)
129141
{
@@ -142,7 +154,8 @@ __STATIC_INLINE void apply_config(nrf_drv_uart_t const * p_instance, nrf_drv_uar
142154
CODE_FOR_UART
143155
(
144156
nrf_uart_baudrate_set(p_instance->reg.p_uart, p_config->baudrate);
145-
nrf_uart_configure(p_instance->reg.p_uart, p_config->parity, p_config->hwfc);
157+
// nrf_uart_configure(p_instance->reg.p_uart, p_config->parity, p_config->hwfc);
158+
nrf_uart_configure(p_instance->reg.p_uart, &uart_cfg);
146159
nrf_uart_txrx_pins_set(p_instance->reg.p_uart, p_config->pseltxd, p_config->pselrxd);
147160
if (p_config->hwfc == NRF_UART_HWFC_ENABLED)
148161
{

lib/sdk/components/libraries/hci/hci_slip.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444
#include "app_uart.h"
4545
#include "nrf_error.h"
4646

47-
#ifdef NRF52840_XXAA
47+
// nRF has native usb peripheral
48+
#ifdef NRF_USBD
4849
#include "tusb.h"
4950
#endif
5051

@@ -121,13 +122,17 @@ static uint32_t send_tx_byte_end(void);
121122
*/
122123
uint32_t (*send_tx_byte) (void) = send_tx_byte_default;
123124

124-
#ifdef NRF52840_XXAA
125-
static uint32_t serial_put(char ch)
126-
{
127-
return tud_cdc_write_char(ch) ? NRF_SUCCESS : NRF_ERROR_NO_MEM;
128-
}
125+
#ifdef NRF_USBD
126+
127+
static uint32_t serial_put(char ch)
128+
{
129+
return tud_cdc_write_char(ch) ? NRF_SUCCESS : NRF_ERROR_NO_MEM;
130+
}
131+
129132
#else
130-
#define serial_put app_uart_put
133+
134+
#define serial_put app_uart_put
135+
131136
#endif
132137

133138
static uint32_t send_tx_byte_end(void)
@@ -345,7 +350,7 @@ static bool rx_buffer_overflowed(void)
345350
return false;
346351
}
347352

348-
#ifdef NRF52840_XXAA
353+
#ifdef NRF_USBD
349354

350355
static uint32_t slip_uart_open(void)
351356
{
@@ -441,7 +446,8 @@ uint32_t hci_slip_open()
441446
uint32_t hci_slip_close()
442447
{
443448
m_current_state = SLIP_OFF;
444-
#ifdef NRF52840_XXAA
449+
450+
#ifdef NRF_USBD
445451
return NRF_SUCCESS;
446452
#else
447453
uint32_t err_code = app_uart_close();

lib/sdk11/components/drivers_nrf/pstorage/pstorage_raw.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@
4040
#define INVALID_OPCODE 0x00 /**< Invalid op code identifier. */
4141

4242
#ifdef NRF51
43-
#define SOC_MAX_WRITE_SIZE 1024 /**< Maximum write size allowed for a single call to \ref sd_flash_write as specified in the SoC API on the nRF51. */
44-
#elif defined(NRF52832_XXAA) || defined(NRF52840_XXAA)
45-
#define SOC_MAX_WRITE_SIZE 4096 /**< Maximum write size allowed for a single call to \ref sd_flash_write as specified in the SoC API on the nRF52. */
43+
#define SOC_MAX_WRITE_SIZE 1024 /**< Maximum write size allowed for a single call to \ref sd_flash_write as specified in the SoC API on the nRF51. */
44+
#elif defined(NRF52_SERIES)
45+
#define SOC_MAX_WRITE_SIZE 4096 /**< Maximum write size allowed for a single call to \ref sd_flash_write as specified in the SoC API on the nRF52. */
4646
#else
47-
#error No target defined
47+
#error No target defined
4848
#endif
4949

5050

lib/sdk11/components/libraries/bootloader_dfu/bootloader.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,19 @@
3232

3333
#include "boards.h"
3434

35-
#ifdef NRF52840_XXAA
35+
#ifdef NRF_USBD
3636
#include "tusb.h"
3737
#endif
3838

3939
#define APP_TIMER_PRESCALER 0
4040

4141
#define IRQ_ENABLED 0x01 /**< Field identifying if an interrupt is enabled. */
4242

43-
/**< Maximum number of interrupts available. */
43+
/**< Maximum number of interrupts available. (from IRQn_Type) */
4444
#if defined(NRF52832_XXAA)
45-
#define MAX_NUMBER_INTERRUPTS 39
46-
#elif defined(NRF52840_XXAA)
47-
#define MAX_NUMBER_INTERRUPTS 48
45+
#define MAX_NUMBER_INTERRUPTS 39
46+
#elif defined(NRF52840_XXAA) || defined(NRF52833_XXAA)
47+
#define MAX_NUMBER_INTERRUPTS 48
4848
#endif
4949

5050
/**@brief Enumeration for specifying current bootloader status.
@@ -119,17 +119,16 @@ static void wait_for_events(void)
119119

120120
// Feed all Watchdog just in case application enable it
121121
// WDT cannot be disabled once started. It even last through soft reset (NVIC Reset)
122-
if ( nrf_wdt_started() )
122+
if ( nrf_wdt_started(NRF_WDT) )
123123
{
124-
for (uint8_t i=0; i<8; i++) nrf_wdt_reload_request_set(i);
124+
for (uint8_t i=0; i<8; i++) nrf_wdt_reload_request_set(NRF_WDT, i);
125125
}
126126

127127
// Event received. Process it from the scheduler.
128128
app_sched_execute();
129129

130-
#ifdef NRF52840_XXAA
130+
#ifdef NRF_USBD
131131
// skip if usb is not inited ( e.g OTA / finializing sd/bootloader )
132-
extern bool usb_inited(void);
133132
if ( tusb_inited() )
134133
{
135134
tud_task();
@@ -194,8 +193,8 @@ static void bootloader_settings_save(bootloader_settings_t * p_settings)
194193
}
195194
else
196195
{
197-
nrf_nvmc_page_erase(BOOTLOADER_SETTINGS_ADDRESS);
198-
nrf_nvmc_write_words(BOOTLOADER_SETTINGS_ADDRESS, (uint32_t *) p_settings, sizeof(bootloader_settings_t) / 4);
196+
nrfx_nvmc_page_erase(BOOTLOADER_SETTINGS_ADDRESS);
197+
nrfx_nvmc_words_write(BOOTLOADER_SETTINGS_ADDRESS, (uint32_t *) p_settings, sizeof(bootloader_settings_t) / 4);
199198

200199
pstorage_callback_handler(&m_bootsettings_handle, PSTORAGE_STORE_OP_CODE, NRF_SUCCESS, (uint8_t *) p_settings, sizeof(bootloader_settings_t));
201200
}

lib/sdk11/components/libraries/bootloader_dfu/bootloader_settings.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ __root const uint32_t m_uicr_bootloader_start_address @ NRF_UICR_BOOT_START_A
3131

3232
#endif
3333

34-
#if defined(NRF52832_XXAA) || defined(NRF52840_XXAA)
34+
#if defined(NRF52_SERIES)
3535
#if defined ( __CC_ARM )
3636

3737
uint8_t m_mbr_params_page[CODE_PAGE_SIZE] __attribute__((at(BOOTLOADER_MBR_PARAMS_PAGE_ADDRESS))) __attribute__((used)); /**< This variable reserves a codepage for mbr parameters, to ensure the compiler doesn't locate any code or variables at his location. */
@@ -50,7 +50,7 @@ __no_init uint8_t m_mbr_params_page[CODE_PAGE_SIZE] @ BOOTLOADER_MBR_PARAMS_
5050
__root const uint32_t m_uicr_mbr_params_page_address @ NRF_UICR_MBR_PARAMS_PAGE_ADDRESS = BOOTLOADER_MBR_PARAMS_PAGE_ADDRESS; /**< This variable ensures that the linker script will write the bootloader start address to the UICR register. This value will be written in the HEX file and thus written to UICR when the bootloader is flashed into the chip. */
5151

5252
#endif
53-
#endif // defined(NRF52832_XXAA) || defined(NRF52840_XXAA)
53+
#endif // NRF52_SERIES
5454

5555

5656
void bootloader_util_settings_get(const bootloader_settings_t ** pp_bootloader_settings)

lib/sdk11/components/libraries/bootloader_dfu/dfu_single_bank.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ static void dfu_prepare_func_app_erase(uint32_t image_size)
151151

152152
for ( uint32_t i = 0; i < page_count; i++ )
153153
{
154-
nrf_nvmc_page_erase(DFU_BANK_0_REGION_START + i * CODE_PAGE_SIZE);
154+
nrfx_nvmc_page_erase(DFU_BANK_0_REGION_START + i * CODE_PAGE_SIZE);
155155
}
156156

157157
// invoke complete callback

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,20 @@
3030
#include "app_util.h"
3131

3232
#define NRF_UICR_BOOT_START_ADDRESS (NRF_UICR_BASE + 0x14) /**< Register where the bootloader start address is stored in the UICR register. */
33-
34-
#if defined(NRF52832_XXAA) || defined(NRF52840_XXAA)
3533
#define NRF_UICR_MBR_PARAMS_PAGE_ADDRESS (NRF_UICR_BASE + 0x18) /**< Register where the mbr params page is stored in the UICR register. (Only in use in nRF52 MBR).*/
36-
#endif
3734

3835
#define CODE_REGION_1_START SD_SIZE_GET(MBR_SIZE) /**< This field should correspond to the size of Code Region 0, (which is identical to Start of Code Region 1), found in UICR.CLEN0 register. This value is used for compile safety, as the linker will fail if application expands into bootloader. Runtime, the bootloader will use the value found in UICR.CLEN0. */
3936
#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. */
4037
#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. */
4138

42-
43-
#if defined(NRF52832_XXAA)
39+
// Flash = 512 KB
40+
#if defined(NRF52832_XXAA) || defined(NRF52833_XXAA)
4441

4542
#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. */
4643
#define BOOTLOADER_SETTINGS_ADDRESS 0x0007F000 /**< The field specifies the page location of the bootloader settings address. */
4744
#define BOOTLOADER_MBR_PARAMS_PAGE_ADDRESS 0x0007E000 /**< The field specifies the page location of the mbr params page address. */
4845

46+
// Flash = 1024 KB
4947
#elif defined(NRF52840_XXAA)
5048

5149
#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. */

0 commit comments

Comments
 (0)