From f183d0810bb4570bf569cb08a6644933b8813dff Mon Sep 17 00:00:00 2001 From: kkitayam <45088311+kkitayam@users.noreply.github.com> Date: Sat, 23 Oct 2021 15:14:28 +0900 Subject: Add files for msp432e4 --- src/device/dcd_attr.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/device') diff --git a/src/device/dcd_attr.h b/src/device/dcd_attr.h index 15d8ce204..1befa89b6 100644 --- a/src/device/dcd_attr.h +++ b/src/device/dcd_attr.h @@ -143,7 +143,7 @@ #define DCD_ATTR_ENDPOINT_EXCLUSIVE_NUMBER //------------- TI -------------// -#elif TU_CHECK_MCU(OPT_MCU_MSP430x5xx) +#elif TU_CHECK_MCU(OPT_MCU_MSP430x5xx, OPT_MCU_MSP432E4xx) #define DCD_ATTR_ENDPOINT_MAX 8 //------------- ValentyUSB -------------// -- cgit v1.3.1 From 6fea50f735d00dff23d958eec8cf4a386282c193 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 8 Nov 2021 16:41:08 +0700 Subject: musb work well with tm4c123 --- hw/bsp/ek-tm4c123gxl/board.mk | 1 + hw/bsp/ek-tm4c123gxl/tm4c123gxl.c | 173 +++++++++++++++++--------------- src/device/dcd_attr.h | 5 +- src/portable/mentor/musb/dcd_musb.c | 18 +++- src/portable/mentor/musb/musb_msp432e.h | 40 ++++++++ src/portable/mentor/musb/musb_tm4c.h | 45 +++++++++ src/tusb_option.h | 3 +- 7 files changed, 201 insertions(+), 84 deletions(-) create mode 100644 src/portable/mentor/musb/musb_msp432e.h create mode 100644 src/portable/mentor/musb/musb_tm4c.h (limited to 'src/device') diff --git a/hw/bsp/ek-tm4c123gxl/board.mk b/hw/bsp/ek-tm4c123gxl/board.mk index 368e79f4e..9d0d67e1c 100644 --- a/hw/bsp/ek-tm4c123gxl/board.mk +++ b/hw/bsp/ek-tm4c123gxl/board.mk @@ -25,6 +25,7 @@ INC += \ $(TOP)/hw/bsp SRC_C += \ + src/portable/mentor/musb/dcd_musb.c \ $(MCU_DIR)/Source/system_TM4C123.c \ $(MCU_DIR)/Source/GCC/tm4c123_startup.c diff --git a/hw/bsp/ek-tm4c123gxl/tm4c123gxl.c b/hw/bsp/ek-tm4c123gxl/tm4c123gxl.c index b370b7577..663fbf127 100644 --- a/hw/bsp/ek-tm4c123gxl/tm4c123gxl.c +++ b/hw/bsp/ek-tm4c123gxl/tm4c123gxl.c @@ -15,143 +15,156 @@ #define LED_PIN_GREEN 3 #define LED_STATE_ON 1 -static void board_uart_init(void) +//--------------------------------------------------------------------+ +// Forward USB interrupt events to TinyUSB IRQ Handler +//--------------------------------------------------------------------+ +void USB0_Handler(void) { - SYSCTL->RCGCUART |= (1<<0); // Enable the clock to UART0 - SYSCTL->RCGCGPIO |= (1<<0); // Enable the clock to GPIOA + tud_int_handler(0); +} + +//--------------------------------------------------------------------+ +// MACRO TYPEDEF CONSTANT ENUM +//--------------------------------------------------------------------+ - GPIOA->AFSEL |= (1<<1)|(1<<0); // Enable the alternate function on pin PA0 & PA1 - GPIOA->PCTL |= (1<<0)|(1<<4); // Configure the GPIOPCTL register to select UART0 in PA0 and PA1 - GPIOA->DEN |= (1<<0)|(1<<1); // Enable the digital functionality in PA0 and PA1 +static void board_uart_init (void) +{ + SYSCTL->RCGCUART |= (1 << 0); // Enable the clock to UART0 + SYSCTL->RCGCGPIO |= (1 << 0); // Enable the clock to GPIOA - /** BAUDRATE = 9600 bits per second, refer manual for calculation **/ + GPIOA->AFSEL |= (1 << 1) | (1 << 0); // Enable the alternate function on pin PA0 & PA1 + GPIOA->PCTL |= (1 << 0) | (1 << 4); // Configure the GPIOPCTL register to select UART0 in PA0 and PA1 + GPIOA->DEN |= (1 << 0) | (1 << 1); // Enable the digital functionality in PA0 and PA1 - UART0->CTL &= ~(1<<0); // Disable UART0 by clearing UARTEN bit in the UARTCTL register - UART0->IBRD = 325; // Write the integer portion of the BRD to the UARTIRD register - UART0->FBRD = 33; // Write the fractional portion of the BRD to the UARTFBRD registerer + /** BAUDRATE = 9600 bits per second, refer manual for calculation **/ + UART0->CTL &= ~(1 << 0); // Disable UART0 by clearing UARTEN bit in the UARTCTL register + UART0->IBRD = 325; // Write the integer portion of the BRD to the UARTIRD register + UART0->FBRD = 33; // Write the fractional portion of the BRD to the UARTFBRD registerer - UART0->LCRH = (0x3<<5); // 8-bit, no parity, 1 stop bit - UART0->CC = 0x0; // Configure the UART clock source as system clock + UART0->LCRH = (0x3 << 5); // 8-bit, no parity, 1 stop bit + UART0->CC = 0x0; // Configure the UART clock source as system clock - UART0->CTL = (1<<0)|(1<<8)|(1<<9); // UART0 Enable, Transmit Enable, Recieve Enable + UART0->CTL = (1 << 0) | (1 << 8) | (1 << 9); // UART0 Enable, Transmit Enable, Recieve Enable } -static void initialize_board_led(GPIOA_Type* port, uint8_t PinMsk, uint8_t dirmsk) +static void initialize_board_led (GPIOA_Type *port, uint8_t PinMsk, uint8_t dirmsk) { - /* Enable PortF Clock */ - SYSCTL -> RCGCGPIO |= (1<<5) ; + /* Enable PortF Clock */ + SYSCTL->RCGCGPIO |= (1 << 5); - /* Let the clock stabilize */ - while(! ((SYSCTL->PRGPIO) & (1<<5)) ) ; + /* Let the clock stabilize */ + while ( !((SYSCTL->PRGPIO) & (1 << 5)) ) + ; - /* Port Digital Enable */ - port->DEN |= PinMsk; + /* Port Digital Enable */ + port->DEN |= PinMsk; - /* Set direction */ - port->DIR = dirmsk ; + /* Set direction */ + port->DIR = dirmsk; } -static void board_switch_init(void) +static void board_switch_init (void) { - GPIOF->DIR &= ~(1<PUR |= (1<DEN |= (1<DIR &= ~(1 << BOARD_BTN); + GPIOF->PUR |= (1 << BOARD_BTN); + GPIOF->DEN |= (1 << BOARD_BTN); } -static void WriteGPIOPin(GPIOA_Type* port, uint8_t PinMsk, bool state) +static void WriteGPIOPin (GPIOA_Type *port, uint8_t PinMsk, bool state) { - if(state) - port->DATA |= PinMsk; - else - port->DATA &= ~(PinMsk); + if ( state ) + port->DATA |= PinMsk; + else + port->DATA &= ~(PinMsk); } -static uint32_t ReadGPIOPin(GPIOA_Type *port, uint8_t pinMsk) +static uint32_t ReadGPIOPin (GPIOA_Type *port, uint8_t pinMsk) { - return (port -> DATA & pinMsk) ; + return (port->DATA & pinMsk); } -void board_init(void) +void board_init (void) { - SystemCoreClockUpdate(); - + SystemCoreClockUpdate(); + #if CFG_TUSB_OS == OPT_OS_NONE - // 1ms tick timer - SysTick_Config(SystemCoreClock / 1000); + // 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 - /* Reset USB */ - SYSCTL->SRCR2 |= (1u<<16); + /* Reset USB */ + SYSCTL->SRCR2 |= (1u << 16); + + for ( volatile uint8_t i = 0; i < 20; i++ ) {} - for (volatile uint8_t i=0; i<20; i++); + SYSCTL->SRCR2 &= ~(1u << 16); - SYSCTL->SRCR2 &= ~(1u<<16); + /* Open the USB clock gate */ + SYSCTL->RCGCUSB |= (1 << 0); - /* Open the USB clock gate */ - SYSCTL->RCGCUSB |= (1<<0); + /* Power-up USB PLL */ + SYSCTL->RCC2 &= ~(1u << 14); - /* Power-up USB PLL */ - SYSCTL->RCC2 &= ~(1u<<14); + /* USB IO Initialization */ + SYSCTL->RCGCGPIO |= (1u << 3); - /* USB IO Initialization */ - SYSCTL->RCGCGPIO |= (1u<<3); - - /* Let the clock stabilize */ - while(!(SYSCTL->PRGPIO & (1u<<3))); + /* Let the clock stabilize */ + while ( !(SYSCTL->PRGPIO & (1u << 3)) ) + ; - /* USB IOs to Analog Mode */ - GPIOD->AFSEL &= ~ ( (1u<<4) | (1u<<5) ); - GPIOD->DEN &= ~ ( (1u<<4) | (1u<<5) ); - GPIOD->AMSEL |= ( (1u<<4) | (1u<<5) ); + /* USB IOs to Analog Mode */ + GPIOD->AFSEL &= ~((1u << 4) | (1u << 5)); + GPIOD->DEN &= ~((1u << 4) | (1u << 5)); + GPIOD->AMSEL |= ((1u << 4) | (1u << 5)); - uint8_t leds = (1<FR &(1<<5)) != 0); // Poll until previous data was shofted out - UART0->DR= data[i]; // Write UART0 DATA REGISTER - } + for ( int i = 0; i < len; i++ ) + { + while ( (UART0->FR & (1 << 5)) != 0 ) {} // Poll until previous data was shofted out + UART0->DR = data[i]; // Write UART0 DATA REGISTER + } - return len; + return len; } -int board_uart_read(uint8_t* buf, int len) +int board_uart_read (uint8_t *buf, int len) { - (void) buf; (void) len; + (void) buf; + (void) len; return 0; } - #if CFG_TUSB_OS == OPT_OS_NONE volatile uint32_t system_ticks = 0; void SysTick_Handler (void) @@ -159,7 +172,7 @@ void SysTick_Handler (void) system_ticks++; } -uint32_t board_millis(void) +uint32_t board_millis (void) { return system_ticks; } diff --git a/src/device/dcd_attr.h b/src/device/dcd_attr.h index 1befa89b6..7254f3362 100644 --- a/src/device/dcd_attr.h +++ b/src/device/dcd_attr.h @@ -143,7 +143,10 @@ #define DCD_ATTR_ENDPOINT_EXCLUSIVE_NUMBER //------------- TI -------------// -#elif TU_CHECK_MCU(OPT_MCU_MSP430x5xx, OPT_MCU_MSP432E4xx) +#elif TU_CHECK_MCU(OPT_MCU_MSP430x5xx) + #define DCD_ATTR_ENDPOINT_MAX 8 + +#elif TU_CHECK_MCU(OPT_MCU_MSP432E4xx, OPT_MCU_TM4C123, OPT_MCU_TM4C129) #define DCD_ATTR_ENDPOINT_MAX 8 //------------- ValentyUSB -------------// diff --git a/src/portable/mentor/musb/dcd_musb.c b/src/portable/mentor/musb/dcd_musb.c index 04139dd78..c745b4969 100644 --- a/src/portable/mentor/musb/dcd_musb.c +++ b/src/portable/mentor/musb/dcd_musb.c @@ -26,7 +26,7 @@ #include "tusb_option.h" -#if CFG_TUSB_MCU == OPT_MCU_MSP432E4xx +#if TU_CHECK_MCU(OPT_MCU_MSP432E4xx, OPT_MCU_TM4C123, OPT_MCU_TM4C129) #if __GNUC__ > 8 && defined(__ARM_FEATURE_UNALIGNED) /* GCC warns that an address may be unaligned, even though @@ -35,7 +35,21 @@ _Pragma("GCC diagnostic ignored \"-Waddress-of-packed-member\""); #endif #include "device/dcd.h" -#include "msp.h" + +#if TU_CHECK_MCU(OPT_MCU_MSP432E4xx) + #include "musb_msp432e.h" + +#elif TU_CHECK_MCU(OPT_MCU_TM4C123, OPT_MCU_TM4C129) + #include "musb_tm4c.h" + + // HACK generalize later + #include "musb_type.h" + #define FIFO0_WORD FIFO0 + #define FIFO1_WORD FIFO1 + +#else + #error "Unsupported MCUs" +#endif /*------------------------------------------------------------------ * MACRO TYPEDEF CONSTANT ENUM DECLARATION diff --git a/src/portable/mentor/musb/musb_msp432e.h b/src/portable/mentor/musb/musb_msp432e.h new file mode 100644 index 000000000..fce21de88 --- /dev/null +++ b/src/portable/mentor/musb/musb_msp432e.h @@ -0,0 +1,40 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2021, Ha Thach (tinyusb.org) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * This file is part of the TinyUSB stack. + */ + +#ifndef _TUSB_MUSB_MSP432E_H_ +#define _TUSB_MUSB_MSP432E_H_ + +#ifdef __cplusplus + extern "C" { +#endif + +#include "msp.h" + +#ifdef __cplusplus + } +#endif + +#endif diff --git a/src/portable/mentor/musb/musb_tm4c.h b/src/portable/mentor/musb/musb_tm4c.h new file mode 100644 index 000000000..65a1751b0 --- /dev/null +++ b/src/portable/mentor/musb/musb_tm4c.h @@ -0,0 +1,45 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2021, Ha Thach (tinyusb.org) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * This file is part of the TinyUSB stack. + */ + +#ifndef _TUSB_MUSB_TM4C_H_ +#define _TUSB_MUSB_TM4C_H_ + +#ifdef __cplusplus + extern "C" { +#endif + +#if CFG_TUSB_MCU == OPT_MCU_TM4C123 + #include "TM4C123.h" +//#elif CFG_TUSB_MCU == OPT_MCU_TM4C129 +#else + #error "Unsupported MCUs" +#endif + +#ifdef __cplusplus + } +#endif + +#endif diff --git a/src/tusb_option.h b/src/tusb_option.h index 50a922840..246893ddb 100644 --- a/src/tusb_option.h +++ b/src/tusb_option.h @@ -87,7 +87,8 @@ // TI MSP430 #define OPT_MCU_MSP430x5xx 500 ///< TI MSP430x5xx #define OPT_MCU_MSP432E4xx 510 ///< TI MSP432E4xx -#define OPT_MCU_TM4C123 511 ///< TI Tiva C 123x +#define OPT_MCU_TM4C123 511 ///< TI Tiva-C 123x +#define OPT_MCU_TM4C129 512 ///< TI Tiva-C 129x // ValentyUSB eptri #define OPT_MCU_VALENTYUSB_EPTRI 600 ///< Fomu eptri config -- cgit v1.3.1 From f65917f51a3046c828ced5fbb982348542b382a5 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 8 Nov 2021 17:24:58 +0700 Subject: rename to simply OPT_MCU_MSP432E4, add msp432e to ci --- .github/workflows/build_arm.yml | 1 + hw/bsp/board_mcu.h | 2 +- hw/bsp/msp432e4/family.mk | 2 +- src/class/audio/audio_device.c | 2 +- src/device/dcd_attr.h | 2 +- src/portable/mentor/musb/dcd_musb.c | 4 ++-- src/tusb_option.h | 4 ++-- 7 files changed, 9 insertions(+), 8 deletions(-) (limited to 'src/device') diff --git a/.github/workflows/build_arm.yml b/.github/workflows/build_arm.yml index 8db0fe04f..cf9246d52 100644 --- a/.github/workflows/build_arm.yml +++ b/.github/workflows/build_arm.yml @@ -45,6 +45,7 @@ jobs: - 'lpc54' - 'lpc55' - 'mm32' + - 'msp430e4' - 'nrf' - 'rp2040' - 'samd11' diff --git a/hw/bsp/board_mcu.h b/hw/bsp/board_mcu.h index 2928ea657..f8b5c061c 100644 --- a/hw/bsp/board_mcu.h +++ b/hw/bsp/board_mcu.h @@ -98,7 +98,7 @@ #elif CFG_TUSB_MCU == OPT_MCU_MSP430x5xx #include "msp430.h" -#elif CFG_TUSB_MCU == OPT_MCU_MSP432E4xx +#elif CFG_TUSB_MCU == OPT_MCU_MSP432E4 #include "msp.h" #elif CFG_TUSB_MCU == OPT_MCU_VALENTYUSB_EPTRI diff --git a/hw/bsp/msp432e4/family.mk b/hw/bsp/msp432e4/family.mk index ee7faa208..b664c4c1b 100644 --- a/hw/bsp/msp432e4/family.mk +++ b/hw/bsp/msp432e4/family.mk @@ -9,7 +9,7 @@ CFLAGS += \ -mfloat-abi=hard \ -mfpu=fpv4-sp-d16 \ -D__MSP432E401Y__ \ - -DCFG_TUSB_MCU=OPT_MCU_MSP432E4xx + -DCFG_TUSB_MCU=OPT_MCU_MSP432E4 # mcu driver cause following warnings CFLAGS += -Wno-error=cast-qual -Wno-error=format= diff --git a/src/class/audio/audio_device.c b/src/class/audio/audio_device.c index 38bfc023b..d9f2e284e 100644 --- a/src/class/audio/audio_device.c +++ b/src/class/audio/audio_device.c @@ -103,7 +103,7 @@ CFG_TUSB_MCU == OPT_MCU_LPC18XX || \ CFG_TUSB_MCU == OPT_MCU_LPC43XX || \ CFG_TUSB_MCU == OPT_MCU_MIMXRT10XX || \ - CFG_TUSB_MCU == OPT_MCU_MSP432E4xx + CFG_TUSB_MCU == OPT_MCU_MSP432E4 #if TUD_AUDIO_PREFER_RING_BUFFER #define USE_LINEAR_BUFFER 0 #else diff --git a/src/device/dcd_attr.h b/src/device/dcd_attr.h index 7254f3362..73d592e5c 100644 --- a/src/device/dcd_attr.h +++ b/src/device/dcd_attr.h @@ -146,7 +146,7 @@ #elif TU_CHECK_MCU(OPT_MCU_MSP430x5xx) #define DCD_ATTR_ENDPOINT_MAX 8 -#elif TU_CHECK_MCU(OPT_MCU_MSP432E4xx, OPT_MCU_TM4C123, OPT_MCU_TM4C129) +#elif TU_CHECK_MCU(OPT_MCU_MSP432E4, OPT_MCU_TM4C123, OPT_MCU_TM4C129) #define DCD_ATTR_ENDPOINT_MAX 8 //------------- ValentyUSB -------------// diff --git a/src/portable/mentor/musb/dcd_musb.c b/src/portable/mentor/musb/dcd_musb.c index c745b4969..4b4c2f9b2 100644 --- a/src/portable/mentor/musb/dcd_musb.c +++ b/src/portable/mentor/musb/dcd_musb.c @@ -26,7 +26,7 @@ #include "tusb_option.h" -#if TU_CHECK_MCU(OPT_MCU_MSP432E4xx, OPT_MCU_TM4C123, OPT_MCU_TM4C129) +#if TU_CHECK_MCU(OPT_MCU_MSP432E4, OPT_MCU_TM4C123, OPT_MCU_TM4C129) #if __GNUC__ > 8 && defined(__ARM_FEATURE_UNALIGNED) /* GCC warns that an address may be unaligned, even though @@ -36,7 +36,7 @@ _Pragma("GCC diagnostic ignored \"-Waddress-of-packed-member\""); #include "device/dcd.h" -#if TU_CHECK_MCU(OPT_MCU_MSP432E4xx) +#if TU_CHECK_MCU(OPT_MCU_MSP432E4) #include "musb_msp432e.h" #elif TU_CHECK_MCU(OPT_MCU_TM4C123, OPT_MCU_TM4C129) diff --git a/src/tusb_option.h b/src/tusb_option.h index 246893ddb..2edd310fa 100644 --- a/src/tusb_option.h +++ b/src/tusb_option.h @@ -84,9 +84,9 @@ // Sony #define OPT_MCU_CXD56 400 ///< SONY CXD56 -// TI MSP430 +// TI #define OPT_MCU_MSP430x5xx 500 ///< TI MSP430x5xx -#define OPT_MCU_MSP432E4xx 510 ///< TI MSP432E4xx +#define OPT_MCU_MSP432E4 510 ///< TI MSP432E4xx #define OPT_MCU_TM4C123 511 ///< TI Tiva-C 123x #define OPT_MCU_TM4C129 512 ///< TI Tiva-C 129x -- cgit v1.3.1