diff --git a/.gitmodules b/.gitmodules index f6793a6d4..9c70debf8 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,9 +7,9 @@ [submodule "hw/mcu/st/stm32lib"] path = hw/mcu/st/stm32lib url = https://github.com/hathach/stm32lib.git -[submodule "hw/mcu/nxp/lpcopen"] - path = hw/mcu/nxp/lpcopen - url = https://github.com/hathach/lpcopen.git [submodule "tools/uf2"] path = tools/uf2 url = https://github.com/microsoft/uf2.git +[submodule "hw/mcu/nxp/lpc_driver"] + path = hw/mcu/nxp/lpc_driver + url = https://github.com/hathach/lpc_driver.git diff --git a/README.md b/README.md index 62c9fafcf..a7a401e7a 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ Currently the following OS are supported with tinyusb out of the box with a simp The stack supports the following MCUs - **Nordic:** nRF52840 -- **NXP:** LPC11Uxx, LPC13xx, LPC175x_6x, LPC177x_8x, LPC18xx, LPC40xx, LPC43xx +- **NXP:** LPC11Uxx, LPC13xx, LPC175x_6x, LPC177x_8x, LPC18xx, LPC40xx, LPC43xx, LPC51Uxx - **MicroChip:** SAMD21, SAMD51 (device only) - **ST:** STM32F4 (device only) diff --git a/docs/boards.md b/docs/boards.md index b1c585188..84319aaf3 100644 --- a/docs/boards.md +++ b/docs/boards.md @@ -19,6 +19,7 @@ This code base already had supported for a handful of following boards - [LPCXpresso 11U68](https://www.nxp.com/support/developer-resources/evaluation-and-development-boards/lpcxpresso-boards/lpcxpresso-board-for-lpc11u68:OM13058) - [LPCXpresso 1347](https://www.nxp.com/support/developer-resources/evaluation-and-development-boards/lpcxpresso-boards/lpcxpresso-board-for-lpc1347:OM13045) - [LPCXpresso 1769](https://www.nxp.com/support/developer-resources/evaluation-and-development-boards/lpcxpresso-boards/lpcxpresso-board-for-lpc1769:OM13000) +- [LPCXpresso 51U68](https://www.nxp.com/products/processors-and-microcontrollers/arm-microcontrollers/general-purpose-mcus/lpcxpresso51u68-for-the-lpc51u68-mcus:OM40005) - [Keil MCB1800 Evaluation Board](http://www.keil.com/mcb1800) - [Embedded Artists LPC4088 Quick Start board](https://www.embeddedartists.com/products/lpc4088-quickstart-board) - [Embedded Artists LPC4357 Developer Kit](http://www.embeddedartists.com/products/kits/lpc4357_kit.php) diff --git a/examples/device/board_test/Makefile b/examples/device/board_test/Makefile new file mode 100644 index 000000000..5a455078e --- /dev/null +++ b/examples/device/board_test/Makefile @@ -0,0 +1,12 @@ +include ../../../tools/top.mk +include ../../make.mk + +INC += \ + src \ + $(TOP)/hw \ + +# Example source +EXAMPLE_SOURCE += $(wildcard src/*.c) +SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE)) + +include ../../rules.mk diff --git a/examples/device/board_test/src/main.c b/examples/device/board_test/src/main.c new file mode 100644 index 000000000..0126110ed --- /dev/null +++ b/examples/device/board_test/src/main.c @@ -0,0 +1,67 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2019 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. + * + */ + +#include +#include +#include + +#include "bsp/board.h" + +//--------------------------------------------------------------------+ +// MACRO CONSTANT TYPEDEF PROTYPES +//--------------------------------------------------------------------+ + +/* Blink pattern + * - 250 ms : button is not pressed + * - 1000 ms : button is pressed (and hold) + */ +enum { + BLINK_PRESSED = 250, + BLINK_UNPRESSED = 1000 +}; + +int main(void) +{ + board_init(); + + uint32_t start_ms = 0; + bool led_state = false; + + while (1) + { + uint32_t interval_ms = board_button_read() ? BLINK_PRESSED : BLINK_UNPRESSED; + + // Blink every interval ms + if ( !(board_millis() - start_ms < interval_ms) ) + { + start_ms = board_millis(); + + board_led_write(led_state); + led_state = 1 - led_state; // toggle + } + } + + return 0; +} diff --git a/examples/device/board_test/src/tusb_config.h b/examples/device/board_test/src/tusb_config.h new file mode 100644 index 000000000..5c3cac83a --- /dev/null +++ b/examples/device/board_test/src/tusb_config.h @@ -0,0 +1,83 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2019 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. + * + */ + +#ifndef _TUSB_CONFIG_H_ +#define _TUSB_CONFIG_H_ + +#ifdef __cplusplus + extern "C" { +#endif + +//-------------------------------------------------------------------- +// COMMON CONFIGURATION +//-------------------------------------------------------------------- + +// defined by compiler flags for flexibility +#ifndef CFG_TUSB_MCU + #error CFG_TUSB_MCU must be defined +#endif + +#define CFG_TUSB_RHPORT0_MODE OPT_MODE_NONE +#define CFG_TUSB_OS OPT_OS_NONE + +// CFG_TUSB_DEBUG is defined by compiler in DEBUG build +// #define CFG_TUSB_DEBUG 0 + +/* USB DMA on some MCUs can only access a specific SRAM region with restriction on alignment. + * Tinyusb use follows macros to declare transferring memory so that they can be put + * into those specific section. + * e.g + * - CFG_TUSB_MEM SECTION : __attribute__ (( section(".usb_ram") )) + * - CFG_TUSB_MEM_ALIGN : __attribute__ ((aligned(4))) + */ +#ifndef CFG_TUSB_MEM_SECTION +#define CFG_TUSB_MEM_SECTION +#endif + +#ifndef CFG_TUSB_MEM_ALIGN +#define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(4))) +#endif + +//-------------------------------------------------------------------- +// DEVICE CONFIGURATION +//-------------------------------------------------------------------- + +#define CFG_TUD_ENDOINT0_SIZE 64 + +//------------- CLASS -------------// +#define CFG_TUD_CDC 0 +#define CFG_TUD_MSC 1 +#define CFG_TUD_HID 0 +#define CFG_TUD_MIDI 0 +#define CFG_TUD_VENDOR 0 + +// MSC Buffer size of Device Mass storage +#define CFG_TUD_MSC_BUFSIZE 512 + +#ifdef __cplusplus + } +#endif + +#endif /* _TUSB_CONFIG_H_ */ diff --git a/examples/device/cdc_msc_hid/ses/lpc11u6x/lpc11u6x.emProject b/examples/device/cdc_msc_hid/ses/lpc11u6x/lpc11u6x.emProject index fce8041e7..ea47e0db6 100644 --- a/examples/device/cdc_msc_hid/ses/lpc11u6x/lpc11u6x.emProject +++ b/examples/device/cdc_msc_hid/ses/lpc11u6x/lpc11u6x.emProject @@ -20,7 +20,7 @@ arm_target_interface_type="SWD" build_treat_warnings_as_errors="Yes" c_preprocessor_definitions="__LPC11U68__;__LPC1100_FAMILY;__LPC11U00_SUBFAMILY;ARM_MATH_CM0PLUS;FLASH_PLACEMENT=1;CORE_M0PLUS;CFG_TUSB_MCU=OPT_MCU_LPC11UXX;CFG_TUSB_MEM_SECTION= __attribute__((section(".bss3")));CFG_TUSB_MEM_ALIGN=__attribute__ ((aligned(64)))" - c_user_include_directories="../../src;$(rootDir)/hw;$(rootDir)/hw/mcu/nxp/lpcopen/lpc_chip_11u6x/inc;$(rootDir)/src" + c_user_include_directories="../../src;$(rootDir)/hw;$(rootDir)/hw/mcu/nxp/lpc_driver/lpc_chip_11u6x/inc;$(rootDir)/src" debug_register_definition_file="$(ProjectDir)/LPC11U6x_Registers.xml" debug_target_connection="J-Link" gcc_enable_all_warnings="Yes" @@ -63,35 +63,37 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/device/cdc_msc_hid/ses/lpc13xx/lpc13xx.emProject b/examples/device/cdc_msc_hid/ses/lpc13xx/lpc13xx.emProject index 791944a16..d07cc68ff 100644 --- a/examples/device/cdc_msc_hid/ses/lpc13xx/lpc13xx.emProject +++ b/examples/device/cdc_msc_hid/ses/lpc13xx/lpc13xx.emProject @@ -19,7 +19,7 @@ arm_target_interface_type="SWD" build_treat_warnings_as_errors="Yes" c_preprocessor_definitions="__LPC1347FBD64__;__LPC1300_FAMILY;__LPC134x_SUBFAMILY;ARM_MATH_CM3;FLASH_PLACEMENT=1;CORE_M3;CFG_TUSB_MCU=OPT_MCU_LPC13XX;CFG_TUSB_MEM_SECTION= __attribute__((section(".bss3")));CFG_TUSB_MEM_ALIGN=__attribute__ ((aligned(64)))" - c_user_include_directories="../../src;$(rootDir)/hw;$(rootDir)/hw/mcu/nxp/lpcopen/lpc_chip_13xx/inc;$(rootDir)/src" + c_user_include_directories="../../src;$(rootDir)/hw;$(rootDir)/hw/mcu/nxp/lpc_driver/lpc_chip_13xx/inc;$(rootDir)/src" debug_register_definition_file="$(ProjectDir)/LPC13Uxx_Registers.xml" debug_target_connection="J-Link" gcc_enable_all_warnings="Yes" @@ -53,35 +53,37 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/device/cdc_msc_hid/ses/lpc175x_6x/lpc175x_6x.emProject b/examples/device/cdc_msc_hid/ses/lpc175x_6x/lpc175x_6x.emProject index d0b065370..7d49a90d7 100644 --- a/examples/device/cdc_msc_hid/ses/lpc175x_6x/lpc175x_6x.emProject +++ b/examples/device/cdc_msc_hid/ses/lpc175x_6x/lpc175x_6x.emProject @@ -20,7 +20,7 @@ arm_target_interface_type="SWD" build_treat_warnings_as_errors="Yes" c_preprocessor_definitions="LPC175x_6x;__LPC1700_FAMILY;__LPC176x_SUBFAMILY;ARM_MATH_CM3;FLASH_PLACEMENT=1;CORE_M3;CFG_TUSB_MCU=OPT_MCU_LPC175X_6X" - c_user_include_directories="../../src;$(rootDir)/hw;$(rootDir)/hw/mcu/nxp/lpcopen/lpc_chip_175x_6x/inc;$(rootDir)/src" + c_user_include_directories="../../src;$(rootDir)/hw;$(rootDir)/hw/mcu/nxp/lpc_driver/lpc_chip_175x_6x/inc;$(rootDir)/src" debug_register_definition_file="LPC176x5x_Registers.xml" debug_target_connection="J-Link" gcc_enable_all_warnings="Yes" @@ -46,40 +46,40 @@ - + - + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - - - - - - - + + + + + + + diff --git a/examples/device/cdc_msc_hid/ses/lpc18xx/lpc18xx.emProject b/examples/device/cdc_msc_hid/ses/lpc18xx/lpc18xx.emProject index e7ce7a02a..8f7d91b2a 100644 --- a/examples/device/cdc_msc_hid/ses/lpc18xx/lpc18xx.emProject +++ b/examples/device/cdc_msc_hid/ses/lpc18xx/lpc18xx.emProject @@ -19,7 +19,7 @@ arm_target_interface_type="SWD" build_treat_warnings_as_errors="Yes" c_preprocessor_definitions="LPC18xx;__LPC1800_FAMILY;__LPC185x_SUBFAMILY;ARM_MATH_CM3;FLASH_PLACEMENT=1;CORE_M3;CFG_TUSB_MCU=OPT_MCU_LPC18XX;CFG_TUSB_MEM_SECTION= __attribute__((section(".bss2")))" - c_user_include_directories="../../src;$(rootDir)/hw;$(rootDir)/hw/mcu/nxp/lpcopen/lpc_chip_18xx/inc;$(rootDir)/hw/mcu/nxp/lpcopen/lpc_chip_18xx/inc/config_18xx;$(rootDir)/src" + c_user_include_directories="../../src;$(rootDir)/hw;$(rootDir)/hw/mcu/nxp/lpc_driver/lpc_chip_18xx/inc;$(rootDir)/hw/mcu/nxp/lpc_driver/lpc_chip_18xx/inc/config_18xx;$(rootDir)/src" debug_register_definition_file="$(ProjectDir)/LPC18xx_Registers.xml" debug_target_connection="J-Link" gcc_enable_all_warnings="Yes" @@ -53,51 +53,53 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - diff --git a/examples/device/cdc_msc_hid/ses/lpc40xx/lpc40xx.emProject b/examples/device/cdc_msc_hid/ses/lpc40xx/lpc40xx.emProject index 5a1cbe52b..4a61181ca 100644 --- a/examples/device/cdc_msc_hid/ses/lpc40xx/lpc40xx.emProject +++ b/examples/device/cdc_msc_hid/ses/lpc40xx/lpc40xx.emProject @@ -20,7 +20,7 @@ arm_target_interface_type="SWD" build_treat_warnings_as_errors="Yes" c_preprocessor_definitions="CORE_M4;__LPC4000_FAMILY;__LPC408x_SUBFAMILY;ARM_MATH_CM4;FLASH_PLACEMENT=1;CFG_TUSB_MCU=OPT_MCU_LPC40XX;CFG_TUSB_MEM_SECTION= __attribute__((section(".bss2")))" - c_user_include_directories="../../src;$(rootDir)/hw;$(rootDir)/hw/mcu/nxp/lpcopen/lpc_chip_40xx/inc;$(rootDir)/src" + c_user_include_directories="../../src;$(rootDir)/hw;$(rootDir)/hw/mcu/nxp/lpc_driver/lpc_chip_40xx/inc;$(rootDir)/src" debug_register_definition_file="$(ProjectDir)/LPC408x_7x_Registers.xml" debug_target_connection="J-Link" gcc_enable_all_warnings="Yes" @@ -55,39 +55,41 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/device/cdc_msc_hid/ses/lpc43xx/lpc43xx.emProject b/examples/device/cdc_msc_hid/ses/lpc43xx/lpc43xx.emProject index 26444c469..f751a4323 100644 --- a/examples/device/cdc_msc_hid/ses/lpc43xx/lpc43xx.emProject +++ b/examples/device/cdc_msc_hid/ses/lpc43xx/lpc43xx.emProject @@ -20,7 +20,7 @@ arm_target_interface_type="SWD" build_treat_warnings_as_errors="Yes" c_preprocessor_definitions="CORE_M4;__LPC4300_FAMILY;__LPC435x_SUBFAMILY;ARM_MATH_CM4;FLASH_PLACEMENT=1;CFG_TUSB_MCU=OPT_MCU_LPC43XX;CFG_TUSB_MEM_SECTION= __attribute__((section(".bss2")))" - c_user_include_directories="../../src;$(rootDir)/hw;$(rootDir)/hw/mcu/nxp/lpcopen/lpc_chip_43xx/inc;$(rootDir)/hw/mcu/nxp/lpcopen/lpc_chip_43xx/inc/config_43xx;$(rootDir)/src;$(lpcDir)//inc" + c_user_include_directories="../../src;$(rootDir)/hw;$(rootDir)/hw/mcu/nxp/lpc_driver/lpc_chip_43xx/inc;$(rootDir)/hw/mcu/nxp/lpc_driver/lpc_chip_43xx/inc/config_43xx;$(rootDir)/src;$(lpcDir)//inc" debug_register_definition_file="LPC43xx_Registers.xml" debug_target_connection="J-Link" gcc_enable_all_warnings="Yes" @@ -46,61 +46,63 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - diff --git a/examples/device/cdc_msc_hid/ses/nrf5x/nrf5x.emProject b/examples/device/cdc_msc_hid/ses/nrf5x/nrf5x.emProject index b3f23fbf4..55c5a4ec4 100644 --- a/examples/device/cdc_msc_hid/ses/nrf5x/nrf5x.emProject +++ b/examples/device/cdc_msc_hid/ses/nrf5x/nrf5x.emProject @@ -20,7 +20,7 @@ arm_target_interface_type="SWD" build_treat_warnings_as_errors="Yes" c_preprocessor_definitions="NRF52840_XXAA;__nRF_FAMILY;ARM_MATH_CM4;FLASH_PLACEMENT=1;CFG_TUSB_MCU=OPT_MCU_NRF5X" - c_user_include_directories="../../src;$(rootDir)/hw/cmsis/Include;$(rootDir)/hw;$(rootDir)/src;$(nrfxDir)/..;$(nrfxDir);$(nrfxDir)/mdk;$(nrfxDir)/hal;$(nrfxDir)/drivers/include;$(nrfxDir)/drivers/src" + c_user_include_directories="../../src;$(rootDir)/hw/mcu/nordic/cmsis/Include;$(rootDir)/hw;$(rootDir)/src;$(nrfxDir)/..;$(nrfxDir);$(nrfxDir)/mdk;$(nrfxDir)/hal;$(nrfxDir)/drivers/include;$(nrfxDir)/drivers/src" debug_register_definition_file="nrf52840_Registers.xml" debug_target_connection="J-Link" gcc_enable_all_warnings="Yes" @@ -43,7 +43,7 @@ - + diff --git a/examples/device/cdc_msc_hid/ses/samd21/samd21.emProject b/examples/device/cdc_msc_hid/ses/samd21/samd21.emProject index 30aad55ca..1536af9ab 100644 --- a/examples/device/cdc_msc_hid/ses/samd21/samd21.emProject +++ b/examples/device/cdc_msc_hid/ses/samd21/samd21.emProject @@ -45,7 +45,7 @@ - + diff --git a/examples/device/cdc_msc_hid/ses/samd51/samd51.emProject b/examples/device/cdc_msc_hid/ses/samd51/samd51.emProject index cc34dc63d..ecb1e031b 100644 --- a/examples/device/cdc_msc_hid/ses/samd51/samd51.emProject +++ b/examples/device/cdc_msc_hid/ses/samd51/samd51.emProject @@ -46,7 +46,7 @@ - + diff --git a/examples/device/cdc_msc_hid/ses/stm32f4/stm32f4.emProject b/examples/device/cdc_msc_hid/ses/stm32f4/stm32f4.emProject index 6f6690d21..23b313471 100644 --- a/examples/device/cdc_msc_hid/ses/stm32f4/stm32f4.emProject +++ b/examples/device/cdc_msc_hid/ses/stm32f4/stm32f4.emProject @@ -62,7 +62,7 @@ - + diff --git a/examples/device/cdc_msc_hid_freertos/ses/lpc175x_6x/lpc175x_6x.emProject b/examples/device/cdc_msc_hid_freertos/ses/lpc175x_6x/lpc175x_6x.emProject index 5493af626..4dc111f2e 100644 --- a/examples/device/cdc_msc_hid_freertos/ses/lpc175x_6x/lpc175x_6x.emProject +++ b/examples/device/cdc_msc_hid_freertos/ses/lpc175x_6x/lpc175x_6x.emProject @@ -20,7 +20,7 @@ arm_target_interface_type="SWD" build_treat_warnings_as_errors="No" c_preprocessor_definitions="LPC175x_6x;__LPC1700_FAMILY;__LPC176x_SUBFAMILY;ARM_MATH_CM3;FLASH_PLACEMENT=1;CORE_M3;CFG_TUSB_MCU=OPT_MCU_LPC175X_6X" - c_user_include_directories=".;../../src;$(rootDir)/hw;$(rootDir)/src;$(rootDir)/hw/mcu/nxp/lpcopen/lpc_chip_175x_6x/inc;$(rootDir)/lib/FreeRTOS/Source/include;$(rootDir)/lib/FreeRTOS/Source/portable/GCC/ARM_CM3" + c_user_include_directories=".;../../src;$(rootDir)/hw;$(rootDir)/src;$(rootDir)/hw/mcu/nxp/lpc_driver/lpc_chip_175x_6x/inc;$(rootDir)/lib/FreeRTOS/Source/include;$(rootDir)/lib/FreeRTOS/Source/portable/GCC/ARM_CM3" debug_register_definition_file="LPC176x5x_Registers.xml" debug_target_connection="J-Link" gcc_enable_all_warnings="Yes" @@ -50,16 +50,16 @@ - + - - - - - - - + + + + + + + diff --git a/examples/rules.mk b/examples/rules.mk index 4fbce2529..18410d2d9 100644 --- a/examples/rules.mk +++ b/examples/rules.mk @@ -3,7 +3,7 @@ # # libc -LIBS = -lgcc -lc -lm -lnosys +LIBS += -lgcc -lc -lm -lnosys # TinyUSB Stack source SRC_C += \ diff --git a/hw/bsp/board.h b/hw/bsp/board.h index 9c8ec87bc..b5abfe22c 100644 --- a/hw/bsp/board.h +++ b/hw/bsp/board.h @@ -100,8 +100,10 @@ static inline void board_delay(uint32_t ms) uint32_t start_ms = board_millis(); while (board_millis() - start_ms < ms) { + #if TUSB_OPT_DEVICE_ENABLED // take chance to run usb background tud_task(); + #endif } } diff --git a/hw/bsp/ea4088qs/board.mk b/hw/bsp/ea4088qs/board.mk index 136984e3c..3b723c2e5 100644 --- a/hw/bsp/ea4088qs/board.mk +++ b/hw/bsp/ea4088qs/board.mk @@ -15,16 +15,16 @@ LD_FILE = hw/bsp/ea4088qs/lpc4088.ld SRC_C += src/portable/$(VENDOR)/$(CHIP_FAMILY)/hal_$(CHIP_FAMILY).c SRC_C += \ - hw/mcu/nxp/lpcopen/lpc_chip_40xx/src/chip_17xx_40xx.c \ - hw/mcu/nxp/lpcopen/lpc_chip_40xx/src/clock_17xx_40xx.c \ - hw/mcu/nxp/lpcopen/lpc_chip_40xx/src/gpio_17xx_40xx.c \ - hw/mcu/nxp/lpcopen/lpc_chip_40xx/src/iocon_17xx_40xx.c \ - hw/mcu/nxp/lpcopen/lpc_chip_40xx/src/sysctl_17xx_40xx.c \ - hw/mcu/nxp/lpcopen/lpc_chip_40xx/src/sysinit_17xx_40xx.c \ - hw/mcu/nxp/lpcopen/lpc_chip_40xx/src/uart_17xx_40xx.c + hw/mcu/nxp/lpc_driver/lpc_chip_40xx/src/chip_17xx_40xx.c \ + hw/mcu/nxp/lpc_driver/lpc_chip_40xx/src/clock_17xx_40xx.c \ + hw/mcu/nxp/lpc_driver/lpc_chip_40xx/src/gpio_17xx_40xx.c \ + hw/mcu/nxp/lpc_driver/lpc_chip_40xx/src/iocon_17xx_40xx.c \ + hw/mcu/nxp/lpc_driver/lpc_chip_40xx/src/sysctl_17xx_40xx.c \ + hw/mcu/nxp/lpc_driver/lpc_chip_40xx/src/sysinit_17xx_40xx.c \ + hw/mcu/nxp/lpc_driver/lpc_chip_40xx/src/uart_17xx_40xx.c INC += \ - $(TOP)/hw/mcu/nxp/lpcopen/lpc_chip_40xx/inc + $(TOP)/hw/mcu/nxp/lpc_driver/lpc_chip_40xx/inc # For TinyUSB port source VENDOR = nxp diff --git a/hw/bsp/ea4088qs/board_ea4088qs.c b/hw/bsp/ea4088qs/ea4088qs.c similarity index 100% rename from hw/bsp/ea4088qs/board_ea4088qs.c rename to hw/bsp/ea4088qs/ea4088qs.c diff --git a/hw/bsp/ea4357/board.mk b/hw/bsp/ea4357/board.mk index a44d20f9a..a87f0d617 100644 --- a/hw/bsp/ea4357/board.mk +++ b/hw/bsp/ea4357/board.mk @@ -14,17 +14,17 @@ LD_FILE = hw/bsp/ea4357/lpc4357.ld SRC_C += src/portable/$(VENDOR)/$(CHIP_FAMILY)/hal_$(CHIP_FAMILY).c SRC_C += \ - hw/mcu/nxp/lpcopen/lpc_chip_43xx/src/chip_18xx_43xx.c \ - hw/mcu/nxp/lpcopen/lpc_chip_43xx/src/clock_18xx_43xx.c \ - hw/mcu/nxp/lpcopen/lpc_chip_43xx/src/gpio_18xx_43xx.c \ - hw/mcu/nxp/lpcopen/lpc_chip_43xx/src/sysinit_18xx_43xx.c \ - hw/mcu/nxp/lpcopen/lpc_chip_43xx/src/i2c_18xx_43xx.c \ - hw/mcu/nxp/lpcopen/lpc_chip_43xx/src/i2cm_18xx_43xx.c \ - hw/mcu/nxp/lpcopen/lpc_chip_43xx/src/uart_18xx_43xx.c + hw/mcu/nxp/lpc_driver/lpc_chip_43xx/src/chip_18xx_43xx.c \ + hw/mcu/nxp/lpc_driver/lpc_chip_43xx/src/clock_18xx_43xx.c \ + hw/mcu/nxp/lpc_driver/lpc_chip_43xx/src/gpio_18xx_43xx.c \ + hw/mcu/nxp/lpc_driver/lpc_chip_43xx/src/sysinit_18xx_43xx.c \ + hw/mcu/nxp/lpc_driver/lpc_chip_43xx/src/i2c_18xx_43xx.c \ + hw/mcu/nxp/lpc_driver/lpc_chip_43xx/src/i2cm_18xx_43xx.c \ + hw/mcu/nxp/lpc_driver/lpc_chip_43xx/src/uart_18xx_43xx.c INC += \ - $(TOP)/hw/mcu/nxp/lpcopen/lpc_chip_43xx/inc \ - $(TOP)/hw/mcu/nxp/lpcopen/lpc_chip_43xx/inc/config_43xx + $(TOP)/hw/mcu/nxp/lpc_driver/lpc_chip_43xx/inc \ + $(TOP)/hw/mcu/nxp/lpc_driver/lpc_chip_43xx/inc/config_43xx # For TinyUSB port source VENDOR = nxp diff --git a/hw/bsp/ea4357/board_ea4357.c b/hw/bsp/ea4357/ea4357.c similarity index 100% rename from hw/bsp/ea4357/board_ea4357.c rename to hw/bsp/ea4357/ea4357.c diff --git a/hw/bsp/feather_m4_express/board_feather_m4_express.c b/hw/bsp/feather_m4_express/feather_m4_express.c similarity index 100% rename from hw/bsp/feather_m4_express/board_feather_m4_express.c rename to hw/bsp/feather_m4_express/feather_m4_express.c diff --git a/hw/bsp/feather_nrf52840_express/board.mk b/hw/bsp/feather_nrf52840_express/board.mk index f89baaaaa..11b5e7bdc 100644 --- a/hw/bsp/feather_nrf52840_express/board.mk +++ b/hw/bsp/feather_nrf52840_express/board.mk @@ -21,7 +21,7 @@ SRC_C += \ hw/mcu/nordic/nrfx/mdk/system_nrf52840.c \ INC += \ - $(TOP)/hw/cmsis/Include \ + $(TOP)/hw/mcu/nordic/cmsis/Include \ $(TOP)/hw/mcu/nordic \ $(TOP)/hw/mcu/nordic/nrfx \ $(TOP)/hw/mcu/nordic/nrfx/mdk \ diff --git a/hw/bsp/feather_nrf52840_express/board_feather_nrf52840_express.c b/hw/bsp/feather_nrf52840_express/feather_nrf52840_express.c similarity index 99% rename from hw/bsp/feather_nrf52840_express/board_feather_nrf52840_express.c rename to hw/bsp/feather_nrf52840_express/feather_nrf52840_express.c index 27f939e05..ed3954c82 100644 --- a/hw/bsp/feather_nrf52840_express/board_feather_nrf52840_express.c +++ b/hw/bsp/feather_nrf52840_express/feather_nrf52840_express.c @@ -67,10 +67,12 @@ void board_init(void) SysTick_Config(SystemCoreClock/1000); #endif +#if TUSB_OPT_DEVICE_ENABLED // Priorities 0, 1, 4 (nRF52) are reserved for SoftDevice // 2 is highest for application NVIC_SetPriority(USBD_IRQn, 2); + // USB power may already be ready at this time -> no event generated // We need to invoke the handler based on the status initially uint32_t usb_reg; @@ -103,6 +105,7 @@ void board_init(void) 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); +#endif } //--------------------------------------------------------------------+ diff --git a/hw/bsp/lpcxpresso11u68/board.mk b/hw/bsp/lpcxpresso11u68/board.mk index 70c349a4f..29287692e 100644 --- a/hw/bsp/lpcxpresso11u68/board.mk +++ b/hw/bsp/lpcxpresso11u68/board.mk @@ -14,19 +14,19 @@ CFLAGS += \ LD_FILE = hw/bsp/lpcxpresso11u68/lpc11u68.ld SRC_C += \ - hw/mcu/nxp/lpcopen/lpc_chip_11u6x/src/chip_11u6x.c \ - hw/mcu/nxp/lpcopen/lpc_chip_11u6x/src/clock_11u6x.c \ - hw/mcu/nxp/lpcopen/lpc_chip_11u6x/src/gpio_11u6x.c \ - hw/mcu/nxp/lpcopen/lpc_chip_11u6x/src/iocon_11u6x.c \ - hw/mcu/nxp/lpcopen/lpc_chip_11u6x/src/syscon_11u6x.c \ - hw/mcu/nxp/lpcopen/lpc_chip_11u6x/src/sysinit_11u6x.c + hw/mcu/nxp/lpc_driver/lpc_chip_11u6x/src/chip_11u6x.c \ + hw/mcu/nxp/lpc_driver/lpc_chip_11u6x/src/clock_11u6x.c \ + hw/mcu/nxp/lpc_driver/lpc_chip_11u6x/src/gpio_11u6x.c \ + hw/mcu/nxp/lpc_driver/lpc_chip_11u6x/src/iocon_11u6x.c \ + hw/mcu/nxp/lpc_driver/lpc_chip_11u6x/src/syscon_11u6x.c \ + hw/mcu/nxp/lpc_driver/lpc_chip_11u6x/src/sysinit_11u6x.c INC += \ - $(TOP)/hw/mcu/nxp/lpcopen/lpc_chip_11u6x/inc + $(TOP)/hw/mcu/nxp/lpc_driver/lpc_chip_11u6x/inc # For TinyUSB port source VENDOR = nxp -CHIP_FAMILY = lpc11_13_15 +CHIP_FAMILY = lpc_usbd # For freeRTOS port source FREERTOS_PORT = ARM_CM0 diff --git a/hw/bsp/lpcxpresso11u68/board_lpcxpresso11u68.c b/hw/bsp/lpcxpresso11u68/lpcxpresso11u68.c similarity index 100% rename from hw/bsp/lpcxpresso11u68/board_lpcxpresso11u68.c rename to hw/bsp/lpcxpresso11u68/lpcxpresso11u68.c diff --git a/hw/bsp/lpcxpresso1347/board.mk b/hw/bsp/lpcxpresso1347/board.mk index e87c4e7da..f7600f427 100644 --- a/hw/bsp/lpcxpresso1347/board.mk +++ b/hw/bsp/lpcxpresso1347/board.mk @@ -13,19 +13,19 @@ CFLAGS += \ LD_FILE = hw/bsp/lpcxpresso1347/lpc1347.ld SRC_C += \ - hw/mcu/nxp/lpcopen/lpc_chip_13xx/src/chip_13xx.c \ - hw/mcu/nxp/lpcopen/lpc_chip_13xx/src/clock_13xx.c \ - hw/mcu/nxp/lpcopen/lpc_chip_13xx/src/gpio_13xx_1.c \ - hw/mcu/nxp/lpcopen/lpc_chip_13xx/src/iocon_13xx.c \ - hw/mcu/nxp/lpcopen/lpc_chip_13xx/src/sysctl_13xx.c \ - hw/mcu/nxp/lpcopen/lpc_chip_13xx/src/sysinit_13xx.c + hw/mcu/nxp/lpc_driver/lpc_chip_13xx/src/chip_13xx.c \ + hw/mcu/nxp/lpc_driver/lpc_chip_13xx/src/clock_13xx.c \ + hw/mcu/nxp/lpc_driver/lpc_chip_13xx/src/gpio_13xx_1.c \ + hw/mcu/nxp/lpc_driver/lpc_chip_13xx/src/iocon_13xx.c \ + hw/mcu/nxp/lpc_driver/lpc_chip_13xx/src/sysctl_13xx.c \ + hw/mcu/nxp/lpc_driver/lpc_chip_13xx/src/sysinit_13xx.c INC += \ - $(TOP)/hw/mcu/nxp/lpcopen/lpc_chip_13xx/inc + $(TOP)/hw/mcu/nxp/lpc_driver/lpc_chip_13xx/inc # For TinyUSB port source VENDOR = nxp -CHIP_FAMILY = lpc11_13_15 +CHIP_FAMILY = lpc_usbd # For freeRTOS port source FREERTOS_PORT = ARM_CM3 diff --git a/hw/bsp/lpcxpresso1347/board_lpcxpresso1347.c b/hw/bsp/lpcxpresso1347/lpcxpresso1347.c similarity index 100% rename from hw/bsp/lpcxpresso1347/board_lpcxpresso1347.c rename to hw/bsp/lpcxpresso1347/lpcxpresso1347.c diff --git a/hw/bsp/lpcxpresso1769/board.mk b/hw/bsp/lpcxpresso1769/board.mk index 1885ae909..b1e58d6a5 100644 --- a/hw/bsp/lpcxpresso1769/board.mk +++ b/hw/bsp/lpcxpresso1769/board.mk @@ -15,16 +15,16 @@ LD_FILE = hw/bsp/lpcxpresso1769/lpc1769.ld SRC_C += src/portable/$(VENDOR)/$(CHIP_FAMILY)/hal_$(CHIP_FAMILY).c SRC_C += \ - hw/mcu/nxp/lpcopen/lpc_chip_175x_6x/src/chip_17xx_40xx.c \ - hw/mcu/nxp/lpcopen/lpc_chip_175x_6x/src/clock_17xx_40xx.c \ - hw/mcu/nxp/lpcopen/lpc_chip_175x_6x/src/gpio_17xx_40xx.c \ - hw/mcu/nxp/lpcopen/lpc_chip_175x_6x/src/iocon_17xx_40xx.c \ - hw/mcu/nxp/lpcopen/lpc_chip_175x_6x/src/sysctl_17xx_40xx.c \ - hw/mcu/nxp/lpcopen/lpc_chip_175x_6x/src/sysinit_17xx_40xx.c \ - hw/mcu/nxp/lpcopen/lpc_chip_175x_6x/src/uart_17xx_40xx.c + hw/mcu/nxp/lpc_driver/lpc_chip_175x_6x/src/chip_17xx_40xx.c \ + hw/mcu/nxp/lpc_driver/lpc_chip_175x_6x/src/clock_17xx_40xx.c \ + hw/mcu/nxp/lpc_driver/lpc_chip_175x_6x/src/gpio_17xx_40xx.c \ + hw/mcu/nxp/lpc_driver/lpc_chip_175x_6x/src/iocon_17xx_40xx.c \ + hw/mcu/nxp/lpc_driver/lpc_chip_175x_6x/src/sysctl_17xx_40xx.c \ + hw/mcu/nxp/lpc_driver/lpc_chip_175x_6x/src/sysinit_17xx_40xx.c \ + hw/mcu/nxp/lpc_driver/lpc_chip_175x_6x/src/uart_17xx_40xx.c INC += \ - $(TOP)/hw/mcu/nxp/lpcopen/lpc_chip_175x_6x/inc + $(TOP)/hw/mcu/nxp/lpc_driver/lpc_chip_175x_6x/inc # For TinyUSB port source VENDOR = nxp diff --git a/hw/bsp/lpcxpresso1769/board_lpcxpresso1769.c b/hw/bsp/lpcxpresso1769/lpcxpresso1769.c similarity index 100% rename from hw/bsp/lpcxpresso1769/board_lpcxpresso1769.c rename to hw/bsp/lpcxpresso1769/lpcxpresso1769.c diff --git a/hw/bsp/lpcxpresso51u68/LPC51U68_flash.ld b/hw/bsp/lpcxpresso51u68/LPC51U68_flash.ld new file mode 100644 index 000000000..89b46c692 --- /dev/null +++ b/hw/bsp/lpcxpresso51u68/LPC51U68_flash.ld @@ -0,0 +1,200 @@ +/* +** ################################################################### +** Processors: LPC51U68JBD48 +** LPC51U68JBD64 +** +** Compiler: GNU C Compiler +** Reference manual: LPC51U68 User manual User manual Rev. 1.0 13 Dec 2017 +** Version: rev. 1.0, 2017-12-15 +** Build: b180801 +** +** Abstract: +** Linker file for the GNU C Compiler +** +** Copyright 2016 Freescale Semiconductor, Inc. +** Copyright 2016-2018 NXP +** +** SPDX-License-Identifier: BSD-3-Clause +** +** http: www.nxp.com +** mail: support@nxp.com +** +** ################################################################### +*/ + + + +/* Entry Point */ +ENTRY(Reset_Handler) + +HEAP_SIZE = DEFINED(__heap_size__) ? __heap_size__ : 0x0400; +STACK_SIZE = DEFINED(__stack_size__) ? __stack_size__ : 0x0800; + +/* Specify the memory areas */ +MEMORY +{ + m_interrupts (RX) : ORIGIN = 0x00000000, LENGTH = 0x000000E0 + m_text (RX) : ORIGIN = 0x000000E0, LENGTH = 0x0003FF20 + m_data_sramx (RW) : ORIGIN = 0x04000000, LENGTH = 0x00008000 + m_data (RW) : ORIGIN = 0x20000000, LENGTH = 0x00010000 +} + +/* Define output sections */ +SECTIONS +{ + /* The startup code goes first into internal flash */ + .interrupts : + { + . = ALIGN(4); + KEEP(*(.isr_vector)) /* Startup code */ + . = ALIGN(4); + } > m_interrupts + + /* The program code and other data goes into internal flash */ + .text : + { + . = ALIGN(4); + *(.text) /* .text sections (code) */ + *(.text*) /* .text* sections (code) */ + *(.rodata) /* .rodata sections (constants, strings, etc.) */ + *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ + *(.glue_7) /* glue arm to thumb code */ + *(.glue_7t) /* glue thumb to arm code */ + *(.eh_frame) + KEEP (*(.init)) + KEEP (*(.fini)) + . = ALIGN(4); + } > m_text + + .ARM.extab : + { + *(.ARM.extab* .gnu.linkonce.armextab.*) + } > m_text + + .ARM : + { + __exidx_start = .; + *(.ARM.exidx*) + __exidx_end = .; + } > m_text + + .ctors : + { + __CTOR_LIST__ = .; + /* gcc uses crtbegin.o to find the start of + the constructors, so we make sure it is + first. Because this is a wildcard, it + doesn't matter if the user does not + actually link against crtbegin.o; the + linker won't look for a file to match a + wildcard. The wildcard also means that it + doesn't matter which directory crtbegin.o + is in. */ + KEEP (*crtbegin.o(.ctors)) + KEEP (*crtbegin?.o(.ctors)) + /* We don't want to include the .ctor section from + from the crtend.o file until after the sorted ctors. + The .ctor section from the crtend file contains the + end of ctors marker and it must be last */ + KEEP (*(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)) + KEEP (*(SORT(.ctors.*))) + KEEP (*(.ctors)) + __CTOR_END__ = .; + } > m_text + + .dtors : + { + __DTOR_LIST__ = .; + KEEP (*crtbegin.o(.dtors)) + KEEP (*crtbegin?.o(.dtors)) + KEEP (*(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)) + KEEP (*(SORT(.dtors.*))) + KEEP (*(.dtors)) + __DTOR_END__ = .; + } > m_text + + .preinit_array : + { + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP (*(.preinit_array*)) + PROVIDE_HIDDEN (__preinit_array_end = .); + } > m_text + + .init_array : + { + PROVIDE_HIDDEN (__init_array_start = .); + KEEP (*(SORT(.init_array.*))) + KEEP (*(.init_array*)) + PROVIDE_HIDDEN (__init_array_end = .); + } > m_text + + .fini_array : + { + PROVIDE_HIDDEN (__fini_array_start = .); + KEEP (*(SORT(.fini_array.*))) + KEEP (*(.fini_array*)) + PROVIDE_HIDDEN (__fini_array_end = .); + } > m_text + + __etext = .; /* define a global symbol at end of code */ + __DATA_ROM = .; /* Symbol is used by startup for data initialization */ + + .data : AT(__DATA_ROM) + { + . = ALIGN(4); + __DATA_RAM = .; + __data_start__ = .; /* create a global symbol at data start */ + *(.ramfunc*) /* for functions in ram */ + *(.data) /* .data sections */ + *(.data*) /* .data* sections */ + KEEP(*(.jcr*)) + . = ALIGN(4); + __data_end__ = .; /* define a global symbol at data end */ + } > m_data + + __DATA_END = __DATA_ROM + (__data_end__ - __data_start__); + text_end = ORIGIN(m_text) + LENGTH(m_text); + ASSERT(__DATA_END <= text_end, "region m_text overflowed with text and data") + + /* Uninitialized data section */ + .bss : + { + /* This is used by the startup in order to initialize the .bss section */ + . = ALIGN(4); + __START_BSS = .; + __bss_start__ = .; + *(.bss) + *(.bss*) + *(COMMON) + . = ALIGN(4); + __bss_end__ = .; + __END_BSS = .; + } > m_data + + .heap : + { + . = ALIGN(8); + __end__ = .; + PROVIDE(end = .); + __HeapBase = .; + . += HEAP_SIZE; + __HeapLimit = .; + __heap_limit = .; /* Add for _sbrk */ + } > m_data_sramx + + .stack : + { + . = ALIGN(8); + . += STACK_SIZE; + } > m_data_sramx + + /* Initializes stack on the end of block */ + __StackTop = ORIGIN(m_data_sramx) + LENGTH(m_data_sramx); + __StackLimit = __StackTop - STACK_SIZE; + PROVIDE(__stack = __StackTop); + + .ARM.attributes 0 : { *(.ARM.attributes) } + + ASSERT(__StackLimit >= __HeapLimit, "region m_data_sramx overflowed with stack and heap") +} + diff --git a/hw/bsp/lpcxpresso51u68/board.mk b/hw/bsp/lpcxpresso51u68/board.mk new file mode 100644 index 000000000..83ad1d360 --- /dev/null +++ b/hw/bsp/lpcxpresso51u68/board.mk @@ -0,0 +1,43 @@ +CFLAGS += \ + -mthumb \ + -mabi=aapcs \ + -mcpu=cortex-m0plus \ + -DCORE_M0PLUS \ + -DCFG_TUSB_MCU=OPT_MCU_LPC51UXX \ + -DCPU_LPC51U68JBD64 \ + -Wfatal-errors \ + -DCFG_TUSB_MEM_SECTION='__attribute__((section(".data.$$RAM3")))' \ + -DCFG_TUSB_MEM_ALIGN='__attribute__((aligned(64)))' + +# All source paths should be relative to the top level. +LD_FILE = hw/bsp/lpcxpresso51u68/LPC51U68_flash.ld + +SRC_C += \ + hw/mcu/nxp/lpc_driver/lpc51u6x/devices/LPC51U68/system_LPC51U68.c \ + hw/mcu/nxp/lpc_driver/lpc51u6x/drivers/fsl_clock.c \ + hw/mcu/nxp/lpc_driver/lpc51u6x/drivers/fsl_gpio.c \ + hw/mcu/nxp/lpc_driver/lpc51u6x/drivers/fsl_power.c \ + hw/mcu/nxp/lpc_driver/lpc51u6x/drivers/fsl_reset.c + +INC += \ + $(TOP)/hw/mcu/nxp/lpc_driver/lpc51u6x/CMSIS/Include \ + $(TOP)/hw/mcu/nxp/lpc_driver/lpc51u6x/devices/LPC51U68 \ + $(TOP)/hw/mcu/nxp/lpc_driver/lpc51u6x/drivers + +SRC_S += hw/bsp/lpcxpresso51u68/startup_LPC51U68.S + +LIBS += $(TOP)/hw/mcu/nxp/lpc_driver/lpc51u6x/devices/LPC51U68/libpower.a + +# For TinyUSB port source +VENDOR = nxp +CHIP_FAMILY = lpc_usbd + +# For freeRTOS port source +FREERTOS_PORT = ARM_CM0 + +# For flash-jlink target +JLINK_DEVICE = LPC51U68 +JLINK_IF = swd + +# flash using jlink +#flash: flash-jlink diff --git a/hw/bsp/lpcxpresso51u68/lpcxpresso51u68.c b/hw/bsp/lpcxpresso51u68/lpcxpresso51u68.c new file mode 100644 index 000000000..8b57ce7b9 --- /dev/null +++ b/hw/bsp/lpcxpresso51u68/lpcxpresso51u68.c @@ -0,0 +1,170 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2018, hathach (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. + */ + +#include "../board.h" +#include "LPC51U68.h" +#include "fsl_gpio.h" +#include "fsl_power.h" +#include "fsl_iocon.h" + +#define LED_PORT 0 +#define LED_PIN 29 +#define LED_STATE_ON 0 + +// WAKE button +#define BUTTON_PORT 0 +#define BUTTON_PIN 24 + +// IOCON pin mux +#define IOCON_PIO_DIGITAL_EN 0x80u /*!< Enables digital function */ +#define IOCON_PIO_FUNC1 0x01u /*!< Selects pin function 1 */ +#define IOCON_PIO_FUNC7 0x07u /*!< Selects pin function 7 */ +#define IOCON_PIO_INPFILT_OFF 0x0100u /*!< Input filter disabled */ +#define IOCON_PIO_INV_DI 0x00u /*!< Input function is not inverted */ +#define IOCON_PIO_MODE_INACT 0x00u /*!< No addition pin function */ +#define IOCON_PIO_OPENDRAIN_DI 0x00u /*!< Open drain is disabled */ +#define IOCON_PIO_SLEW_STANDARD 0x00u /*!< Standard mode, output slew rate control is enabled */ + +/**************************************************************** +name: BOARD_BootClockFROHF96M +outputs: +- {id: SYSTICK_clock.outFreq, value: 96 MHz} +- {id: System_clock.outFreq, value: 96 MHz} +settings: +- {id: SYSCON.MAINCLKSELA.sel, value: SYSCON.fro_hf} +sources: +- {id: SYSCON.fro_hf.outFreq, value: 96 MHz} +******************************************************************/ +void BootClockFROHF96M(void) +{ + /*!< Set up the clock sources */ + /*!< Set up FRO */ + POWER_DisablePD(kPDRUNCFG_PD_FRO_EN); /*!< Ensure FRO is on */ + CLOCK_AttachClk(kFRO12M_to_MAIN_CLK); /*!< Switch to FRO 12MHz first to ensure we can change voltage without + accidentally being below the voltage for current speed */ + POWER_SetVoltageForFreq(96000000U); /*!< Set voltage for the one of the fastest clock outputs: System clock output */ + CLOCK_SetFLASHAccessCyclesForFreq(96000000U); /*!< Set FLASH wait states for core */ + + CLOCK_SetupFROClocking(96000000U); /*!< Set up high frequency FRO output to selected frequency */ + + /*!< Set up dividers */ + CLOCK_SetClkDiv(kCLOCK_DivAhbClk, 1U, false); /*!< Set AHBCLKDIV divider to value 1 */ + CLOCK_SetClkDiv(kCLOCK_DivSystickClk, 0U, true); /*!< Reset SYSTICKCLKDIV divider counter and halt it */ + CLOCK_SetClkDiv(kCLOCK_DivSystickClk, 1U, false); /*!< Set SYSTICKCLKDIV divider to value 1 */ + + /*!< Set up clock selectors - Attach clocks to the peripheries */ + CLOCK_AttachClk(kFRO_HF_to_MAIN_CLK); /*!< Switch MAIN_CLK to FRO_HF */ + /*!< Set SystemCoreClock variable. */ + SystemCoreClock = 96000000U; +} + +void board_init(void) +{ + // Enable IOCON clock + CLOCK_EnableClock(kCLOCK_Iocon); + + // Enable GPIO0 clock + CLOCK_EnableClock(kCLOCK_Gpio0); + + // Init 96 MHz clock + BootClockFROHF96M(); + +#if CFG_TUSB_OS == OPT_OS_NONE + // 1ms tick timer + SysTick_Config(SystemCoreClock / 1000); +#elif CFG_TUSB_OS == OPT_OS_FREERTOS + // If freeRTOS is used, IRQ priority is limit by max syscall ( smaller is higher ) + NVIC_SetPriority(USB0_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY ); +#endif + + GPIO_PortInit(GPIO, LED_PORT); + GPIO_PortInit(GPIO, BUTTON_PORT); + + // LED + gpio_pin_config_t const led_config = { kGPIO_DigitalOutput, 0}; + GPIO_PinInit(GPIO, LED_PORT, LED_PIN, &led_config); + board_led_write(true); + + // Button + gpio_pin_config_t const button_config = { kGPIO_DigitalInput, 0}; + GPIO_PinInit(GPIO, BUTTON_PORT, BUTTON_PIN, &button_config); + + // USB + const uint32_t port1_pin6_config = ( + IOCON_PIO_FUNC7 | /* Pin is configured as USB0_VBUS */ + IOCON_PIO_MODE_INACT | /* No addition pin function */ + IOCON_PIO_INV_DI | /* Input function is not inverted */ + IOCON_PIO_DIGITAL_EN | /* Enables digital function */ + IOCON_PIO_INPFILT_OFF | /* Input filter disabled */ + IOCON_PIO_OPENDRAIN_DI /* Open drain is disabled */ + ); + IOCON_PinMuxSet(IOCON, 1, 6, port1_pin6_config); /* PORT1 PIN6 (coords: 26) is configured as USB0_VBUS */ + + POWER_DisablePD(kPDRUNCFG_PD_USB0_PHY); /*Turn on USB Phy */ + CLOCK_EnableUsbfs0Clock(kCLOCK_UsbSrcFro, CLOCK_GetFreq(kCLOCK_FroHf)); /* enable USB IP clock */ +} + +//--------------------------------------------------------------------+ +// Board porting API +//--------------------------------------------------------------------+ + +void board_led_write(bool state) +{ + GPIO_PinWrite(GPIO, LED_PORT, LED_PIN, state ? LED_STATE_ON : (1-LED_STATE_ON)); +} + +uint32_t board_button_read(void) +{ + // active low + return 1-GPIO_PinRead(GPIO, BUTTON_PORT, BUTTON_PIN); +} + +int board_uart_read(uint8_t* buf, int len) +{ + (void) buf; + (void) len; + return 0; +} + +int board_uart_write(void const * buf, int len) +{ + (void) buf; + (void) len; + return 0; +} + +#if CFG_TUSB_OS == OPT_OS_NONE +volatile uint32_t system_ticks = 0; +void SysTick_Handler(void) +{ + system_ticks++; +} + +uint32_t board_millis(void) +{ + return system_ticks; +} +#endif diff --git a/hw/bsp/lpcxpresso51u68/startup_LPC51U68.S b/hw/bsp/lpcxpresso51u68/startup_LPC51U68.S new file mode 100644 index 000000000..81a6f320e --- /dev/null +++ b/hw/bsp/lpcxpresso51u68/startup_LPC51U68.S @@ -0,0 +1,536 @@ +/* --------------------------------------------------------------------------*/ +/* @file: startup_LPC51U68.S */ +/* @purpose: CMSIS Cortex-M0+ Core Device Startup File */ +/* LPC51U68 */ +/* @version: 1.0 */ +/* @date: 2017-12-15 */ +/* --------------------------------------------------------------------------*/ +/* */ +/* Copyright 1997-2016 Freescale Semiconductor, Inc. */ +/* Copyright 2016-2018 NXP */ +/* */ +/* SPDX-License-Identifier: BSD-3-Clause */ +/*****************************************************************************/ +/* Version: GCC for ARM Embedded Processors */ +/*****************************************************************************/ + + + .syntax unified + .arch armv6-m + + .section .isr_vector, "a" + .align 2 + .globl __Vectors +__Vectors: + .long __StackTop /* Top of Stack */ + .long Reset_Handler /* Reset Handler */ + .long NMI_Handler /* NMI Handler */ + .long HardFault_Handler /* Hard Fault Handler */ + .long 0 /* Reserved */ + .long 0 /* Reserved */ + .long 0 /* Reserved */ + .long 0 /* Reserved */ + .long 0 /* Reserved */ + .long 0 /* Reserved */ + .long 0 /* Reserved */ + .long SVC_Handler /* SVCall Handler */ + .long 0 /* Reserved */ + .long 0 /* Reserved */ + .long PendSV_Handler /* PendSV Handler */ + .long SysTick_Handler /* SysTick Handler */ + + /* External Interrupts */ + .long WDT_BOD_IRQHandler /* Windowed watchdog timer, Brownout detect */ + .long DMA0_IRQHandler /* DMA controller */ + .long GINT0_IRQHandler /* GPIO group 0 */ + .long GINT1_IRQHandler /* GPIO group 1 */ + .long PIN_INT0_IRQHandler /* Pin interrupt 0 or pattern match engine slice 0 */ + .long PIN_INT1_IRQHandler /* Pin interrupt 1or pattern match engine slice 1 */ + .long PIN_INT2_IRQHandler /* Pin interrupt 2 or pattern match engine slice 2 */ + .long PIN_INT3_IRQHandler /* Pin interrupt 3 or pattern match engine slice 3 */ + .long UTICK0_IRQHandler /* Micro-tick Timer */ + .long MRT0_IRQHandler /* Multi-rate timer */ + .long CTIMER0_IRQHandler /* Standard counter/timer CTIMER0 */ + .long CTIMER1_IRQHandler /* Standard counter/timer CTIMER1 */ + .long SCT0_IRQHandler /* SCTimer/PWM */ + .long CTIMER3_IRQHandler /* Standard counter/timer CTIMER3 */ + .long FLEXCOMM0_IRQHandler /* Flexcomm Interface 0 (USART, SPI, I2C) */ + .long FLEXCOMM1_IRQHandler /* Flexcomm Interface 1 (USART, SPI, I2C) */ + .long FLEXCOMM2_IRQHandler /* Flexcomm Interface 2 (USART, SPI, I2C) */ + .long FLEXCOMM3_IRQHandler /* Flexcomm Interface 3 (USART, SPI, I2C) */ + .long FLEXCOMM4_IRQHandler /* Flexcomm Interface 4 (USART, SPI, I2C) */ + .long FLEXCOMM5_IRQHandler /* Flexcomm Interface 5 (USART, SPI, I2C) */ + .long FLEXCOMM6_IRQHandler /* Flexcomm Interface 6 (USART, SPI, I2C, I2S) */ + .long FLEXCOMM7_IRQHandler /* Flexcomm Interface 7 (USART, SPI, I2C, I2S) */ + .long ADC0_SEQA_IRQHandler /* ADC0 sequence A completion. */ + .long ADC0_SEQB_IRQHandler /* ADC0 sequence B completion. */ + .long ADC0_THCMP_IRQHandler /* ADC0 threshold compare and error. */ + .long Reserved41_IRQHandler /* Reserved interrupt */ + .long Reserved42_IRQHandler /* Reserved interrupt */ + .long USB0_NEEDCLK_IRQHandler /* USB Activity Wake-up Interrupt */ + .long USB0_IRQHandler /* USB device */ + .long RTC_IRQHandler /* RTC alarm and wake-up interrupts */ + .long Reserved46_IRQHandler /* Reserved interrupt */ + .long Reserved47_IRQHandler /* Reserved interrupt */ + + .size __Vectors, . - __Vectors + + .text + .thumb + +/* Reset Handler */ + .thumb_func + .align 2 + .globl Reset_Handler + .weak Reset_Handler + .type Reset_Handler, %function +Reset_Handler: + cpsid i /* Mask interrupts */ + +#ifndef __NO_SYSTEM_INIT + ldr r0,=SystemInit + blx r0 +#endif +/* Loop to copy data from read only memory to RAM. The ranges + * of copy from/to are specified by following symbols evaluated in + * linker script. + * __etext: End of code section, i.e., begin of data sections to copy from. + * __data_start__/__data_end__: RAM address range that data should be + * copied to. Both must be aligned to 4 bytes boundary. */ + + ldr r1, =__etext + ldr r2, =__data_start__ + ldr r3, =__data_end__ + + subs r3, r2 + ble .LC0 + +.LC1: + subs r3, 4 + ldr r0, [r1,r3] + str r0, [r2,r3] + bgt .LC1 +.LC0: + +#ifdef __STARTUP_CLEAR_BSS +/* This part of work usually is done in C library startup code. Otherwise, + * define this macro to enable it in this startup. + * + * Loop to zero out BSS section, which uses following symbols + * in linker script: + * __bss_start__: start of BSS section. Must align to 4 + * __bss_end__: end of BSS section. Must align to 4 + */ + ldr r1, =__bss_start__ + ldr r2, =__bss_end__ + + subs r2, r1 + ble .LC3 + + movs r0, 0 +.LC2: + str r0, [r1, r2] + subs r2, 4 + bge .LC2 +.LC3: +#endif + cpsie i /* Unmask interrupts */ + +#ifndef __START +#define __START _start +#endif +#ifndef __ATOLLIC__ + ldr r0,=__START + blx r0 +#else + ldr r0,=__libc_init_array + blx r0 + ldr r0,=main + bx r0 +#endif + .pool + .size Reset_Handler, . - Reset_Handler + + .align 1 + .thumb_func + .weak DefaultISR + .type DefaultISR, %function +DefaultISR: + ldr r0, =DefaultISR + bx r0 + .size DefaultISR, . - DefaultISR + + .align 1 + .thumb_func + .weak NMI_Handler + .type NMI_Handler, %function +NMI_Handler: + ldr r0,=NMI_Handler + bx r0 + .size NMI_Handler, . - NMI_Handler + + .align 1 + .thumb_func + .weak HardFault_Handler + .type HardFault_Handler, %function +HardFault_Handler: + ldr r0,=HardFault_Handler + bx r0 + .size HardFault_Handler, . - HardFault_Handler + + .align 1 + .thumb_func + .weak SVC_Handler + .type SVC_Handler, %function +SVC_Handler: + ldr r0,=SVC_Handler + bx r0 + .size SVC_Handler, . - SVC_Handler + + .align 1 + .thumb_func + .weak PendSV_Handler + .type PendSV_Handler, %function +PendSV_Handler: + ldr r0,=PendSV_Handler + bx r0 + .size PendSV_Handler, . - PendSV_Handler + + .align 1 + .thumb_func + .weak SysTick_Handler + .type SysTick_Handler, %function +SysTick_Handler: + ldr r0,=SysTick_Handler + bx r0 + .size SysTick_Handler, . - SysTick_Handler + + .align 1 + .thumb_func + .weak WDT_BOD_IRQHandler + .type WDT_BOD_IRQHandler, %function +WDT_BOD_IRQHandler: + ldr r0,=WDT_BOD_DriverIRQHandler + bx r0 + .size WDT_BOD_IRQHandler, . - WDT_BOD_IRQHandler + + .align 1 + .thumb_func + .weak DMA0_IRQHandler + .type DMA0_IRQHandler, %function +DMA0_IRQHandler: + ldr r0,=DMA0_DriverIRQHandler + bx r0 + .size DMA0_IRQHandler, . - DMA0_IRQHandler + + .align 1 + .thumb_func + .weak GINT0_IRQHandler + .type GINT0_IRQHandler, %function +GINT0_IRQHandler: + ldr r0,=GINT0_DriverIRQHandler + bx r0 + .size GINT0_IRQHandler, . - GINT0_IRQHandler + + .align 1 + .thumb_func + .weak GINT1_IRQHandler + .type GINT1_IRQHandler, %function +GINT1_IRQHandler: + ldr r0,=GINT1_DriverIRQHandler + bx r0 + .size GINT1_IRQHandler, . - GINT1_IRQHandler + + .align 1 + .thumb_func + .weak PIN_INT0_IRQHandler + .type PIN_INT0_IRQHandler, %function +PIN_INT0_IRQHandler: + ldr r0,=PIN_INT0_DriverIRQHandler + bx r0 + .size PIN_INT0_IRQHandler, . - PIN_INT0_IRQHandler + + .align 1 + .thumb_func + .weak PIN_INT1_IRQHandler + .type PIN_INT1_IRQHandler, %function +PIN_INT1_IRQHandler: + ldr r0,=PIN_INT1_DriverIRQHandler + bx r0 + .size PIN_INT1_IRQHandler, . - PIN_INT1_IRQHandler + + .align 1 + .thumb_func + .weak PIN_INT2_IRQHandler + .type PIN_INT2_IRQHandler, %function +PIN_INT2_IRQHandler: + ldr r0,=PIN_INT2_DriverIRQHandler + bx r0 + .size PIN_INT2_IRQHandler, . - PIN_INT2_IRQHandler + + .align 1 + .thumb_func + .weak PIN_INT3_IRQHandler + .type PIN_INT3_IRQHandler, %function +PIN_INT3_IRQHandler: + ldr r0,=PIN_INT3_DriverIRQHandler + bx r0 + .size PIN_INT3_IRQHandler, . - PIN_INT3_IRQHandler + + .align 1 + .thumb_func + .weak UTICK0_IRQHandler + .type UTICK0_IRQHandler, %function +UTICK0_IRQHandler: + ldr r0,=UTICK0_DriverIRQHandler + bx r0 + .size UTICK0_IRQHandler, . - UTICK0_IRQHandler + + .align 1 + .thumb_func + .weak MRT0_IRQHandler + .type MRT0_IRQHandler, %function +MRT0_IRQHandler: + ldr r0,=MRT0_DriverIRQHandler + bx r0 + .size MRT0_IRQHandler, . - MRT0_IRQHandler + + .align 1 + .thumb_func + .weak CTIMER0_IRQHandler + .type CTIMER0_IRQHandler, %function +CTIMER0_IRQHandler: + ldr r0,=CTIMER0_DriverIRQHandler + bx r0 + .size CTIMER0_IRQHandler, . - CTIMER0_IRQHandler + + .align 1 + .thumb_func + .weak CTIMER1_IRQHandler + .type CTIMER1_IRQHandler, %function +CTIMER1_IRQHandler: + ldr r0,=CTIMER1_DriverIRQHandler + bx r0 + .size CTIMER1_IRQHandler, . - CTIMER1_IRQHandler + + .align 1 + .thumb_func + .weak SCT0_IRQHandler + .type SCT0_IRQHandler, %function +SCT0_IRQHandler: + ldr r0,=SCT0_DriverIRQHandler + bx r0 + .size SCT0_IRQHandler, . - SCT0_IRQHandler + + .align 1 + .thumb_func + .weak CTIMER3_IRQHandler + .type CTIMER3_IRQHandler, %function +CTIMER3_IRQHandler: + ldr r0,=CTIMER3_DriverIRQHandler + bx r0 + .size CTIMER3_IRQHandler, . - CTIMER3_IRQHandler + + .align 1 + .thumb_func + .weak FLEXCOMM0_IRQHandler + .type FLEXCOMM0_IRQHandler, %function +FLEXCOMM0_IRQHandler: + ldr r0,=FLEXCOMM0_DriverIRQHandler + bx r0 + .size FLEXCOMM0_IRQHandler, . - FLEXCOMM0_IRQHandler + + .align 1 + .thumb_func + .weak FLEXCOMM1_IRQHandler + .type FLEXCOMM1_IRQHandler, %function +FLEXCOMM1_IRQHandler: + ldr r0,=FLEXCOMM1_DriverIRQHandler + bx r0 + .size FLEXCOMM1_IRQHandler, . - FLEXCOMM1_IRQHandler + + .align 1 + .thumb_func + .weak FLEXCOMM2_IRQHandler + .type FLEXCOMM2_IRQHandler, %function +FLEXCOMM2_IRQHandler: + ldr r0,=FLEXCOMM2_DriverIRQHandler + bx r0 + .size FLEXCOMM2_IRQHandler, . - FLEXCOMM2_IRQHandler + + .align 1 + .thumb_func + .weak FLEXCOMM3_IRQHandler + .type FLEXCOMM3_IRQHandler, %function +FLEXCOMM3_IRQHandler: + ldr r0,=FLEXCOMM3_DriverIRQHandler + bx r0 + .size FLEXCOMM3_IRQHandler, . - FLEXCOMM3_IRQHandler + + .align 1 + .thumb_func + .weak FLEXCOMM4_IRQHandler + .type FLEXCOMM4_IRQHandler, %function +FLEXCOMM4_IRQHandler: + ldr r0,=FLEXCOMM4_DriverIRQHandler + bx r0 + .size FLEXCOMM4_IRQHandler, . - FLEXCOMM4_IRQHandler + + .align 1 + .thumb_func + .weak FLEXCOMM5_IRQHandler + .type FLEXCOMM5_IRQHandler, %function +FLEXCOMM5_IRQHandler: + ldr r0,=FLEXCOMM5_DriverIRQHandler + bx r0 + .size FLEXCOMM5_IRQHandler, . - FLEXCOMM5_IRQHandler + + .align 1 + .thumb_func + .weak FLEXCOMM6_IRQHandler + .type FLEXCOMM6_IRQHandler, %function +FLEXCOMM6_IRQHandler: + ldr r0,=FLEXCOMM6_DriverIRQHandler + bx r0 + .size FLEXCOMM6_IRQHandler, . - FLEXCOMM6_IRQHandler + + .align 1 + .thumb_func + .weak FLEXCOMM7_IRQHandler + .type FLEXCOMM7_IRQHandler, %function +FLEXCOMM7_IRQHandler: + ldr r0,=FLEXCOMM7_DriverIRQHandler + bx r0 + .size FLEXCOMM7_IRQHandler, . - FLEXCOMM7_IRQHandler + + .align 1 + .thumb_func + .weak ADC0_SEQA_IRQHandler + .type ADC0_SEQA_IRQHandler, %function +ADC0_SEQA_IRQHandler: + ldr r0,=ADC0_SEQA_DriverIRQHandler + bx r0 + .size ADC0_SEQA_IRQHandler, . - ADC0_SEQA_IRQHandler + + .align 1 + .thumb_func + .weak ADC0_SEQB_IRQHandler + .type ADC0_SEQB_IRQHandler, %function +ADC0_SEQB_IRQHandler: + ldr r0,=ADC0_SEQB_DriverIRQHandler + bx r0 + .size ADC0_SEQB_IRQHandler, . - ADC0_SEQB_IRQHandler + + .align 1 + .thumb_func + .weak ADC0_THCMP_IRQHandler + .type ADC0_THCMP_IRQHandler, %function +ADC0_THCMP_IRQHandler: + ldr r0,=ADC0_THCMP_DriverIRQHandler + bx r0 + .size ADC0_THCMP_IRQHandler, . - ADC0_THCMP_IRQHandler + + .align 1 + .thumb_func + .weak Reserved41_IRQHandler + .type Reserved41_IRQHandler, %function +Reserved41_IRQHandler: + ldr r0,=Reserved41_DriverIRQHandler + bx r0 + .size Reserved41_IRQHandler, . - Reserved41_IRQHandler + + .align 1 + .thumb_func + .weak Reserved42_IRQHandler + .type Reserved42_IRQHandler, %function +Reserved42_IRQHandler: + ldr r0,=Reserved42_DriverIRQHandler + bx r0 + .size Reserved42_IRQHandler, . - Reserved42_IRQHandler + + .align 1 + .thumb_func + .weak USB0_NEEDCLK_IRQHandler + .type USB0_NEEDCLK_IRQHandler, %function +USB0_NEEDCLK_IRQHandler: + ldr r0,=USB0_NEEDCLK_DriverIRQHandler + bx r0 + .size USB0_NEEDCLK_IRQHandler, . - USB0_NEEDCLK_IRQHandler + + .align 1 + .thumb_func + .weak USB0_IRQHandler + .type USB0_IRQHandler, %function +USB0_IRQHandler: + ldr r0,=USB0_DriverIRQHandler + bx r0 + .size USB0_IRQHandler, . - USB0_IRQHandler + + .align 1 + .thumb_func + .weak RTC_IRQHandler + .type RTC_IRQHandler, %function +RTC_IRQHandler: + ldr r0,=RTC_DriverIRQHandler + bx r0 + .size RTC_IRQHandler, . - RTC_IRQHandler + + .align 1 + .thumb_func + .weak Reserved46_IRQHandler + .type Reserved46_IRQHandler, %function +Reserved46_IRQHandler: + ldr r0,=Reserved46_DriverIRQHandler + bx r0 + .size Reserved46_IRQHandler, . - Reserved46_IRQHandler + + .align 1 + .thumb_func + .weak Reserved47_IRQHandler + .type Reserved47_IRQHandler, %function +Reserved47_IRQHandler: + ldr r0,=Reserved47_DriverIRQHandler + bx r0 + .size Reserved47_IRQHandler, . - Reserved47_IRQHandler + +/* Macro to define default handlers. Default handler + * will be weak symbol and just dead loops. They can be + * overwritten by other handlers */ + .macro def_irq_handler handler_name + .weak \handler_name + .set \handler_name, DefaultISR + .endm + def_irq_handler WDT_BOD_DriverIRQHandler + def_irq_handler DMA0_DriverIRQHandler + def_irq_handler GINT0_DriverIRQHandler + def_irq_handler GINT1_DriverIRQHandler + def_irq_handler PIN_INT0_DriverIRQHandler + def_irq_handler PIN_INT1_DriverIRQHandler + def_irq_handler PIN_INT2_DriverIRQHandler + def_irq_handler PIN_INT3_DriverIRQHandler + def_irq_handler UTICK0_DriverIRQHandler + def_irq_handler MRT0_DriverIRQHandler + def_irq_handler CTIMER0_DriverIRQHandler + def_irq_handler CTIMER1_DriverIRQHandler + def_irq_handler SCT0_DriverIRQHandler + def_irq_handler CTIMER3_DriverIRQHandler + def_irq_handler FLEXCOMM0_DriverIRQHandler + def_irq_handler FLEXCOMM1_DriverIRQHandler + def_irq_handler FLEXCOMM2_DriverIRQHandler + def_irq_handler FLEXCOMM3_DriverIRQHandler + def_irq_handler FLEXCOMM4_DriverIRQHandler + def_irq_handler FLEXCOMM5_DriverIRQHandler + def_irq_handler FLEXCOMM6_DriverIRQHandler + def_irq_handler FLEXCOMM7_DriverIRQHandler + def_irq_handler ADC0_SEQA_DriverIRQHandler + def_irq_handler ADC0_SEQB_DriverIRQHandler + def_irq_handler ADC0_THCMP_DriverIRQHandler + def_irq_handler Reserved41_DriverIRQHandler + def_irq_handler Reserved42_DriverIRQHandler + def_irq_handler USB0_NEEDCLK_DriverIRQHandler + def_irq_handler USB0_DriverIRQHandler + def_irq_handler RTC_DriverIRQHandler + def_irq_handler Reserved46_DriverIRQHandler + def_irq_handler Reserved47_DriverIRQHandler + + .end diff --git a/hw/bsp/mcb1800/board.mk b/hw/bsp/mcb1800/board.mk index 7fdcc077a..50752d784 100644 --- a/hw/bsp/mcb1800/board.mk +++ b/hw/bsp/mcb1800/board.mk @@ -14,15 +14,15 @@ LD_FILE = hw/bsp/mcb1800/lpc1857.ld SRC_C += src/portable/$(VENDOR)/$(CHIP_FAMILY)/hal_$(CHIP_FAMILY).c SRC_C += \ - hw/mcu/nxp/lpcopen/lpc_chip_18xx/src/chip_18xx_43xx.c \ - hw/mcu/nxp/lpcopen/lpc_chip_18xx/src/clock_18xx_43xx.c \ - hw/mcu/nxp/lpcopen/lpc_chip_18xx/src/gpio_18xx_43xx.c \ - hw/mcu/nxp/lpcopen/lpc_chip_18xx/src/sysinit_18xx_43xx.c \ - hw/mcu/nxp/lpcopen/lpc_chip_18xx/src/uart_18xx_43xx.c + hw/mcu/nxp/lpc_driver/lpc_chip_18xx/src/chip_18xx_43xx.c \ + hw/mcu/nxp/lpc_driver/lpc_chip_18xx/src/clock_18xx_43xx.c \ + hw/mcu/nxp/lpc_driver/lpc_chip_18xx/src/gpio_18xx_43xx.c \ + hw/mcu/nxp/lpc_driver/lpc_chip_18xx/src/sysinit_18xx_43xx.c \ + hw/mcu/nxp/lpc_driver/lpc_chip_18xx/src/uart_18xx_43xx.c INC += \ - $(TOP)/hw/mcu/nxp/lpcopen/lpc_chip_18xx/inc \ - $(TOP)/hw/mcu/nxp/lpcopen/lpc_chip_18xx/inc/config_18xx + $(TOP)/hw/mcu/nxp/lpc_driver/lpc_chip_18xx/inc \ + $(TOP)/hw/mcu/nxp/lpc_driver/lpc_chip_18xx/inc/config_18xx # For TinyUSB port source VENDOR = nxp diff --git a/hw/bsp/mcb1800/board_mcb1800.c b/hw/bsp/mcb1800/mcb1800.c similarity index 100% rename from hw/bsp/mcb1800/board_mcb1800.c rename to hw/bsp/mcb1800/mcb1800.c diff --git a/hw/bsp/metro_m0_express/board_metro_m0_express.c b/hw/bsp/metro_m0_express/metro_m0_express.c similarity index 100% rename from hw/bsp/metro_m0_express/board_metro_m0_express.c rename to hw/bsp/metro_m0_express/metro_m0_express.c diff --git a/hw/bsp/metro_m4_express/board_metro_m4_express.c b/hw/bsp/metro_m4_express/metro_m4_express.c similarity index 100% rename from hw/bsp/metro_m4_express/board_metro_m4_express.c rename to hw/bsp/metro_m4_express/metro_m4_express.c diff --git a/hw/bsp/pca10056/board.mk b/hw/bsp/pca10056/board.mk index d8f63690f..9dbaea426 100644 --- a/hw/bsp/pca10056/board.mk +++ b/hw/bsp/pca10056/board.mk @@ -21,7 +21,7 @@ SRC_C += \ hw/mcu/nordic/nrfx/mdk/system_nrf52840.c \ INC += \ - $(TOP)/hw/cmsis/Include \ + $(TOP)/hw/mcu/nordic/cmsis/Include \ $(TOP)/hw/mcu/nordic \ $(TOP)/hw/mcu/nordic/nrfx \ $(TOP)/hw/mcu/nordic/nrfx/mdk \ diff --git a/hw/bsp/pca10056/board_pca10056.c b/hw/bsp/pca10056/pca10056.c similarity index 99% rename from hw/bsp/pca10056/board_pca10056.c rename to hw/bsp/pca10056/pca10056.c index 3c67d9426..c50b61db9 100644 --- a/hw/bsp/pca10056/board_pca10056.c +++ b/hw/bsp/pca10056/pca10056.c @@ -65,6 +65,7 @@ void board_init(void) SysTick_Config(SystemCoreClock/1000); #endif +#if TUSB_OPT_DEVICE_ENABLED // Priorities 0, 1, 4 (nRF52) are reserved for SoftDevice // 2 is highest for application NVIC_SetPriority(USBD_IRQn, 2); @@ -101,6 +102,7 @@ void board_init(void) 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); +#endif } //--------------------------------------------------------------------+ diff --git a/hw/bsp/stm32f303disco/board_stm32f303disco.c b/hw/bsp/stm32f303disco/stm32f303disco.c similarity index 100% rename from hw/bsp/stm32f303disco/board_stm32f303disco.c rename to hw/bsp/stm32f303disco/stm32f303disco.c diff --git a/hw/bsp/stm32f407disco/board_stm32f407disco.c b/hw/bsp/stm32f407disco/stm32f407disco.c similarity index 100% rename from hw/bsp/stm32f407disco/board_stm32f407disco.c rename to hw/bsp/stm32f407disco/stm32f407disco.c diff --git a/hw/bsp/stm32f411disco/board_stm32f411disco.c b/hw/bsp/stm32f411disco/stm32f411disco.c similarity index 100% rename from hw/bsp/stm32f411disco/board_stm32f411disco.c rename to hw/bsp/stm32f411disco/stm32f411disco.c diff --git a/hw/cmsis/Include/arm_common_tables.h b/hw/mcu/nordic/cmsis/Include/arm_common_tables.h similarity index 100% rename from hw/cmsis/Include/arm_common_tables.h rename to hw/mcu/nordic/cmsis/Include/arm_common_tables.h diff --git a/hw/cmsis/Include/arm_const_structs.h b/hw/mcu/nordic/cmsis/Include/arm_const_structs.h similarity index 100% rename from hw/cmsis/Include/arm_const_structs.h rename to hw/mcu/nordic/cmsis/Include/arm_const_structs.h diff --git a/hw/cmsis/Include/arm_math.h b/hw/mcu/nordic/cmsis/Include/arm_math.h similarity index 100% rename from hw/cmsis/Include/arm_math.h rename to hw/mcu/nordic/cmsis/Include/arm_math.h diff --git a/hw/cmsis/Include/cmsis_armcc.h b/hw/mcu/nordic/cmsis/Include/cmsis_armcc.h similarity index 100% rename from hw/cmsis/Include/cmsis_armcc.h rename to hw/mcu/nordic/cmsis/Include/cmsis_armcc.h diff --git a/hw/cmsis/Include/cmsis_armcc_V6.h b/hw/mcu/nordic/cmsis/Include/cmsis_armcc_V6.h similarity index 100% rename from hw/cmsis/Include/cmsis_armcc_V6.h rename to hw/mcu/nordic/cmsis/Include/cmsis_armcc_V6.h diff --git a/hw/cmsis/Include/cmsis_gcc.h b/hw/mcu/nordic/cmsis/Include/cmsis_gcc.h similarity index 100% rename from hw/cmsis/Include/cmsis_gcc.h rename to hw/mcu/nordic/cmsis/Include/cmsis_gcc.h diff --git a/hw/cmsis/Include/core_cm0.h b/hw/mcu/nordic/cmsis/Include/core_cm0.h similarity index 100% rename from hw/cmsis/Include/core_cm0.h rename to hw/mcu/nordic/cmsis/Include/core_cm0.h diff --git a/hw/cmsis/Include/core_cm0plus.h b/hw/mcu/nordic/cmsis/Include/core_cm0plus.h similarity index 100% rename from hw/cmsis/Include/core_cm0plus.h rename to hw/mcu/nordic/cmsis/Include/core_cm0plus.h diff --git a/hw/cmsis/Include/core_cm3.h b/hw/mcu/nordic/cmsis/Include/core_cm3.h similarity index 100% rename from hw/cmsis/Include/core_cm3.h rename to hw/mcu/nordic/cmsis/Include/core_cm3.h diff --git a/hw/cmsis/Include/core_cm4.h b/hw/mcu/nordic/cmsis/Include/core_cm4.h similarity index 100% rename from hw/cmsis/Include/core_cm4.h rename to hw/mcu/nordic/cmsis/Include/core_cm4.h diff --git a/hw/cmsis/Include/core_cm7.h b/hw/mcu/nordic/cmsis/Include/core_cm7.h similarity index 100% rename from hw/cmsis/Include/core_cm7.h rename to hw/mcu/nordic/cmsis/Include/core_cm7.h diff --git a/hw/cmsis/Include/core_cmFunc.h b/hw/mcu/nordic/cmsis/Include/core_cmFunc.h similarity index 100% rename from hw/cmsis/Include/core_cmFunc.h rename to hw/mcu/nordic/cmsis/Include/core_cmFunc.h diff --git a/hw/cmsis/Include/core_cmInstr.h b/hw/mcu/nordic/cmsis/Include/core_cmInstr.h similarity index 100% rename from hw/cmsis/Include/core_cmInstr.h rename to hw/mcu/nordic/cmsis/Include/core_cmInstr.h diff --git a/hw/cmsis/Include/core_cmSimd.h b/hw/mcu/nordic/cmsis/Include/core_cmSimd.h similarity index 100% rename from hw/cmsis/Include/core_cmSimd.h rename to hw/mcu/nordic/cmsis/Include/core_cmSimd.h diff --git a/hw/cmsis/Include/core_sc000.h b/hw/mcu/nordic/cmsis/Include/core_sc000.h similarity index 100% rename from hw/cmsis/Include/core_sc000.h rename to hw/mcu/nordic/cmsis/Include/core_sc000.h diff --git a/hw/cmsis/Include/core_sc300.h b/hw/mcu/nordic/cmsis/Include/core_sc300.h similarity index 100% rename from hw/cmsis/Include/core_sc300.h rename to hw/mcu/nordic/cmsis/Include/core_sc300.h diff --git a/hw/mcu/nxp/lpc_driver b/hw/mcu/nxp/lpc_driver new file mode 160000 index 000000000..dee2dad8e --- /dev/null +++ b/hw/mcu/nxp/lpc_driver @@ -0,0 +1 @@ +Subproject commit dee2dad8e9246afdad7c6ed0e331b2f79f21fb8a diff --git a/hw/mcu/nxp/lpcopen b/hw/mcu/nxp/lpcopen deleted file mode 160000 index 06b4c2e50..000000000 --- a/hw/mcu/nxp/lpcopen +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 06b4c2e509147924b66ace90f6be5ebe599af45c diff --git a/src/class/vendor/vendor_device.c b/src/class/vendor/vendor_device.c index d1ba63a9d..a00257476 100644 --- a/src/class/vendor/vendor_device.c +++ b/src/class/vendor/vendor_device.c @@ -125,6 +125,11 @@ uint32_t tud_vendor_n_write (uint8_t itf, void const* buffer, uint32_t bufsize) return ret; } +uint32_t tud_vendor_n_write_available (uint8_t itf) +{ + return tu_fifo_remaining(&_vendord_itf[itf].tx_ff); +} + //--------------------------------------------------------------------+ // USBD Driver API //--------------------------------------------------------------------+ diff --git a/src/class/vendor/vendor_device.h b/src/class/vendor/vendor_device.h index 17fbc54ef..30fe94c3a 100644 --- a/src/class/vendor/vendor_device.h +++ b/src/class/vendor/vendor_device.h @@ -41,24 +41,28 @@ //--------------------------------------------------------------------+ // Application API (Multiple Interfaces) //--------------------------------------------------------------------+ -bool tud_vendor_n_mounted (uint8_t itf); -uint32_t tud_vendor_n_available (uint8_t itf); -uint32_t tud_vendor_n_read (uint8_t itf, void* buffer, uint32_t bufsize); -bool tud_vendor_n_peek (uint8_t itf, int pos, uint8_t* u8); -uint32_t tud_vendor_n_write (uint8_t itf, void const* buffer, uint32_t bufsize); +bool tud_vendor_n_mounted (uint8_t itf); + +uint32_t tud_vendor_n_available (uint8_t itf); +uint32_t tud_vendor_n_read (uint8_t itf, void* buffer, uint32_t bufsize); +bool tud_vendor_n_peek (uint8_t itf, int pos, uint8_t* u8); + +uint32_t tud_vendor_n_write (uint8_t itf, void const* buffer, uint32_t bufsize); +uint32_t tud_vendor_n_write_available (uint8_t itf); static inline -uint32_t tud_vendor_n_write_str (uint8_t itf, char const* str); +uint32_t tud_vendor_n_write_str (uint8_t itf, char const* str); //--------------------------------------------------------------------+ // Application API (Single Port) //--------------------------------------------------------------------+ -static inline bool tud_vendor_mounted (void); -static inline uint32_t tud_vendor_available (void); -static inline uint32_t tud_vendor_read (void* buffer, uint32_t bufsize); -static inline bool tud_vendor_peek (int pos, uint8_t* u8); -static inline uint32_t tud_vendor_write (void const* buffer, uint32_t bufsize); -static inline uint32_t tud_vendor_write_str (char const* str); +static inline bool tud_vendor_mounted (void); +static inline uint32_t tud_vendor_available (void); +static inline uint32_t tud_vendor_read (void* buffer, uint32_t bufsize); +static inline bool tud_vendor_peek (int pos, uint8_t* u8); +static inline uint32_t tud_vendor_write (void const* buffer, uint32_t bufsize); +static inline uint32_t tud_vendor_write_str (char const* str); +static inline uint32_t tud_vendor_write_available (void); //--------------------------------------------------------------------+ // Application Callback API (weak is optional) @@ -106,6 +110,11 @@ static inline uint32_t tud_vendor_write_str (char const* str) return tud_vendor_n_write_str(0, str); } +static inline uint32_t tud_vendor_write_available (void) +{ + return tud_vendor_n_write_available(0); +} + //--------------------------------------------------------------------+ // Internal Class Driver API //--------------------------------------------------------------------+ diff --git a/src/common/tusb_common.h b/src/common/tusb_common.h index ee77b62f1..4352505eb 100644 --- a/src/common/tusb_common.h +++ b/src/common/tusb_common.h @@ -106,6 +106,11 @@ static inline uint16_t tu_max16 (uint16_t x, uint16_t y) { return (x > y) ? x : static inline uint32_t tu_max32 (uint32_t x, uint32_t y) { return (x > y) ? x : y; } // Align +static inline uint32_t tu_align_n(uint32_t value, uint32_t alignment) +{ + return value & ((uint32_t) ~(alignment-1)); +} + static inline uint32_t tu_align32 (uint32_t value) { return (value & 0xFFFFFFE0UL); } static inline uint32_t tu_align16 (uint32_t value) { return (value & 0xFFFFFFF0UL); } static inline uint32_t tu_align4k (uint32_t value) { return (value & 0xFFFFF000UL); } diff --git a/src/device/usbd.h b/src/device/usbd.h index 396964e00..5f96e55a4 100644 --- a/src/device/usbd.h +++ b/src/device/usbd.h @@ -169,15 +169,15 @@ TU_ATTR_WEAK bool tud_vendor_control_complete_cb(uint8_t rhport, tusb_control_re /* CDC Header */\ 5, TUSB_DESC_CS_INTERFACE, CDC_FUNC_DESC_HEADER, U16_TO_U8S_LE(0x0120),\ /* CDC Call */\ - 5, TUSB_DESC_CS_INTERFACE, CDC_FUNC_DESC_CALL_MANAGEMENT, 0, (_itfnum) + 1,\ + 5, TUSB_DESC_CS_INTERFACE, CDC_FUNC_DESC_CALL_MANAGEMENT, 0, (uint8_t)((_itfnum) + 1),\ /* CDC ACM: support line request */\ 4, TUSB_DESC_CS_INTERFACE, CDC_FUNC_DESC_ABSTRACT_CONTROL_MANAGEMENT, 2,\ /* CDC Union */\ - 5, TUSB_DESC_CS_INTERFACE, CDC_FUNC_DESC_UNION, _itfnum, (_itfnum) + 1,\ + 5, TUSB_DESC_CS_INTERFACE, CDC_FUNC_DESC_UNION, _itfnum, (uint8_t)((_itfnum) + 1),\ /* Endpoint Notification */\ 7, TUSB_DESC_ENDPOINT, _ep_notif, TUSB_XFER_INTERRUPT, U16_TO_U8S_LE(_ep_notif_size), 16,\ /* CDC Data Interface */\ - 9, TUSB_DESC_INTERFACE, (_itfnum)+1, 0, 2, TUSB_CLASS_CDC_DATA, 0, 0, 0,\ + 9, TUSB_DESC_INTERFACE, (uint8_t)((_itfnum)+1), 0, 2, TUSB_CLASS_CDC_DATA, 0, 0, 0,\ /* Endpoint Out */\ 7, TUSB_DESC_ENDPOINT, _epout, TUSB_XFER_BULK, U16_TO_U8S_LE(_epsize), 0,\ /* Endpoint In */\ @@ -239,9 +239,9 @@ TU_ATTR_WEAK bool tud_vendor_control_complete_cb(uint8_t rhport, tusb_control_re /* Audio Control (AC) Interface */\ 9, TUSB_DESC_INTERFACE, _itfnum, 0, 0, TUSB_CLASS_AUDIO, AUDIO_SUBCLASS_CONTROL, AUDIO_PROTOCOL_V1, _stridx,\ /* AC Header */\ - 9, TUSB_DESC_CS_INTERFACE, AUDIO_CS_INTERFACE_HEADER, U16_TO_U8S_LE(0x0100), U16_TO_U8S_LE(0x0009), 1, _itfnum+1,\ + 9, TUSB_DESC_CS_INTERFACE, AUDIO_CS_INTERFACE_HEADER, U16_TO_U8S_LE(0x0100), U16_TO_U8S_LE(0x0009), 1, (uint8_t)((_itfnum)+1),\ /* MIDI Streaming (MS) Interface */\ - 9, TUSB_DESC_INTERFACE, _itfnum+1, 0, 2, TUSB_CLASS_AUDIO, AUDIO_SUBCLASS_MIDI_STREAMING, AUDIO_PROTOCOL_V1, 0,\ + 9, TUSB_DESC_INTERFACE, (uint8_t)((_itfnum)+1), 0, 2, TUSB_CLASS_AUDIO, AUDIO_SUBCLASS_MIDI_STREAMING, AUDIO_PROTOCOL_V1, 0,\ /* MS Header */\ 7, TUSB_DESC_CS_INTERFACE, MIDI_CS_INTERFACE_HEADER, U16_TO_U8S_LE(0x0100), U16_TO_U8S_LE(0x0025),\ /* MS In Jack (Embedded) */\ diff --git a/src/portable/nxp/lpc11_13_15/dcd_lpc11_13_15.c b/src/portable/nxp/lpc_usbd/dcd_lpc_usbd.c similarity index 80% rename from src/portable/nxp/lpc11_13_15/dcd_lpc11_13_15.c rename to src/portable/nxp/lpc_usbd/dcd_lpc_usbd.c index 39c365d87..ec3177c4b 100644 --- a/src/portable/nxp/lpc11_13_15/dcd_lpc11_13_15.c +++ b/src/portable/nxp/lpc_usbd/dcd_lpc_usbd.c @@ -26,9 +26,31 @@ #include "tusb_option.h" -#if TUSB_OPT_DEVICE_ENABLED && (CFG_TUSB_MCU == OPT_MCU_LPC11UXX || CFG_TUSB_MCU == OPT_MCU_LPC13XX) +/* Since 2012 starting with LPC11uxx, NXP start to use common USB Device Controller + * for almost their new MCUs. Currently supported and tested families are + * - LPC11Uxx + * - LPC13xx + * - LPC51Uxx + * + * For similar controller of other families, this file may require some minimal changes to work with. + * Previous MCUs such as LPC17xx, LPC40xx, LPC18xx, LPC43xx have their own driver implementation. + */ + +#if TUSB_OPT_DEVICE_ENABLED && ( CFG_TUSB_MCU == OPT_MCU_LPC11UXX || \ + CFG_TUSB_MCU == OPT_MCU_LPC13XX || \ + CFG_TUSB_MCU == OPT_MCU_LPC51UXX ) + +#if CFG_TUSB_MCU == OPT_MCU_LPC11UXX || CFG_TUSB_MCU == OPT_MCU_LPC13XX + // LPC11Uxx and LPC13xx use lpcopen + #include "chip.h" + #define DCD_REGS LPC_USB + #define DCD_IRQHandler USB_IRQHandler +#elif CFG_TUSB_MCU == OPT_MCU_LPC51UXX + #include "fsl_device_registers.h" + #define DCD_REGS USB0 + #define DCD_IRQHandler USB0_IRQHandler +#endif -#include "chip.h" #include "device/dcd.h" //--------------------------------------------------------------------+ @@ -39,15 +61,19 @@ #define EP_COUNT 10 // only SRAM1 & USB RAM can be used for transfer +// 2000 0000 to 203F FFFF #define SRAM_REGION 0x20000000 /* Although device controller are the same. DMA of - * - LPC11u can only transfer up to nbytes = 64 - * - LPC13 can transfer nbytes = 1023 (maximum) - * - LPC15 can ??? + * - M0/M+ can only transfer up to nbytes = 64 + * - M3/M4 can transfer nbytes = 1023 (maximum) */ enum { - DMA_NBYTES_MAX = (CFG_TUSB_MCU == OPT_MCU_LPC11UXX ? 64 : 1023) + #ifdef __ARM_ARCH_6M__ // Cortex M0/M0+ + DMA_NBYTES_MAX = 64 + #else + DMA_NBYTES_MAX = 1023 + #endif }; enum { @@ -130,12 +156,12 @@ void dcd_init(uint8_t rhport) { (void) rhport; - LPC_USB->EPLISTSTART = (uint32_t) _dcd.ep; - LPC_USB->DATABUFSTART = SRAM_REGION; + DCD_REGS->EPLISTSTART = (uint32_t) _dcd.ep; + DCD_REGS->DATABUFSTART = SRAM_REGION; // 22-bit alignment - LPC_USB->INTSTAT = LPC_USB->INTSTAT; // clear all pending interrupt - LPC_USB->INTEN = INT_DEVICE_STATUS_MASK; - LPC_USB->DEVCMDSTAT |= CMDSTAT_DEVICE_ENABLE_MASK | CMDSTAT_DEVICE_CONNECT_MASK | + DCD_REGS->INTSTAT = DCD_REGS->INTSTAT; // clear all pending interrupt + DCD_REGS->INTEN = INT_DEVICE_STATUS_MASK; + DCD_REGS->DEVCMDSTAT |= CMDSTAT_DEVICE_ENABLE_MASK | CMDSTAT_DEVICE_CONNECT_MASK | CMDSTAT_RESET_CHANGE_MASK | CMDSTAT_CONNECT_CHANGE_MASK | CMDSTAT_SUSPEND_CHANGE_MASK; NVIC_ClearPendingIRQ(USB0_IRQn); @@ -158,8 +184,8 @@ void dcd_set_address(uint8_t rhport, uint8_t dev_addr) // Response with status first before changing device address dcd_edpt_xfer(rhport, tu_edpt_addr(0, TUSB_DIR_IN), NULL, 0); - LPC_USB->DEVCMDSTAT &= ~CMDSTAT_DEVICE_ADDR_MASK; - LPC_USB->DEVCMDSTAT |= dev_addr; + DCD_REGS->DEVCMDSTAT &= ~CMDSTAT_DEVICE_ADDR_MASK; + DCD_REGS->DEVCMDSTAT |= dev_addr; } void dcd_set_config(uint8_t rhport, uint8_t config_num) @@ -213,7 +239,7 @@ bool dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc) _dcd.ep[ep_id][0].is_iso = (p_endpoint_desc->bmAttributes.xfer == TUSB_XFER_ISOCHRONOUS); // Enable EP interrupt - LPC_USB->INTEN |= TU_BIT(ep_id); + DCD_REGS->INTEN |= TU_BIT(ep_id); return true; } @@ -258,13 +284,13 @@ static void bus_reset(void) _dcd.ep[0][1].buffer_offset = get_buf_offset(_dcd.setup_packet); - LPC_USB->EPINUSE = 0; - LPC_USB->EPBUFCFG = 0; - LPC_USB->EPSKIP = 0xFFFFFFFF; + DCD_REGS->EPINUSE = 0; + DCD_REGS->EPBUFCFG = 0; + DCD_REGS->EPSKIP = 0xFFFFFFFF; - LPC_USB->INTSTAT = LPC_USB->INTSTAT; // clear all pending interrupt - LPC_USB->DEVCMDSTAT |= CMDSTAT_SETUP_RECEIVED_MASK; // clear setup received interrupt - LPC_USB->INTEN = INT_DEVICE_STATUS_MASK | TU_BIT(0) | TU_BIT(1); // enable device status & control endpoints + DCD_REGS->INTSTAT = DCD_REGS->INTSTAT; // clear all pending interrupt + DCD_REGS->DEVCMDSTAT |= CMDSTAT_SETUP_RECEIVED_MASK; // clear setup received interrupt + DCD_REGS->INTEN = INT_DEVICE_STATUS_MASK | TU_BIT(0) | TU_BIT(1); // enable device status & control endpoints } static void process_xfer_isr(uint32_t int_status) @@ -297,19 +323,19 @@ static void process_xfer_isr(uint32_t int_status) } } -void USB_IRQHandler(void) +void DCD_IRQHandler(void) { - uint32_t const dev_cmd_stat = LPC_USB->DEVCMDSTAT; + uint32_t const dev_cmd_stat = DCD_REGS->DEVCMDSTAT; - uint32_t int_status = LPC_USB->INTSTAT & LPC_USB->INTEN; - LPC_USB->INTSTAT = int_status; // Acknowledge handled interrupt + uint32_t int_status = DCD_REGS->INTSTAT & DCD_REGS->INTEN; + DCD_REGS->INTSTAT = int_status; // Acknowledge handled interrupt if (int_status == 0) return; //------------- Device Status -------------// if ( int_status & INT_DEVICE_STATUS_MASK ) { - LPC_USB->DEVCMDSTAT |= CMDSTAT_RESET_CHANGE_MASK | CMDSTAT_CONNECT_CHANGE_MASK | CMDSTAT_SUSPEND_CHANGE_MASK; + DCD_REGS->DEVCMDSTAT |= CMDSTAT_RESET_CHANGE_MASK | CMDSTAT_CONNECT_CHANGE_MASK | CMDSTAT_SUSPEND_CHANGE_MASK; if ( dev_cmd_stat & CMDSTAT_RESET_CHANGE_MASK) // bus reset { bus_reset(); @@ -352,7 +378,7 @@ void USB_IRQHandler(void) _dcd.ep[0][0].active = _dcd.ep[1][0].active = 0; _dcd.ep[0][0].stall = _dcd.ep[1][0].stall = 0; - LPC_USB->DEVCMDSTAT |= CMDSTAT_SETUP_RECEIVED_MASK; + DCD_REGS->DEVCMDSTAT |= CMDSTAT_SETUP_RECEIVED_MASK; dcd_event_setup_received(0, _dcd.setup_packet, true); diff --git a/src/tusb_option.h b/src/tusb_option.h index a273d59b3..bf1fac6ea 100644 --- a/src/tusb_option.h +++ b/src/tusb_option.h @@ -42,6 +42,7 @@ #define OPT_MCU_LPC18XX 6 ///< NXP LPC18xx #define OPT_MCU_LPC40XX 7 ///< NXP LPC40xx #define OPT_MCU_LPC43XX 8 ///< NXP LPC43xx +#define OPT_MCU_LPC51UXX 9 ///< NXP LPC51U6x #define OPT_MCU_NRF5X 100 ///< Nordic nRF5x series diff --git a/tools/build_all.py b/tools/build_all.py index 9efd79fe2..9c379d0dc 100644 --- a/tools/build_all.py +++ b/tools/build_all.py @@ -51,7 +51,7 @@ for example in all_examples: if build_result.returncode != 0: exit_status = build_result.returncode - success = "\033[31mfailed\033[0m" + success = "\033[31mfailed\033[0m " fail_count += 1 else: success = "\033[32msucceeded\033[0m"