Skip to content

Commit d7175ad

Browse files
committed
update nrf cmake and make to support nrf5340 (pca10095)
1 parent 9f5b08d commit d7175ad

File tree

13 files changed

+189
-48
lines changed

13 files changed

+189
-48
lines changed

.idea/cmake.xml

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/rules.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ JLINK_IF ?= swd
230230
# Flash using jlink
231231
flash-jlink: $(BUILD)/$(PROJECT).hex
232232
@echo halt > $(BUILD)/$(BOARD).jlink
233-
@echo r > $(BUILD)/$(BOARD).jlink
233+
@echo r >> $(BUILD)/$(BOARD).jlink
234234
@echo loadfile $^ >> $(BUILD)/$(BOARD).jlink
235235
@echo r >> $(BUILD)/$(BOARD).jlink
236236
@echo go >> $(BUILD)/$(BOARD).jlink

hw/bsp/imxrt/family.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ function(family_configure_target TARGET)
130130
#---------- Flash ----------
131131
# Flash using pyocd
132132
add_custom_target(${TARGET}-pyocd
133+
DEPENDS ${TARGET}
133134
COMMAND pyocd flash -t ${PYOCD_TARGET} $<TARGET_FILE:${TARGET}>
134135
)
135136

@@ -139,6 +140,7 @@ function(family_configure_target TARGET)
139140
# realpath error: No such file or directory
140141
execute_process(COMMAND which LinkServer OUTPUT_VARIABLE LINKSERVER_PATH OUTPUT_STRIP_TRAILING_WHITESPACE)
141142
add_custom_target(${TARGET}-nxplink
143+
DEPENDS ${TARGET}
142144
COMMAND ${LINKSERVER_PATH} flash ${NXPLINK_DEVICE} load $<TARGET_FILE:${TARGET}>
143145
)
144146

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
set(MCU_VARIANT nrf5340_application)
2+
set(LD_FILE_gcc ${NRFX_DIR}/mdk/nrf5340_xxaa_application.ld)
3+
4+
function(update_board TARGET)
5+
target_compile_definitions(${TARGET} PUBLIC
6+
NRF5340_XXAA
7+
NRF5340_XXAA_APPLICATION
8+
)
9+
target_sources(${TARGET} PUBLIC
10+
${NRFX_DIR}/drivers/src/nrfx_usbreg.c
11+
)
12+
endfunction()

hw/bsp/nrf/boards/pca10095/board.h

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2020, Ha Thach (tinyusb.org)
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*
24+
* This file is part of the TinyUSB stack.
25+
*/
26+
27+
#ifndef BOARD_H_
28+
#define BOARD_H_
29+
30+
#ifdef __cplusplus
31+
extern "C" {
32+
#endif
33+
34+
// LED
35+
#define LED_PIN 28
36+
#define LED_STATE_ON 0
37+
38+
// Button
39+
#define BUTTON_PIN 23
40+
#define BUTTON_STATE_ACTIVE 0
41+
42+
// UART
43+
#define UART_RX_PIN 32
44+
#define UART_TX_PIN 33
45+
46+
#ifdef __cplusplus
47+
}
48+
#endif
49+
50+
#endif /* BOARD_H_ */

hw/bsp/nrf/boards/pca10095/board.mk

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
MCU_VARIANT = nrf5340_application
2+
CFLAGS += -DNRF5340_XXAA -DNRF5340_XXAA_APPLICATION
3+
4+
LD_FILE = hw/mcu/nordic/nrfx/mdk/nrf5340_xxaa_application.ld
5+
6+
SRC_C += hw/mcu/nordic/nrfx/drivers/src/nrfx_usbreg.c
7+
8+
# caused by void SystemStoreFICRNS() (without void) in system_nrf5340_application.c
9+
CFLAGS += -Wno-error=strict-prototypes
10+
11+
# flash using jlink
12+
JLINK_DEVICE = nrf5340_xxaa_app
13+
flash: flash-jlink

hw/bsp/nrf/family.c

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
#include "board.h"
2929

3030
#include "nrfx.h"
31-
#include "nrfx/hal/nrf_gpio.h"
32-
#include "nrfx/drivers/include/nrfx_power.h"
33-
#include "nrfx/drivers/include/nrfx_uarte.h"
31+
#include "hal/nrf_gpio.h"
32+
#include "drivers/include/nrfx_power.h"
33+
#include "drivers/include/nrfx_uarte.h"
3434

3535
#ifdef SOFTDEVICE_PRESENT
3636
#include "nrf_sdm.h"
@@ -49,6 +49,23 @@ void USBD_IRQHandler(void)
4949
/* MACRO TYPEDEF CONSTANT ENUM
5050
*------------------------------------------------------------------*/
5151

52+
// Value is chosen to be as same as NRFX_POWER_USB_EVT_* in nrfx_power.h
53+
enum {
54+
USB_EVT_DETECTED = 0,
55+
USB_EVT_REMOVED = 1,
56+
USB_EVT_READY = 2
57+
};
58+
59+
#ifdef NRF5340_XXAA
60+
#define LFCLK_SRC_RC CLOCK_LFCLKSRC_SRC_LFRC
61+
#define VBUSDETECT_Msk USBREG_USBREGSTATUS_VBUSDETECT_Msk
62+
#define OUTPUTRDY_Msk USBREG_USBREGSTATUS_OUTPUTRDY_Msk
63+
#else
64+
#define LFCLK_SRC_RC CLOCK_LFCLKSRC_SRC_RC
65+
#define VBUSDETECT_Msk POWER_USBREGSTATUS_VBUSDETECT_Msk
66+
#define OUTPUTRDY_Msk POWER_USBREGSTATUS_OUTPUTRDY_Msk
67+
#endif
68+
5269
static nrfx_uarte_t _uart_id = NRFX_UARTE_INSTANCE(0);
5370

5471
// tinyusb function that handles power event (detected, ready, removed)
@@ -68,7 +85,7 @@ void board_init(void)
6885
NRF_CLOCK->TASKS_LFCLKSTOP = 1UL;
6986

7087
// Use Internal OSC to compatible with all boards
71-
NRF_CLOCK->LFCLKSRC = CLOCK_LFCLKSRC_SRC_RC;
88+
NRF_CLOCK->LFCLKSRC = LFCLK_SRC_RC;
7289
NRF_CLOCK->TASKS_LFCLKSTART = 1UL;
7390

7491
// LED
@@ -123,21 +140,26 @@ void board_init(void)
123140
#endif
124141
{
125142
// Power module init
126-
const nrfx_power_config_t pwr_cfg = { 0 };
143+
const nrfx_power_config_t pwr_cfg = {0};
127144
nrfx_power_init(&pwr_cfg);
128145

129146
// Register tusb function as USB power handler
130147
// cause cast-function-type warning
131-
const nrfx_power_usbevt_config_t config = { .handler = power_event_handler };
148+
const nrfx_power_usbevt_config_t config = {.handler = power_event_handler};
132149
nrfx_power_usbevt_init(&config);
133-
134150
nrfx_power_usbevt_enable();
135151

152+
// USB power may already be ready at this time -> no event generated
153+
// We need to invoke the handler based on the status initially
154+
#ifdef NRF5340_XXAA
155+
usb_reg = NRF_USBREGULATOR->USBREGSTATUS;
156+
#else
136157
usb_reg = NRF_POWER->USBREGSTATUS;
158+
#endif
137159
}
138160

139-
if ( usb_reg & POWER_USBREGSTATUS_VBUSDETECT_Msk ) tusb_hal_nrf_power_event(NRFX_POWER_USB_EVT_DETECTED);
140-
if ( usb_reg & POWER_USBREGSTATUS_OUTPUTRDY_Msk ) tusb_hal_nrf_power_event(NRFX_POWER_USB_EVT_READY);
161+
if ( usb_reg & VBUSDETECT_Msk ) tusb_hal_nrf_power_event(USB_EVT_DETECTED);
162+
if ( usb_reg & OUTPUTRDY_Msk ) tusb_hal_nrf_power_event(USB_EVT_READY);
141163
#endif
142164
}
143165

hw/bsp/nrf/family.cmake

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,26 @@ if (NOT BOARD)
88
message(FATAL_ERROR "BOARD not specified")
99
endif ()
1010

11-
# toolchain set up
12-
set(CMAKE_SYSTEM_PROCESSOR cortex-m4 CACHE INTERNAL "System Processor")
13-
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_LIST_DIR}/../../../examples/cmake/toolchain/arm_${TOOLCHAIN}.cmake)
14-
15-
set(FAMILY_MCUS NRF5X CACHE INTERNAL "")
16-
1711
# TOP is path to root directory
1812
set(TOP "${CMAKE_CURRENT_LIST_DIR}/../../..")
1913
set(NRFX_DIR ${TOP}/hw/mcu/nordic/nrfx)
2014
set(CMSIS_DIR ${TOP}/lib/CMSIS_5)
2115

2216
# include board specific
2317
include(${CMAKE_CURRENT_LIST_DIR}/boards/${BOARD}/board.cmake)
24-
set(JLINK_DEVICE $(MCU_VARIANT)_xxaa)
18+
19+
# toolchain set up
20+
if (MCU_VARIANT STREQUAL "nrf5340_application")
21+
set(CMAKE_SYSTEM_PROCESSOR cortex-m33 CACHE INTERNAL "System Processor")
22+
set(JLINK_DEVICE nrf5340_xxaa_app)
23+
else ()
24+
set(CMAKE_SYSTEM_PROCESSOR cortex-m4 CACHE INTERNAL "System Processor")
25+
set(JLINK_DEVICE ${MCU_VARIANT}_xxaa)
26+
endif ()
27+
28+
set(CMAKE_TOOLCHAIN_FILE ${TOP}/examples/cmake/toolchain/arm_${TOOLCHAIN}.cmake)
29+
30+
set(FAMILY_MCUS NRF5X CACHE INTERNAL "")
2531

2632
#------------------------------------
2733
# BOARD_TARGET
@@ -40,8 +46,7 @@ if (NOT TARGET ${BOARD_TARGET})
4046
CONFIG_GPIO_AS_PINRESET
4147
)
4248
target_include_directories(${BOARD_TARGET} PUBLIC
43-
${NRFX_DIR}/../ # hw/mcu/nordic: remove later
44-
# driver
49+
${CMAKE_CURRENT_LIST_DIR}
4550
${NRFX_DIR}
4651
${NRFX_DIR}/mdk
4752
${NRFX_DIR}/hal
@@ -78,6 +83,8 @@ endif () # BOARD_TARGET
7883
# Functions
7984
#------------------------------------
8085
function(family_configure_target TARGET)
86+
#family_add_default_example_warnings(${TARGET})
87+
8188
# set output name to .elf
8289
set_target_properties(${TARGET} PROPERTIES OUTPUT_NAME ${TARGET}.elf)
8390

@@ -126,16 +133,23 @@ function(family_configure_target TARGET)
126133
#---------- Flash ----------
127134
# Flash using pyocd
128135
add_custom_target(${TARGET}-pyocd
136+
DEPENDS ${TARGET}
129137
COMMAND pyocd flash -t ${PYOCD_TARGET} $<TARGET_FILE:${TARGET}>
130138
)
131139

132-
# Flash using NXP LinkServer (redlink)
133-
# https://www.nxp.com/design/software/development-software/mcuxpresso-software-and-tools-/linkserver-for-microcontrollers:LINKERSERVER
134-
# LinkServer has a bug that can only execute with full path otherwise it throws:
135-
# realpath error: No such file or directory
136-
execute_process(COMMAND which LinkServer OUTPUT_VARIABLE LINKSERVER_PATH OUTPUT_STRIP_TRAILING_WHITESPACE)
137-
add_custom_target(${TARGET}-nxplink
138-
COMMAND ${LINKSERVER_PATH} flash ${NXPLINK_DEVICE} load $<TARGET_FILE:${TARGET}>
140+
# Flash using jlink
141+
set(JLINKEXE JLinkExe)
142+
file(GENERATE
143+
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.jlink
144+
CONTENT "halt
145+
loadfile $<TARGET_FILE:${TARGET}>
146+
r
147+
go
148+
exit"
149+
)
150+
add_custom_target(${TARGET}-jlink
151+
DEPENDS ${TARGET}
152+
COMMAND ${JLINKEXE} -device ${JLINK_DEVICE} -if swd -JTAGConf -1,-1 -speed auto -CommandFile ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.jlink
139153
)
140154

141155
endfunction()

hw/bsp/nrf/family.mk

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ CFLAGS += \
1414
-DCONFIG_GPIO_AS_PINRESET
1515

1616
# suppress warning caused by vendor mcu driver
17-
CFLAGS += -Wno-error=undef -Wno-error=unused-parameter -Wno-error=cast-align -Wno-error=cast-qual
17+
CFLAGS += -Wno-error=undef -Wno-error=unused-parameter -Wno-error=cast-align -Wno-error=cast-qual -Wno-error=redundant-decls
1818

1919
# All source paths should be relative to the top level.
2020
LD_FILE ?= hw/bsp/nrf/boards/$(BOARD)/nrf52840_s140_v6.ld
@@ -30,7 +30,6 @@ SRC_C += \
3030
INC += \
3131
$(TOP)/$(BOARD_PATH) \
3232
$(TOP)/lib/CMSIS_5/CMSIS/Core/Include \
33-
$(TOP)/hw/mcu/nordic \
3433
$(TOP)/hw/mcu/nordic/nrfx \
3534
$(TOP)/hw/mcu/nordic/nrfx/mdk \
3635
$(TOP)/hw/mcu/nordic/nrfx/hal \
@@ -45,4 +44,4 @@ ASFLAGS += -D__HEAP_SIZE=0
4544
FREERTOS_PORTABLE_SRC = $(FREERTOS_PORTABLE_PATH)/ARM_CM4F
4645

4746
# For flash-jlink target
48-
JLINK_DEVICE = $(MCU_VARIANT)_xxaa
47+
JLINK_DEVICE ?= $(MCU_VARIANT)_xxaa

hw/bsp/nrf/nrfx_config.h

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#ifndef NRFX_CONFIG_H__
2+
#define NRFX_CONFIG_H__
3+
4+
#define NRFX_POWER_ENABLED 1
5+
#define NRFX_POWER_DEFAULT_CONFIG_IRQ_PRIORITY 7
6+
7+
#define NRFX_CLOCK_ENABLED 0
8+
9+
#define NRFX_UARTE_ENABLED 1
10+
#define NRFX_UARTE0_ENABLED 1
11+
12+
#define NRFX_UARTE1_ENABLED 0
13+
#define NRFX_UARTE2_ENABLED 0
14+
#define NRFX_UARTE3_ENABLED 0
15+
16+
#define NRFX_PRS_ENABLED 0
17+
#define NRFX_USBREG_ENABLED 1
18+
19+
#if defined(NRF51)
20+
#include <templates/nrfx_config_nrf51.h>
21+
#elif defined(NRF52805_XXAA)
22+
#include <templates/nrfx_config_nrf52805.h>
23+
#elif defined(NRF52810_XXAA)
24+
#include <templates/nrfx_config_nrf52810.h>
25+
#elif defined(NRF52811_XXAA)
26+
#include <templates/nrfx_config_nrf52811.h>
27+
#elif defined(NRF52820_XXAA)
28+
#include <templates/nrfx_config_nrf52820.h>
29+
#elif defined(NRF52832_XXAA) || defined (NRF52832_XXAB)
30+
#include <templates/nrfx_config_nrf52832.h>
31+
#elif defined(NRF52833_XXAA)
32+
#include <templates/nrfx_config_nrf52833.h>
33+
#elif defined(NRF52840_XXAA)
34+
#include <templates/nrfx_config_nrf52840.h>
35+
#elif defined(NRF5340_XXAA_APPLICATION)
36+
#include <templates/nrfx_config_nrf5340_application.h>
37+
#elif defined(NRF5340_XXAA_NETWORK)
38+
#include <templates/nrfx_config_nrf5340_network.h>
39+
#elif defined(NRF9120_XXAA) || defined(NRF9160_XXAA)
40+
#include <templates/nrfx_config_nrf91.h>
41+
#else
42+
#error "Unknown device."
43+
#endif
44+
45+
46+
#endif // NRFX_CONFIG_H__

0 commit comments

Comments
 (0)