mirror of
https://github.com/hathach/tinyusb.git
synced 2025-01-31 05:52:55 +08:00
- update nrfx to v3.4.0
- compile nrf with __STARTUP_CLEAR_BSS and link flag -nostartfiles
This commit is contained in:
parent
83b4cb178b
commit
9d1d171b0c
@ -1,5 +1,4 @@
|
|||||||
set(MCU_VARIANT nrf52840)
|
set(MCU_VARIANT nrf52840)
|
||||||
set(LD_FILE_GNU ${NRFX_DIR}/mdk/nrf52840_xxaa.ld)
|
|
||||||
|
|
||||||
function(update_board TARGET)
|
function(update_board TARGET)
|
||||||
endfunction()
|
endfunction()
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
#pragma GCC diagnostic ignored "-Wcast-qual"
|
#pragma GCC diagnostic ignored "-Wcast-qual"
|
||||||
#pragma GCC diagnostic ignored "-Wcast-align"
|
#pragma GCC diagnostic ignored "-Wcast-align"
|
||||||
#pragma GCC diagnostic ignored "-Wunused-parameter"
|
#pragma GCC diagnostic ignored "-Wunused-parameter"
|
||||||
|
#pragma GCC diagnostic ignored "-Wunused-variable"
|
||||||
#pragma GCC diagnostic ignored "-Wundef"
|
#pragma GCC diagnostic ignored "-Wundef"
|
||||||
#pragma GCC diagnostic ignored "-Wredundant-decls"
|
#pragma GCC diagnostic ignored "-Wredundant-decls"
|
||||||
#endif
|
#endif
|
||||||
@ -54,6 +55,14 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
// There is API changes between nrfx v2 and v3
|
||||||
|
#if 85301 >= (10000*MDK_MAJOR_VERSION + 100*MDK_MINOR_VERSION + MDK_MICRO_VERSION)
|
||||||
|
// note MDK 8.53.1 is also used by nrfx v3.0.0, just skip this version and use later 3.x
|
||||||
|
#define NRFX_VER 2
|
||||||
|
#else
|
||||||
|
#define NRFX_VER 3
|
||||||
|
#endif
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// Forward USB interrupt events to TinyUSB IRQ Handler
|
// Forward USB interrupt events to TinyUSB IRQ Handler
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
@ -100,11 +109,19 @@ static void max3421_init(void);
|
|||||||
static nrfx_spim_t _spi = NRFX_SPIM_INSTANCE(1);
|
static nrfx_spim_t _spi = NRFX_SPIM_INSTANCE(1);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
//
|
//
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
|
|
||||||
|
// Implement _start() since we use linker flag '-nostartfiles'.
|
||||||
|
// Requires defined __STARTUP_CLEAR_BSS,
|
||||||
|
extern int main(void);
|
||||||
|
TU_ATTR_UNUSED void _start(void) {
|
||||||
|
// called by startup code
|
||||||
|
main();
|
||||||
|
while (1) {}
|
||||||
|
}
|
||||||
|
|
||||||
void board_init(void) {
|
void board_init(void) {
|
||||||
// stop LF clock just in case we jump from application without reset
|
// stop LF clock just in case we jump from application without reset
|
||||||
NRF_CLOCK->TASKS_LFCLKSTOP = 1UL;
|
NRF_CLOCK->TASKS_LFCLKSTOP = 1UL;
|
||||||
@ -124,6 +141,7 @@ void board_init(void) {
|
|||||||
SysTick_Config(SystemCoreClock / 1000);
|
SysTick_Config(SystemCoreClock / 1000);
|
||||||
|
|
||||||
// UART
|
// UART
|
||||||
|
#if NRFX_VER == 2
|
||||||
nrfx_uarte_config_t uart_cfg = {
|
nrfx_uarte_config_t uart_cfg = {
|
||||||
.pseltxd = UART_TX_PIN,
|
.pseltxd = UART_TX_PIN,
|
||||||
.pselrxd = UART_RX_PIN,
|
.pselrxd = UART_RX_PIN,
|
||||||
@ -137,6 +155,21 @@ void board_init(void) {
|
|||||||
.parity = NRF_UARTE_PARITY_EXCLUDED,
|
.parity = NRF_UARTE_PARITY_EXCLUDED,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
#elif NRFX_VER == 3
|
||||||
|
nrfx_uarte_config_t uart_cfg = {
|
||||||
|
.txd_pin = UART_TX_PIN,
|
||||||
|
.rxd_pin = UART_RX_PIN,
|
||||||
|
.rts_pin = NRF_UARTE_PSEL_DISCONNECTED,
|
||||||
|
.cts_pin = NRF_UARTE_PSEL_DISCONNECTED,
|
||||||
|
.p_context = NULL,
|
||||||
|
.baudrate = NRF_UARTE_BAUDRATE_115200, // CFG_BOARD_UART_BAUDRATE
|
||||||
|
.interrupt_priority = 7,
|
||||||
|
.config = {
|
||||||
|
.hwfc = NRF_UARTE_HWFC_DISABLED,
|
||||||
|
.parity = NRF_UARTE_PARITY_EXCLUDED,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
nrfx_uarte_init(&_uart_id, &uart_cfg, NULL); //uart_handler);
|
nrfx_uarte_init(&_uart_id, &uart_cfg, NULL); //uart_handler);
|
||||||
|
|
||||||
@ -224,11 +257,17 @@ int board_uart_read(uint8_t* buf, int len) {
|
|||||||
(void) buf;
|
(void) buf;
|
||||||
(void) len;
|
(void) len;
|
||||||
return 0;
|
return 0;
|
||||||
// return NRFX_SUCCESS == nrfx_uart_rx(&_uart_id, buf, (size_t) len) ? len : 0;
|
// nrfx_err_t err = nrfx_uarte_rx(&_uart_id, buf, (size_t) len);
|
||||||
|
// return NRFX_SUCCESS == err ? len : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int board_uart_write(void const* buf, int len) {
|
int board_uart_write(void const* buf, int len) {
|
||||||
return (NRFX_SUCCESS == nrfx_uarte_tx(&_uart_id, (uint8_t const*) buf, (size_t) len)) ? len : 0;
|
nrfx_err_t err = nrfx_uarte_tx(&_uart_id, (uint8_t const*) buf, (size_t) len
|
||||||
|
#if NRFX_VER == 3
|
||||||
|
,0
|
||||||
|
#endif
|
||||||
|
);
|
||||||
|
return (NRFX_SUCCESS == err) ? len : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if CFG_TUSB_OS == OPT_OS_NONE
|
#if CFG_TUSB_OS == OPT_OS_NONE
|
||||||
@ -241,7 +280,6 @@ void SysTick_Handler(void) {
|
|||||||
uint32_t board_millis(void) {
|
uint32_t board_millis(void) {
|
||||||
return system_ticks;
|
return system_ticks;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef SOFTDEVICE_PRESENT
|
#ifdef SOFTDEVICE_PRESENT
|
||||||
|
@ -31,14 +31,13 @@ set(FAMILY_MCUS NRF5X CACHE INTERNAL "")
|
|||||||
function(add_board_target BOARD_TARGET)
|
function(add_board_target BOARD_TARGET)
|
||||||
if (NOT TARGET ${BOARD_TARGET})
|
if (NOT TARGET ${BOARD_TARGET})
|
||||||
if (NOT DEFINED LD_FILE_${CMAKE_C_COMPILER_ID})
|
if (NOT DEFINED LD_FILE_${CMAKE_C_COMPILER_ID})
|
||||||
set(LD_FILE_GNU ${NRFX_DIR}/mdk/${MCU_VARIANT}_xxaa.ld)
|
set(LD_FILE_GNU ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/linker/${MCU_VARIANT}_xxaa.ld)
|
||||||
set(LD_FILE_Clang ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/linker/clang/${MCU_VARIANT}_xxaa.ld)
|
set(LD_FILE_Clang ${LD_FILE_GNU})
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
if (NOT DEFINED STARTUP_FILE_${CMAKE_C_COMPILER_ID})
|
if (NOT DEFINED STARTUP_FILE_${CMAKE_C_COMPILER_ID})
|
||||||
set(STARTUP_FILE_GNU ${NRFX_DIR}/mdk/gcc_startup_${MCU_VARIANT}.S)
|
set(STARTUP_FILE_GNU ${NRFX_DIR}/mdk/gcc_startup_${MCU_VARIANT}.S)
|
||||||
set(STARTUP_FILE_Clang ${STARTUP_FILE_GNU})
|
set(STARTUP_FILE_Clang ${STARTUP_FILE_GNU})
|
||||||
#set(STARTUP_FILE_Clang ${NRFX_DIR}/mdk/arm_startup_${MCU_VARIANT}.s)
|
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
add_library(${BOARD_TARGET} STATIC
|
add_library(${BOARD_TARGET} STATIC
|
||||||
@ -48,9 +47,13 @@ function(add_board_target BOARD_TARGET)
|
|||||||
${NRFX_DIR}/drivers/src/nrfx_spim.c
|
${NRFX_DIR}/drivers/src/nrfx_spim.c
|
||||||
${NRFX_DIR}/drivers/src/nrfx_uarte.c
|
${NRFX_DIR}/drivers/src/nrfx_uarte.c
|
||||||
${NRFX_DIR}/mdk/system_${MCU_VARIANT}.c
|
${NRFX_DIR}/mdk/system_${MCU_VARIANT}.c
|
||||||
|
${NRFX_DIR}/soc/nrfx_atomic.c
|
||||||
${STARTUP_FILE_${CMAKE_C_COMPILER_ID}}
|
${STARTUP_FILE_${CMAKE_C_COMPILER_ID}}
|
||||||
)
|
)
|
||||||
target_compile_definitions(${BOARD_TARGET} PUBLIC CONFIG_GPIO_AS_PINRESET)
|
target_compile_definitions(${BOARD_TARGET} PUBLIC
|
||||||
|
__STARTUP_CLEAR_BSS
|
||||||
|
CONFIG_GPIO_AS_PINRESET
|
||||||
|
)
|
||||||
|
|
||||||
if (MCU_VARIANT STREQUAL "nrf52840")
|
if (MCU_VARIANT STREQUAL "nrf52840")
|
||||||
target_compile_definitions(${BOARD_TARGET} PUBLIC NRF52840_XXAA)
|
target_compile_definitions(${BOARD_TARGET} PUBLIC NRF52840_XXAA)
|
||||||
@ -82,12 +85,12 @@ function(add_board_target BOARD_TARGET)
|
|||||||
"LINKER:--script=${LD_FILE_GNU}"
|
"LINKER:--script=${LD_FILE_GNU}"
|
||||||
-L${NRFX_DIR}/mdk
|
-L${NRFX_DIR}/mdk
|
||||||
--specs=nosys.specs --specs=nano.specs
|
--specs=nosys.specs --specs=nano.specs
|
||||||
|
-nostartfiles
|
||||||
)
|
)
|
||||||
elseif (CMAKE_C_COMPILER_ID STREQUAL "Clang")
|
elseif (CMAKE_C_COMPILER_ID STREQUAL "Clang")
|
||||||
target_link_options(${BOARD_TARGET} PUBLIC
|
target_link_options(${BOARD_TARGET} PUBLIC
|
||||||
"LINKER:--script=${LD_FILE_Clang}"
|
"LINKER:--script=${LD_FILE_Clang}"
|
||||||
-L${NRFX_DIR}/mdk
|
-L${NRFX_DIR}/mdk
|
||||||
-lcrt0
|
|
||||||
)
|
)
|
||||||
elseif (CMAKE_C_COMPILER_ID STREQUAL "IAR")
|
elseif (CMAKE_C_COMPILER_ID STREQUAL "IAR")
|
||||||
target_link_options(${BOARD_TARGET} PUBLIC
|
target_link_options(${BOARD_TARGET} PUBLIC
|
||||||
|
26
hw/bsp/nrf/linker/nrf52840_xxaa.ld
Normal file
26
hw/bsp/nrf/linker/nrf52840_xxaa.ld
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
/* Linker script to configure memory regions. */
|
||||||
|
|
||||||
|
SEARCH_DIR(.)
|
||||||
|
|
||||||
|
MEMORY
|
||||||
|
{
|
||||||
|
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x100000
|
||||||
|
EXTFLASH (rx) : ORIGIN = 0x12000000, LENGTH = 0x8000000
|
||||||
|
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x40000
|
||||||
|
CODE_RAM (rwx) : ORIGIN = 0x800000, LENGTH = 0x40000
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
INCLUDE "nrf_common.ld"
|
||||||
|
|
||||||
|
/* nrfx v2 linker does not define __tbss_start/end__ __sbss_start/end__*/
|
||||||
|
/*__tbss_start__ = __tbss_start;*/
|
||||||
|
/*__tbss_end__ = __tbss_end;*/
|
||||||
|
/*__sbss_start__ = __sbss_start;*/
|
||||||
|
/*__sbss_end__ = __sbss_end;*/
|
||||||
|
|
||||||
|
/* picolibc crt0 */
|
||||||
|
/*__data_source = __copy_table_start__;*/
|
||||||
|
/*__tls_base = __tdata_start;*/
|
||||||
|
/*PROVIDE( __tls_align = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss)) );*/
|
||||||
|
/*PROVIDE( __arm32_tls_tcb_offset = MAX(8, __tls_align) );*/
|
@ -58,7 +58,8 @@
|
|||||||
|
|
||||||
/* Try to detect nrfx version if not configured with CFG_TUD_NRF_NRFX_VERSION
|
/* Try to detect nrfx version if not configured with CFG_TUD_NRF_NRFX_VERSION
|
||||||
* nrfx v1 and v2 are concurrently developed. There is no NRFX_VERSION only MDK VERSION which is as follows:
|
* nrfx v1 and v2 are concurrently developed. There is no NRFX_VERSION only MDK VERSION which is as follows:
|
||||||
* - v2.6.0: 8.44.1, v2.5.0: 8.40.2, v2.4.0: 8.37.0, v2.3.0: 8.35.0, v2.2.0: 8.32.1, v2.1.0: 8.30.2, v2.0.0: 8.29.0
|
* - v3.0.0: 8.53.1 (conflict with v2.11.0), v3.1.0: 8.55.0 ...
|
||||||
|
* - v2.11.0: 8.53.1, v2.6.0: 8.44.1, v2.5.0: 8.40.2, v2.4.0: 8.37.0, v2.3.0: 8.35.0, v2.2.0: 8.32.1, v2.1.0: 8.30.2, v2.0.0: 8.29.0
|
||||||
* - v1.9.0: 8.40.3, v1.8.6: 8.35.0 (conflict with v2.3.0), v1.8.5: 8.32.3, v1.8.4: 8.32.1 (conflict with v2.2.0),
|
* - v1.9.0: 8.40.3, v1.8.6: 8.35.0 (conflict with v2.3.0), v1.8.5: 8.32.3, v1.8.4: 8.32.1 (conflict with v2.2.0),
|
||||||
* v1.8.2: 8.32.1 (conflict with v2.2.0), v1.8.1: 8.27.1
|
* v1.8.2: 8.32.1 (conflict with v2.2.0), v1.8.1: 8.27.1
|
||||||
* Therefore the check for v1 would be:
|
* Therefore the check for v1 would be:
|
||||||
|
@ -42,7 +42,7 @@ deps_optional = {
|
|||||||
'0b79559eb411149d36e073c1635c620e576308d4',
|
'0b79559eb411149d36e073c1635c620e576308d4',
|
||||||
'mm32'],
|
'mm32'],
|
||||||
'hw/mcu/nordic/nrfx': ['https://github.com/NordicSemiconductor/nrfx.git',
|
'hw/mcu/nordic/nrfx': ['https://github.com/NordicSemiconductor/nrfx.git',
|
||||||
'2527e3c8449cfd38aee41598e8af8492f410ed15',
|
'7c47cc0a56ce44658e6da2458e86cd8783ccc4a2',
|
||||||
'nrf'],
|
'nrf'],
|
||||||
'hw/mcu/nuvoton': ['https://github.com/majbthrd/nuc_driver.git',
|
'hw/mcu/nuvoton': ['https://github.com/majbthrd/nuc_driver.git',
|
||||||
'2204191ec76283371419fbcec207da02e1bc22fa',
|
'2204191ec76283371419fbcec207da02e1bc22fa',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user