This commit is contained in:
hathach
2025-01-16 10:46:37 +07:00
parent c8130afe9b
commit 91214b4614
16 changed files with 372 additions and 111 deletions

View File

@@ -38,22 +38,24 @@ extern "C" {
#include "tusb.h"
#if CFG_TUSB_OS == OPT_OS_FREERTOS
#if TUSB_MCU_VENDOR_ESPRESSIF
// ESP-IDF need "freertos/" prefix in include path.
// CFG_TUSB_OS_INC_PATH should be defined accordingly.
#include "freertos/FreeRTOS.h"
#include "freertos/semphr.h"
#include "freertos/queue.h"
#include "freertos/task.h"
#include "freertos/timers.h"
#else
#include "FreeRTOS.h"
#include "semphr.h"
#include "queue.h"
#include "task.h"
#include "timers.h"
#endif
#if CFG_TUSB_OS == OPT_OS_ZEPHYR
#include <zephyr/kernel.h>
#elif CFG_TUSB_OS == OPT_OS_FREERTOS
#if TUSB_MCU_VENDOR_ESPRESSIF
// ESP-IDF need "freertos/" prefix in include path.
// CFG_TUSB_OS_INC_PATH should be defined accordingly.
#include "freertos/FreeRTOS.h"
#include "freertos/semphr.h"
#include "freertos/queue.h"
#include "freertos/task.h"
#include "freertos/timers.h"
#else
#include "FreeRTOS.h"
#include "semphr.h"
#include "queue.h"
#include "task.h"
#include "timers.h"
#endif
#endif
// Define the default baudrate
@@ -124,6 +126,10 @@ static inline uint32_t board_millis(void) {
// Implement your own board_millis() in any of .c file
uint32_t board_millis(void);
#elif CFG_TUSB_OS == OPT_OS_ZEPHYR
static inline uint32_t board_millis(void) {
return k_uptime_get_32();
}
#else
#error "board_millis() is not implemented for this OS"
#endif

View File

@@ -73,34 +73,39 @@ if (NOT NO_WARN_RWX_SEGMENTS_SUPPORTED)
set(NO_WARN_RWX_SEGMENTS_SUPPORTED 1)
endif()
set(WARNING_FLAGS_GNU
-Wall
-Wextra
-Werror
-Wfatal-errors
-Wdouble-promotion
-Wstrict-prototypes
-Wstrict-overflow
-Werror-implicit-function-declaration
-Wfloat-equal
-Wundef
-Wshadow
-Wwrite-strings
-Wsign-compare
-Wmissing-format-attribute
-Wunreachable-code
-Wcast-align
-Wcast-function-type
-Wcast-qual
-Wnull-dereference
-Wuninitialized
-Wunused
-Wreturn-type
-Wredundant-decls
)
#set(WARNING_FLAGS_GNU
# -Wall
# -Wextra
# -Werror
# -Wfatal-errors
# -Wdouble-promotion
# -Wstrict-prototypes
# -Wstrict-overflow
# -Werror-implicit-function-declaration
# -Wfloat-equal
# -Wundef
# -Wshadow
# -Wwrite-strings
# -Wsign-compare
# -Wmissing-format-attribute
# -Wunreachable-code
# -Wcast-align
# -Wcast-function-type
# -Wcast-qual
# -Wnull-dereference
# -Wuninitialized
# -Wunused
# -Wreturn-type
# -Wredundant-decls
# )
set(WARNING_FLAGS_IAR "")
#if (BUILD_ZEPHYR)
# set(BOARD_ROOT ${TOP}/hw/bsp/${FAMILY})
# find_package(Zephyr REQUIRED HINTS ${TOP}/lib/zephyr)
#endif ()
#-------------------------------------------------------------
# Functions
#-------------------------------------------------------------
@@ -216,7 +221,7 @@ function(family_configure_common TARGET RTOS)
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
target_link_options(${TARGET} PUBLIC "LINKER:-Map=$<TARGET_FILE:${TARGET}>.map")
if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 12.0 AND NO_WARN_RWX_SEGMENTS_SUPPORTED)
target_link_options(${TARGET} PUBLIC "LINKER:--no-warn-rwx-segments")
# target_link_options(${TARGET} PUBLIC "LINKER:--no-warn-rwx-segments")
endif ()
elseif (CMAKE_C_COMPILER_ID STREQUAL "Clang")
target_link_options(${TARGET} PUBLIC "LINKER:-Map=$<TARGET_FILE:${TARGET}>.map")
@@ -244,12 +249,12 @@ function(family_configure_common TARGET RTOS)
endif ()
# run size after build
find_program(SIZE_EXE ${CMAKE_SIZE})
if(NOT ${SIZE_EXE} STREQUAL SIZE_EXE-NOTFOUND)
add_custom_command(TARGET ${TARGET} POST_BUILD
COMMAND ${SIZE_EXE} $<TARGET_FILE:${TARGET}>
)
endif ()
# find_program(SIZE_EXE ${CMAKE_SIZE})
# if(NOT ${SIZE_EXE} STREQUAL SIZE_EXE-NOTFOUND)
# add_custom_command(TARGET ${TARGET} POST_BUILD
# COMMAND ${SIZE_EXE} $<TARGET_FILE:${TARGET}>
# )
# endif ()
endfunction()
# Add tinyusb to example
@@ -272,6 +277,8 @@ function(family_add_tinyusb TARGET OPT_MCU RTOS)
if (RTOS STREQUAL "freertos")
target_compile_definitions(${TARGET}-tinyusb_config INTERFACE CFG_TUSB_OS=OPT_OS_FREERTOS)
elseif (RTOS STREQUAL "zephyr")
target_compile_definitions(${TARGET}-tinyusb_config INTERFACE CFG_TUSB_OS=OPT_OS_ZEPHYR)
endif ()
# tinyusb's CMakeList.txt
@@ -280,6 +287,8 @@ function(family_add_tinyusb TARGET OPT_MCU RTOS)
if (RTOS STREQUAL "freertos")
# link tinyusb with freeRTOS kernel
target_link_libraries(${TARGET}-tinyusb PUBLIC freertos_kernel)
elseif (RTOS STREQUAL "zephyr")
target_include_directories(${TARGET}-tinyusb PUBLIC ${ZEPHYR_BASE}/include)
endif ()
# use max3421 as host controller
@@ -353,33 +362,33 @@ endfunction()
# RPI specific: refactor later
#----------------------------------
function(family_add_default_example_warnings TARGET)
target_compile_options(${TARGET} PUBLIC
-Wall
-Wextra
-Werror
-Wfatal-errors
-Wdouble-promotion
-Wfloat-equal
# FIXME commented out because of https://github.com/raspberrypi/pico-sdk/issues/1468
#-Wshadow
-Wwrite-strings
-Wsign-compare
-Wmissing-format-attribute
-Wunreachable-code
-Wcast-align
-Wcast-qual
-Wnull-dereference
-Wuninitialized
-Wunused
-Wredundant-decls
#-Wstrict-prototypes
#-Werror-implicit-function-declaration
#-Wundef
)
# target_compile_options(${TARGET} PUBLIC
# -Wall
# -Wextra
# -Werror
# -Wfatal-errors
# -Wdouble-promotion
# -Wfloat-equal
# # FIXME commented out because of https://github.com/raspberrypi/pico-sdk/issues/1468
# #-Wshadow
# -Wwrite-strings
# -Wsign-compare
# -Wmissing-format-attribute
# -Wunreachable-code
# -Wcast-align
# -Wcast-qual
# -Wnull-dereference
# -Wuninitialized
# -Wunused
# -Wredundant-decls
# #-Wstrict-prototypes
# #-Werror-implicit-function-declaration
# #-Wundef
# )
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 12.0 AND NO_WARN_RWX_SEGMENTS_SUPPORTED)
target_link_options(${TARGET} PUBLIC "LINKER:--no-warn-rwx-segments")
# target_link_options(${TARGET} PUBLIC "LINKER:--no-warn-rwx-segments")
endif()
# GCC 10

View File

@@ -2,3 +2,9 @@ set(MCU_VARIANT nrf52840)
function(update_board TARGET)
endfunction()
#board_runner_args(jlink "--device=nRF52840_xxAA" "--speed=4000")
#include(${ZEPHYR_BASE}/boards/common/nrfjprog.board.cmake)
#include(${ZEPHYR_BASE}/boards/common/nrfutil.board.cmake)
#include(${ZEPHYR_BASE}/boards/common/jlink.board.cmake)
#include(${ZEPHYR_BASE}/boards/common/openocd-nrf5.board.cmake)

View File

@@ -67,6 +67,8 @@
#define NRFX_VER 3
#endif
extern void nrfx_isr(const void *irq_handler);
//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
@@ -137,8 +139,22 @@ void board_init(void) {
// Button
nrf_gpio_cfg_input(BUTTON_PIN, NRF_GPIO_PIN_PULLUP);
#if CFG_TUSB_OS == OPT_OS_NONE
// 1ms tick timer
SysTick_Config(SystemCoreClock / 1000);
#elif CFG_TUSB_OS == OPT_OS_ZEPHYR
#ifdef CONFIG_HAS_HW_NRF_USBREG
// IRQ_CONNECT(USBREGULATOR_IRQn, DT_IRQ(DT_INST(0, nordic_nrf_clock), priority), nrfx_isr, nrfx_usbreg_irq_handler, 0);
// irq_enable(USBREGULATOR_IRQn);
#endif
// IRQ_CONNECT(CLOCK_POWER_IRQn, 0, nrfx_isr, nrfx_power_irq_handler, 0);
/* USB device controller access from devicetree */
// #define DT_DRV_COMPAT nordic_nrf_usbd
// IRQ_CONNECT(DT_INST_IRQN(0), DT_INST_IRQ(0, priority), nrfx_isr, nrf_usbd_common_irq_handler, 0);
#endif
// UART
#if NRFX_VER <= 2

View File

@@ -8,10 +8,10 @@ include(${CMAKE_CURRENT_LIST_DIR}/boards/${BOARD}/board.cmake)
# toolchain set up
if (MCU_VARIANT STREQUAL "nrf5340_application")
set(CMAKE_SYSTEM_PROCESSOR cortex-m33 CACHE INTERNAL "System Processor")
set(CMAKE_SYSTEM_CPU cortex-m33 CACHE INTERNAL "System Processor")
set(JLINK_DEVICE nrf5340_xxaa_app)
else ()
set(CMAKE_SYSTEM_PROCESSOR cortex-m4 CACHE INTERNAL "System Processor")
set(CMAKE_SYSTEM_CPU cortex-m4 CACHE INTERNAL "System Processor")
set(JLINK_DEVICE ${MCU_VARIANT}_xxaa)
endif ()
@@ -113,12 +113,16 @@ endfunction()
function(family_configure_example TARGET RTOS)
family_configure_common(${TARGET} ${RTOS})
# Board target
add_board_target(board_${BOARD})
if (BUILD_ZEPHYR)
#target_link_libraries(board_${BOARD} PUBLIC zephyr_interface kernel)
elseif ()
# Board target
add_board_target(board_${BOARD})
endif ()
#---------- Port Specific ----------
# These files are built for each example since it depends on example's tusb_config.h
target_sources(${TARGET} PUBLIC
target_sources(${TARGET} PRIVATE
# BSP
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/family.c
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../board.c
@@ -132,16 +136,20 @@ function(family_configure_example TARGET RTOS)
# Add TinyUSB target and port source
family_add_tinyusb(${TARGET} OPT_MCU_NRF5X ${RTOS})
target_sources(${TARGET}-tinyusb PUBLIC
target_sources(${TARGET}-tinyusb PRIVATE
${TOP}/src/portable/nordic/nrf5x/dcd_nrf5x.c
)
target_link_libraries(${TARGET}-tinyusb PUBLIC board_${BOARD})
# Link dependencies
target_link_libraries(${TARGET} PUBLIC board_${BOARD} ${TARGET}-tinyusb)
if (BUILD_ZEPHYR)
target_link_libraries(${TARGET}-tinyusb PUBLIC zephyr_interface kernel)
target_link_libraries(${TARGET} PUBLIC ${TARGET}-tinyusb)
elseif ()
target_link_libraries(${TARGET}-tinyusb PUBLIC board_${BOARD})
target_link_libraries(${TARGET} PUBLIC board_${BOARD} ${TARGET}-tinyusb)
endif ()
# Flashing
family_add_bin_hex(${TARGET})
#family_add_bin_hex(${TARGET})
family_flash_jlink(${TARGET})
# family_flash_adafruit_nrfutil(${TARGET})
endfunction()

View File

@@ -1,7 +1,9 @@
/*
* Copyright (c) 2017 - 2018, Nordic Semiconductor ASA
* Copyright (c) 2017 - 2024, Nordic Semiconductor ASA
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
@@ -60,14 +62,14 @@ extern "C" {
/**
* @brief Macro for placing a runtime assertion.
*
* @param expression Expression to evaluate.
* @param expression Expression to be evaluated.
*/
#define NRFX_ASSERT(expression)
/**
* @brief Macro for placing a compile time assertion.
*
* @param expression Expression to evaluate.
* @param expression Expression to be evaluated.
*/
#define NRFX_STATIC_ASSERT(expression)
@@ -76,8 +78,8 @@ extern "C" {
/**
* @brief Macro for setting the priority of a specific IRQ.
*
* @param irq_number IRQ number.
* @param priority Priority to set.
* @param irq_number IRQ number.
* @param priority Priority to be set.
*/
#define NRFX_IRQ_PRIORITY_SET(irq_number, priority) _NRFX_IRQ_PRIORITY_SET(irq_number, priority)
static inline void _NRFX_IRQ_PRIORITY_SET(IRQn_Type irq_number,
@@ -158,14 +160,10 @@ static inline bool _NRFX_IRQ_IS_PENDING(IRQn_Type irq_number)
return (NVIC_GetPendingIRQ(irq_number) == 1);
}
/**
* @brief Macro for entering into a critical section.
*/
/** @brief Macro for entering into a critical section. */
#define NRFX_CRITICAL_SECTION_ENTER()
/**
* @brief Macro for exiting from a critical section.
*/
/** @brief Macro for exiting from a critical section. */
#define NRFX_CRITICAL_SECTION_EXIT()
//------------------------------------------------------------------------------