update nrf cmake and make to support nrf5340 (pca10095)

This commit is contained in:
hathach 2023-05-15 16:51:06 +07:00
parent 9f5b08dc93
commit d7175ad834
No known key found for this signature in database
GPG Key ID: F5D50C6D51D17CBA
13 changed files with 189 additions and 48 deletions

View File

@ -2,7 +2,8 @@
<project version="4">
<component name="CMakeSharedSettings">
<configurations>
<configuration PROFILE_NAME="pca10056" ENABLED="true" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DFAMILY=nrf -DBOARD=pca10056" />
<configuration PROFILE_NAME="pca10095" ENABLED="true" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DFAMILY=nrf -DBOARD=pca10095" BUILD_OPTIONS="-v" />
<configuration PROFILE_NAME="pca10056" ENABLED="false" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DFAMILY=nrf -DBOARD=pca10056" BUILD_OPTIONS="-v" />
<configuration PROFILE_NAME="lpc55s69" ENABLED="false" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DFAMILY=lpc55 -DBOARD=lpcxpresso55s69" />
<configuration PROFILE_NAME="esp32s3" ENABLED="false" GENERATION_OPTIONS="-DFAMILY=espressif -DBOARD=espressif_s3_devkitm -DIDF_TARGET=esp32s3">
<ADDITIONAL_GENERATION_ENVIRONMENT>

View File

@ -230,7 +230,7 @@ JLINK_IF ?= swd
# Flash using jlink
flash-jlink: $(BUILD)/$(PROJECT).hex
@echo halt > $(BUILD)/$(BOARD).jlink
@echo r > $(BUILD)/$(BOARD).jlink
@echo r >> $(BUILD)/$(BOARD).jlink
@echo loadfile $^ >> $(BUILD)/$(BOARD).jlink
@echo r >> $(BUILD)/$(BOARD).jlink
@echo go >> $(BUILD)/$(BOARD).jlink

View File

@ -130,6 +130,7 @@ function(family_configure_target TARGET)
#---------- Flash ----------
# Flash using pyocd
add_custom_target(${TARGET}-pyocd
DEPENDS ${TARGET}
COMMAND pyocd flash -t ${PYOCD_TARGET} $<TARGET_FILE:${TARGET}>
)
@ -139,6 +140,7 @@ function(family_configure_target TARGET)
# realpath error: No such file or directory
execute_process(COMMAND which LinkServer OUTPUT_VARIABLE LINKSERVER_PATH OUTPUT_STRIP_TRAILING_WHITESPACE)
add_custom_target(${TARGET}-nxplink
DEPENDS ${TARGET}
COMMAND ${LINKSERVER_PATH} flash ${NXPLINK_DEVICE} load $<TARGET_FILE:${TARGET}>
)

View File

@ -0,0 +1,12 @@
set(MCU_VARIANT nrf5340_application)
set(LD_FILE_gcc ${NRFX_DIR}/mdk/nrf5340_xxaa_application.ld)
function(update_board TARGET)
target_compile_definitions(${TARGET} PUBLIC
NRF5340_XXAA
NRF5340_XXAA_APPLICATION
)
target_sources(${TARGET} PUBLIC
${NRFX_DIR}/drivers/src/nrfx_usbreg.c
)
endfunction()

View File

@ -0,0 +1,50 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2020, Ha Thach (tinyusb.org)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* This file is part of the TinyUSB stack.
*/
#ifndef BOARD_H_
#define BOARD_H_
#ifdef __cplusplus
extern "C" {
#endif
// LED
#define LED_PIN 28
#define LED_STATE_ON 0
// Button
#define BUTTON_PIN 23
#define BUTTON_STATE_ACTIVE 0
// UART
#define UART_RX_PIN 32
#define UART_TX_PIN 33
#ifdef __cplusplus
}
#endif
#endif /* BOARD_H_ */

View File

@ -0,0 +1,13 @@
MCU_VARIANT = nrf5340_application
CFLAGS += -DNRF5340_XXAA -DNRF5340_XXAA_APPLICATION
LD_FILE = hw/mcu/nordic/nrfx/mdk/nrf5340_xxaa_application.ld
SRC_C += hw/mcu/nordic/nrfx/drivers/src/nrfx_usbreg.c
# caused by void SystemStoreFICRNS() (without void) in system_nrf5340_application.c
CFLAGS += -Wno-error=strict-prototypes
# flash using jlink
JLINK_DEVICE = nrf5340_xxaa_app
flash: flash-jlink

View File

@ -28,9 +28,9 @@
#include "board.h"
#include "nrfx.h"
#include "nrfx/hal/nrf_gpio.h"
#include "nrfx/drivers/include/nrfx_power.h"
#include "nrfx/drivers/include/nrfx_uarte.h"
#include "hal/nrf_gpio.h"
#include "drivers/include/nrfx_power.h"
#include "drivers/include/nrfx_uarte.h"
#ifdef SOFTDEVICE_PRESENT
#include "nrf_sdm.h"
@ -49,6 +49,23 @@ void USBD_IRQHandler(void)
/* MACRO TYPEDEF CONSTANT ENUM
*------------------------------------------------------------------*/
// Value is chosen to be as same as NRFX_POWER_USB_EVT_* in nrfx_power.h
enum {
USB_EVT_DETECTED = 0,
USB_EVT_REMOVED = 1,
USB_EVT_READY = 2
};
#ifdef NRF5340_XXAA
#define LFCLK_SRC_RC CLOCK_LFCLKSRC_SRC_LFRC
#define VBUSDETECT_Msk USBREG_USBREGSTATUS_VBUSDETECT_Msk
#define OUTPUTRDY_Msk USBREG_USBREGSTATUS_OUTPUTRDY_Msk
#else
#define LFCLK_SRC_RC CLOCK_LFCLKSRC_SRC_RC
#define VBUSDETECT_Msk POWER_USBREGSTATUS_VBUSDETECT_Msk
#define OUTPUTRDY_Msk POWER_USBREGSTATUS_OUTPUTRDY_Msk
#endif
static nrfx_uarte_t _uart_id = NRFX_UARTE_INSTANCE(0);
// tinyusb function that handles power event (detected, ready, removed)
@ -68,7 +85,7 @@ void board_init(void)
NRF_CLOCK->TASKS_LFCLKSTOP = 1UL;
// Use Internal OSC to compatible with all boards
NRF_CLOCK->LFCLKSRC = CLOCK_LFCLKSRC_SRC_RC;
NRF_CLOCK->LFCLKSRC = LFCLK_SRC_RC;
NRF_CLOCK->TASKS_LFCLKSTART = 1UL;
// LED
@ -123,21 +140,26 @@ void board_init(void)
#endif
{
// Power module init
const nrfx_power_config_t pwr_cfg = { 0 };
const nrfx_power_config_t pwr_cfg = {0};
nrfx_power_init(&pwr_cfg);
// Register tusb function as USB power handler
// cause cast-function-type warning
const nrfx_power_usbevt_config_t config = { .handler = power_event_handler };
const nrfx_power_usbevt_config_t config = {.handler = power_event_handler};
nrfx_power_usbevt_init(&config);
nrfx_power_usbevt_enable();
// USB power may already be ready at this time -> no event generated
// We need to invoke the handler based on the status initially
#ifdef NRF5340_XXAA
usb_reg = NRF_USBREGULATOR->USBREGSTATUS;
#else
usb_reg = NRF_POWER->USBREGSTATUS;
#endif
}
if ( usb_reg & POWER_USBREGSTATUS_VBUSDETECT_Msk ) tusb_hal_nrf_power_event(NRFX_POWER_USB_EVT_DETECTED);
if ( usb_reg & POWER_USBREGSTATUS_OUTPUTRDY_Msk ) tusb_hal_nrf_power_event(NRFX_POWER_USB_EVT_READY);
if ( usb_reg & VBUSDETECT_Msk ) tusb_hal_nrf_power_event(USB_EVT_DETECTED);
if ( usb_reg & OUTPUTRDY_Msk ) tusb_hal_nrf_power_event(USB_EVT_READY);
#endif
}

View File

@ -8,12 +8,6 @@ if (NOT BOARD)
message(FATAL_ERROR "BOARD not specified")
endif ()
# toolchain set up
set(CMAKE_SYSTEM_PROCESSOR cortex-m4 CACHE INTERNAL "System Processor")
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_LIST_DIR}/../../../examples/cmake/toolchain/arm_${TOOLCHAIN}.cmake)
set(FAMILY_MCUS NRF5X CACHE INTERNAL "")
# TOP is path to root directory
set(TOP "${CMAKE_CURRENT_LIST_DIR}/../../..")
set(NRFX_DIR ${TOP}/hw/mcu/nordic/nrfx)
@ -21,7 +15,19 @@ set(CMSIS_DIR ${TOP}/lib/CMSIS_5)
# include board specific
include(${CMAKE_CURRENT_LIST_DIR}/boards/${BOARD}/board.cmake)
set(JLINK_DEVICE $(MCU_VARIANT)_xxaa)
# toolchain set up
if (MCU_VARIANT STREQUAL "nrf5340_application")
set(CMAKE_SYSTEM_PROCESSOR cortex-m33 CACHE INTERNAL "System Processor")
set(JLINK_DEVICE nrf5340_xxaa_app)
else ()
set(CMAKE_SYSTEM_PROCESSOR cortex-m4 CACHE INTERNAL "System Processor")
set(JLINK_DEVICE ${MCU_VARIANT}_xxaa)
endif ()
set(CMAKE_TOOLCHAIN_FILE ${TOP}/examples/cmake/toolchain/arm_${TOOLCHAIN}.cmake)
set(FAMILY_MCUS NRF5X CACHE INTERNAL "")
#------------------------------------
# BOARD_TARGET
@ -40,8 +46,7 @@ if (NOT TARGET ${BOARD_TARGET})
CONFIG_GPIO_AS_PINRESET
)
target_include_directories(${BOARD_TARGET} PUBLIC
${NRFX_DIR}/../ # hw/mcu/nordic: remove later
# driver
${CMAKE_CURRENT_LIST_DIR}
${NRFX_DIR}
${NRFX_DIR}/mdk
${NRFX_DIR}/hal
@ -78,6 +83,8 @@ endif () # BOARD_TARGET
# Functions
#------------------------------------
function(family_configure_target TARGET)
#family_add_default_example_warnings(${TARGET})
# set output name to .elf
set_target_properties(${TARGET} PROPERTIES OUTPUT_NAME ${TARGET}.elf)
@ -126,16 +133,23 @@ function(family_configure_target TARGET)
#---------- Flash ----------
# Flash using pyocd
add_custom_target(${TARGET}-pyocd
DEPENDS ${TARGET}
COMMAND pyocd flash -t ${PYOCD_TARGET} $<TARGET_FILE:${TARGET}>
)
# Flash using NXP LinkServer (redlink)
# https://www.nxp.com/design/software/development-software/mcuxpresso-software-and-tools-/linkserver-for-microcontrollers:LINKERSERVER
# LinkServer has a bug that can only execute with full path otherwise it throws:
# realpath error: No such file or directory
execute_process(COMMAND which LinkServer OUTPUT_VARIABLE LINKSERVER_PATH OUTPUT_STRIP_TRAILING_WHITESPACE)
add_custom_target(${TARGET}-nxplink
COMMAND ${LINKSERVER_PATH} flash ${NXPLINK_DEVICE} load $<TARGET_FILE:${TARGET}>
# Flash using jlink
set(JLINKEXE JLinkExe)
file(GENERATE
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.jlink
CONTENT "halt
loadfile $<TARGET_FILE:${TARGET}>
r
go
exit"
)
add_custom_target(${TARGET}-jlink
DEPENDS ${TARGET}
COMMAND ${JLINKEXE} -device ${JLINK_DEVICE} -if swd -JTAGConf -1,-1 -speed auto -CommandFile ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.jlink
)
endfunction()

View File

@ -14,7 +14,7 @@ CFLAGS += \
-DCONFIG_GPIO_AS_PINRESET
# suppress warning caused by vendor mcu driver
CFLAGS += -Wno-error=undef -Wno-error=unused-parameter -Wno-error=cast-align -Wno-error=cast-qual
CFLAGS += -Wno-error=undef -Wno-error=unused-parameter -Wno-error=cast-align -Wno-error=cast-qual -Wno-error=redundant-decls
# All source paths should be relative to the top level.
LD_FILE ?= hw/bsp/nrf/boards/$(BOARD)/nrf52840_s140_v6.ld
@ -30,7 +30,6 @@ SRC_C += \
INC += \
$(TOP)/$(BOARD_PATH) \
$(TOP)/lib/CMSIS_5/CMSIS/Core/Include \
$(TOP)/hw/mcu/nordic \
$(TOP)/hw/mcu/nordic/nrfx \
$(TOP)/hw/mcu/nordic/nrfx/mdk \
$(TOP)/hw/mcu/nordic/nrfx/hal \
@ -45,4 +44,4 @@ ASFLAGS += -D__HEAP_SIZE=0
FREERTOS_PORTABLE_SRC = $(FREERTOS_PORTABLE_PATH)/ARM_CM4F
# For flash-jlink target
JLINK_DEVICE = $(MCU_VARIANT)_xxaa
JLINK_DEVICE ?= $(MCU_VARIANT)_xxaa

46
hw/bsp/nrf/nrfx_config.h Normal file
View File

@ -0,0 +1,46 @@
#ifndef NRFX_CONFIG_H__
#define NRFX_CONFIG_H__
#define NRFX_POWER_ENABLED 1
#define NRFX_POWER_DEFAULT_CONFIG_IRQ_PRIORITY 7
#define NRFX_CLOCK_ENABLED 0
#define NRFX_UARTE_ENABLED 1
#define NRFX_UARTE0_ENABLED 1
#define NRFX_UARTE1_ENABLED 0
#define NRFX_UARTE2_ENABLED 0
#define NRFX_UARTE3_ENABLED 0
#define NRFX_PRS_ENABLED 0
#define NRFX_USBREG_ENABLED 1
#if defined(NRF51)
#include <templates/nrfx_config_nrf51.h>
#elif defined(NRF52805_XXAA)
#include <templates/nrfx_config_nrf52805.h>
#elif defined(NRF52810_XXAA)
#include <templates/nrfx_config_nrf52810.h>
#elif defined(NRF52811_XXAA)
#include <templates/nrfx_config_nrf52811.h>
#elif defined(NRF52820_XXAA)
#include <templates/nrfx_config_nrf52820.h>
#elif defined(NRF52832_XXAA) || defined (NRF52832_XXAB)
#include <templates/nrfx_config_nrf52832.h>
#elif defined(NRF52833_XXAA)
#include <templates/nrfx_config_nrf52833.h>
#elif defined(NRF52840_XXAA)
#include <templates/nrfx_config_nrf52840.h>
#elif defined(NRF5340_XXAA_APPLICATION)
#include <templates/nrfx_config_nrf5340_application.h>
#elif defined(NRF5340_XXAA_NETWORK)
#include <templates/nrfx_config_nrf5340_network.h>
#elif defined(NRF9120_XXAA) || defined(NRF9160_XXAA)
#include <templates/nrfx_config_nrf91.h>
#else
#error "Unknown device."
#endif
#endif // NRFX_CONFIG_H__

View File

@ -1,18 +0,0 @@
#ifndef NRFX_CONFIG_H__
#define NRFX_CONFIG_H__
#define NRFX_POWER_ENABLED 1
#define NRFX_POWER_DEFAULT_CONFIG_IRQ_PRIORITY 7
#define NRFX_CLOCK_ENABLED 0
#define NRFX_UARTE_ENABLED 1
#define NRFX_UARTE0_ENABLED 1
#define NRFX_UARTE1_ENABLED 0
#define NRFX_UARTE2_ENABLED 0
#define NRFX_UARTE3_ENABLED 0
#define NRFX_PRS_ENABLED 0
#endif // NRFX_CONFIG_H__