clang work with lpc55

This commit is contained in:
hathach
2024-04-23 10:57:45 +07:00
parent d486a56ded
commit 3fd82cfe22
5 changed files with 83 additions and 81 deletions

View File

@@ -50,8 +50,7 @@ static uint32_t blink_interval_ms = BLINK_NOT_MOUNTED;
void led_blinking_task(void); void led_blinking_task(void);
/*------------- MAIN -------------*/ /*------------- MAIN -------------*/
int main(void) int main(void) {
{
board_init(); board_init();
// init device stack on configured roothub port // init device stack on configured roothub port
@@ -61,8 +60,7 @@ int main(void)
board_init_after_tusb(); board_init_after_tusb();
} }
while (1) while (1) {
{
tud_task(); // tinyusb device task tud_task(); // tinyusb device task
led_blinking_task(); led_blinking_task();
} }
@@ -73,37 +71,32 @@ int main(void)
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// Invoked when device is mounted // Invoked when device is mounted
void tud_mount_cb(void) void tud_mount_cb(void) {
{
blink_interval_ms = BLINK_MOUNTED; blink_interval_ms = BLINK_MOUNTED;
} }
// Invoked when device is unmounted // Invoked when device is unmounted
void tud_umount_cb(void) void tud_umount_cb(void) {
{
blink_interval_ms = BLINK_NOT_MOUNTED; blink_interval_ms = BLINK_NOT_MOUNTED;
} }
// Invoked when usb bus is suspended // Invoked when usb bus is suspended
// remote_wakeup_en : if host allow us to perform remote wakeup // remote_wakeup_en : if host allow us to perform remote wakeup
// Within 7ms, device must draw an average of current less than 2.5 mA from bus // Within 7ms, device must draw an average of current less than 2.5 mA from bus
void tud_suspend_cb(bool remote_wakeup_en) void tud_suspend_cb(bool remote_wakeup_en) {
{
(void) remote_wakeup_en; (void) remote_wakeup_en;
blink_interval_ms = BLINK_SUSPENDED; blink_interval_ms = BLINK_SUSPENDED;
} }
// Invoked when usb bus is resumed // Invoked when usb bus is resumed
void tud_resume_cb(void) void tud_resume_cb(void) {
{
blink_interval_ms = tud_mounted() ? BLINK_MOUNTED : BLINK_NOT_MOUNTED; blink_interval_ms = tud_mounted() ? BLINK_MOUNTED : BLINK_NOT_MOUNTED;
} }
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// BLINKING TASK // BLINKING TASK
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
void led_blinking_task(void) void led_blinking_task(void) {
{
static uint32_t start_ms = 0; static uint32_t start_ms = 0;
static bool led_state = false; static bool led_state = false;

View File

@@ -72,13 +72,11 @@
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler // Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
void USB0_IRQHandler(void) void USB0_IRQHandler(void) {
{
tud_int_handler(0); tud_int_handler(0);
} }
void USB1_IRQHandler(void) void USB1_IRQHandler(void) {
{
tud_int_handler(1); tud_int_handler(1);
} }
@@ -92,8 +90,7 @@ settings:
sources: sources:
- {id: SYSCON.fro_hf.outFreq, value: 96 MHz} - {id: SYSCON.fro_hf.outFreq, value: 96 MHz}
******************************************************************/ ******************************************************************/
void BootClockFROHF96M(void) void BootClockFROHF96M(void) {
{
/*!< Set up the clock sources */ /*!< Set up the clock sources */
/*!< Set up FRO */ /*!< Set up FRO */
POWER_DisablePD(kPDRUNCFG_PD_FRO192M); /*!< Ensure FRO is on */ POWER_DisablePD(kPDRUNCFG_PD_FRO192M); /*!< Ensure FRO is on */
@@ -116,8 +113,7 @@ void BootClockFROHF96M(void)
SystemCoreClock = 96000000U; SystemCoreClock = 96000000U;
} }
void board_init(void) void board_init(void) {
{
// Enable IOCON clock // Enable IOCON clock
CLOCK_EnableClock(kCLOCK_Iocon); CLOCK_EnableClock(kCLOCK_Iocon);
@@ -250,8 +246,7 @@ void board_init(void)
// Board porting API // Board porting API
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
void board_led_write(bool state) void board_led_write(bool state) {
{
GPIO_PinWrite(GPIO, LED_PORT, LED_PIN, state ? LED_STATE_ON : (1 - LED_STATE_ON)); GPIO_PinWrite(GPIO, LED_PORT, LED_PIN, state ? LED_STATE_ON : (1 - LED_STATE_ON));
#ifdef NEOPIXEL_PIN #ifdef NEOPIXEL_PIN
@@ -266,33 +261,50 @@ void board_led_write(bool state)
#endif #endif
} }
uint32_t board_button_read(void) uint32_t board_button_read(void) {
{
// active low // active low
return BUTTON_STATE_ACTIVE == GPIO_PinRead(GPIO, BUTTON_PORT, BUTTON_PIN); return BUTTON_STATE_ACTIVE == GPIO_PinRead(GPIO, BUTTON_PORT, BUTTON_PIN);
} }
int board_uart_read(uint8_t* buf, int len) int board_uart_read(uint8_t* buf, int len) {
{ (void) buf;
(void) buf; (void) len; (void) len;
return 0; return 0;
} }
int board_uart_write(void const * buf, int len) int board_uart_write(void const* buf, int len) {
{
USART_WriteBlocking(UART_DEV, (uint8_t const*) buf, len); USART_WriteBlocking(UART_DEV, (uint8_t const*) buf, len);
return len; return len;
} }
#if CFG_TUSB_OS == OPT_OS_NONE #if CFG_TUSB_OS == OPT_OS_NONE
volatile uint32_t system_ticks = 0; volatile uint32_t system_ticks = 0;
void SysTick_Handler(void)
{ void SysTick_Handler(void) {
system_ticks++; system_ticks++;
} }
uint32_t board_millis(void) uint32_t board_millis(void) {
{
return system_ticks; return system_ticks;
} }
#endif #endif
#ifndef __ICCARM__
// 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) {}
}
#ifdef __clang__
void _exit (int __status) {
while (1) {}
}
#endif
#endif

View File

@@ -1,9 +1,5 @@
include_guard() include_guard()
if (NOT BOARD)
message(FATAL_ERROR "BOARD not specified")
endif ()
set(SDK_DIR ${TOP}/hw/mcu/nxp/mcux-sdk) set(SDK_DIR ${TOP}/hw/mcu/nxp/mcux-sdk)
set(CMSIS_DIR ${TOP}/lib/CMSIS_5) set(CMSIS_DIR ${TOP}/lib/CMSIS_5)
@@ -32,7 +28,18 @@ function(add_board_target BOARD_TARGET)
return() return()
endif() endif()
if (NOT DEFINED LD_FILE_GNU)
set(LD_FILE_GNU ${SDK_DIR}/devices/${MCU_VARIANT}/gcc/${MCU_CORE}_flash.ld)
endif ()
set(LD_FILE_Clang ${LD_FILE_GNU})
if (NOT DEFINED STARTUP_FILE_GNU)
set(STARTUP_FILE_GNU ${SDK_DIR}/devices/${MCU_VARIANT}/gcc/startup_${MCU_CORE}.S)
endif ()
set(STARTUP_FILE_Clang ${STARTUP_FILE_GNU})
add_library(${BOARD_TARGET} STATIC add_library(${BOARD_TARGET} STATIC
${STARTUP_FILE_${CMAKE_C_COMPILER_ID}}
# driver # driver
${SDK_DIR}/drivers/lpc_gpio/fsl_gpio.c ${SDK_DIR}/drivers/lpc_gpio/fsl_gpio.c
${SDK_DIR}/drivers/common/fsl_common_arm.c ${SDK_DIR}/drivers/common/fsl_common_arm.c
@@ -44,12 +51,27 @@ function(add_board_target BOARD_TARGET)
${SDK_DIR}/devices/${MCU_VARIANT}/drivers/fsl_power.c ${SDK_DIR}/devices/${MCU_VARIANT}/drivers/fsl_power.c
${SDK_DIR}/devices/${MCU_VARIANT}/drivers/fsl_reset.c ${SDK_DIR}/devices/${MCU_VARIANT}/drivers/fsl_reset.c
) )
target_include_directories(${BOARD_TARGET} PUBLIC
${TOP}/lib/sct_neopixel
# driver
${SDK_DIR}/drivers/common
${SDK_DIR}/drivers/flexcomm
${SDK_DIR}/drivers/lpc_iocon
${SDK_DIR}/drivers/lpc_gpio
${SDK_DIR}/drivers/lpuart
${SDK_DIR}/drivers/sctimer
# mcu
${SDK_DIR}/devices/${MCU_VARIANT}
${SDK_DIR}/devices/${MCU_VARIANT}/drivers
${CMSIS_DIR}/CMSIS/Core/Include
)
target_compile_definitions(${BOARD_TARGET} PUBLIC target_compile_definitions(${BOARD_TARGET} PUBLIC
CFG_TUSB_MEM_ALIGN=TU_ATTR_ALIGNED\(64\) CFG_TUSB_MEM_ALIGN=TU_ATTR_ALIGNED\(64\)
BOARD_TUD_RHPORT=${PORT} BOARD_TUD_RHPORT=${PORT}
BOARD_TUH_RHPORT=${HOST_PORT} BOARD_TUH_RHPORT=${HOST_PORT}
__STARTUP_CLEAR_BSS
) )
# Port 0 is Fullspeed, Port 1 is Highspeed. Port1 controller can only access USB_SRAM # Port 0 is Fullspeed, Port 1 is Highspeed. Port1 controller can only access USB_SRAM
if (PORT EQUAL 1) if (PORT EQUAL 1)
target_compile_definitions(${BOARD_TARGET} PUBLIC target_compile_definitions(${BOARD_TARGET} PUBLIC
@@ -65,42 +87,17 @@ function(add_board_target BOARD_TARGET)
) )
endif () endif ()
target_include_directories(${BOARD_TARGET} PUBLIC
${TOP}/lib/sct_neopixel
# driver
${SDK_DIR}/drivers/common
${SDK_DIR}/drivers/flexcomm
${SDK_DIR}/drivers/lpc_iocon
${SDK_DIR}/drivers/lpc_gpio
${SDK_DIR}/drivers/lpuart
${SDK_DIR}/drivers/sctimer
# mcu
${CMSIS_DIR}/CMSIS/Core/Include
${SDK_DIR}/devices/${MCU_VARIANT}
${SDK_DIR}/devices/${MCU_VARIANT}/drivers
)
update_board(${BOARD_TARGET}) update_board(${BOARD_TARGET})
if (NOT DEFINED LD_FILE_${CMAKE_C_COMPILER_ID})
set(LD_FILE_GNU ${SDK_DIR}/devices/${MCU_VARIANT}/gcc/${MCU_CORE}_flash.ld)
endif ()
if (NOT DEFINED STARTUP_FILE_${CMAKE_C_COMPILER_ID})
set(STARTUP_FILE_GNU ${SDK_DIR}/devices/${MCU_VARIANT}/gcc/startup_${MCU_CORE}.S)
endif ()
target_sources(${BOARD_TARGET} PUBLIC
${STARTUP_FILE_${CMAKE_C_COMPILER_ID}}
)
if (CMAKE_C_COMPILER_ID STREQUAL "GNU") if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
target_link_options(${BOARD_TARGET} PUBLIC target_link_options(${BOARD_TARGET} PUBLIC
# linker file
"LINKER:--script=${LD_FILE_GNU}" "LINKER:--script=${LD_FILE_GNU}"
# nanolib --specs=nosys.specs --specs=nano.specs
--specs=nosys.specs -nostartfiles
--specs=nano.specs )
elseif (CMAKE_C_COMPILER_ID STREQUAL "Clang")
target_link_options(${BOARD_TARGET} PUBLIC
"LINKER:--script=${LD_FILE_Clang}"
) )
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

View File

@@ -239,7 +239,7 @@ TU_ATTR_ALWAYS_INLINE static inline bool ep_is_iso(ep_cmd_sts_t* ep_cs, bool is_
return is_highspeed ? (ep_cs[0].cmd_sts.type && !ep_cs[0].cmd_sts.rf_tv) : ep_cs->cmd_sts.type; return is_highspeed ? (ep_cs[0].cmd_sts.type && !ep_cs[0].cmd_sts.rf_tv) : ep_cs->cmd_sts.type;
} }
TU_ATTR_ALWAYS_INLINE static inline bool ep_is_bulk(ep_cmd_sts_t* ep_cs) { TU_ATTR_ALWAYS_INLINE TU_ATTR_UNUSED static inline bool ep_is_bulk(ep_cmd_sts_t* ep_cs) {
return (ep_cs[0].cmd_sts.type == 0) && (ep_cs[0].cmd_sts.rf_tv == 0); return (ep_cs[0].cmd_sts.type == 0) && (ep_cs[0].cmd_sts.rf_tv == 0);
} }