musb work well with tm4c123
This commit is contained in:
parent
91646d039c
commit
6fea50f735
|
@ -25,6 +25,7 @@ INC += \
|
||||||
$(TOP)/hw/bsp
|
$(TOP)/hw/bsp
|
||||||
|
|
||||||
SRC_C += \
|
SRC_C += \
|
||||||
|
src/portable/mentor/musb/dcd_musb.c \
|
||||||
$(MCU_DIR)/Source/system_TM4C123.c \
|
$(MCU_DIR)/Source/system_TM4C123.c \
|
||||||
$(MCU_DIR)/Source/GCC/tm4c123_startup.c
|
$(MCU_DIR)/Source/GCC/tm4c123_startup.c
|
||||||
|
|
||||||
|
|
|
@ -15,143 +15,156 @@
|
||||||
#define LED_PIN_GREEN 3
|
#define LED_PIN_GREEN 3
|
||||||
#define LED_STATE_ON 1
|
#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
|
tud_int_handler(0);
|
||||||
SYSCTL->RCGCGPIO |= (1<<0); // Enable the clock to GPIOA
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
/** 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->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)
|
//--------------------------------------------------------------------+
|
||||||
|
// MACRO TYPEDEF CONSTANT ENUM
|
||||||
|
//--------------------------------------------------------------------+
|
||||||
|
|
||||||
|
static void board_uart_init (void)
|
||||||
{
|
{
|
||||||
/* Enable PortF Clock */
|
SYSCTL->RCGCUART |= (1 << 0); // Enable the clock to UART0
|
||||||
SYSCTL -> RCGCGPIO |= (1<<5) ;
|
SYSCTL->RCGCGPIO |= (1 << 0); // Enable the clock to GPIOA
|
||||||
|
|
||||||
/* Let the clock stabilize */
|
GPIOA->AFSEL |= (1 << 1) | (1 << 0); // Enable the alternate function on pin PA0 & PA1
|
||||||
while(! ((SYSCTL->PRGPIO) & (1<<5)) ) ;
|
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
|
||||||
|
|
||||||
/* Port Digital Enable */
|
/** BAUDRATE = 9600 bits per second, refer manual for calculation **/
|
||||||
port->DEN |= PinMsk;
|
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
|
||||||
|
|
||||||
/* Set direction */
|
UART0->LCRH = (0x3 << 5); // 8-bit, no parity, 1 stop bit
|
||||||
port->DIR = dirmsk ;
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
static void board_switch_init(void)
|
static void initialize_board_led (GPIOA_Type *port, uint8_t PinMsk, uint8_t dirmsk)
|
||||||
{
|
{
|
||||||
GPIOF->DIR &= ~(1<<BOARD_BTN);
|
/* Enable PortF Clock */
|
||||||
GPIOF->PUR |= (1<<BOARD_BTN);
|
SYSCTL->RCGCGPIO |= (1 << 5);
|
||||||
GPIOF->DEN |= (1<<BOARD_BTN);
|
|
||||||
|
/* Let the clock stabilize */
|
||||||
|
while ( !((SYSCTL->PRGPIO) & (1 << 5)) )
|
||||||
|
;
|
||||||
|
|
||||||
|
/* Port Digital Enable */
|
||||||
|
port->DEN |= PinMsk;
|
||||||
|
|
||||||
|
/* Set direction */
|
||||||
|
port->DIR = dirmsk;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void WriteGPIOPin(GPIOA_Type* port, uint8_t PinMsk, bool state)
|
static void board_switch_init (void)
|
||||||
{
|
{
|
||||||
if(state)
|
GPIOF->DIR &= ~(1 << BOARD_BTN);
|
||||||
port->DATA |= PinMsk;
|
GPIOF->PUR |= (1 << BOARD_BTN);
|
||||||
else
|
GPIOF->DEN |= (1 << BOARD_BTN);
|
||||||
port->DATA &= ~(PinMsk);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t ReadGPIOPin(GPIOA_Type *port, uint8_t pinMsk)
|
static void WriteGPIOPin (GPIOA_Type *port, uint8_t PinMsk, bool state)
|
||||||
{
|
{
|
||||||
return (port -> DATA & pinMsk) ;
|
if ( state )
|
||||||
|
port->DATA |= PinMsk;
|
||||||
|
else
|
||||||
|
port->DATA &= ~(PinMsk);
|
||||||
}
|
}
|
||||||
|
|
||||||
void board_init(void)
|
static uint32_t ReadGPIOPin (GPIOA_Type *port, uint8_t pinMsk)
|
||||||
{
|
{
|
||||||
SystemCoreClockUpdate();
|
return (port->DATA & pinMsk);
|
||||||
|
}
|
||||||
|
|
||||||
|
void board_init (void)
|
||||||
|
{
|
||||||
|
SystemCoreClockUpdate();
|
||||||
|
|
||||||
#if CFG_TUSB_OS == OPT_OS_NONE
|
#if CFG_TUSB_OS == OPT_OS_NONE
|
||||||
// 1ms tick timer
|
// 1ms tick timer
|
||||||
SysTick_Config(SystemCoreClock / 1000);
|
SysTick_Config(SystemCoreClock / 1000);
|
||||||
#elif CFG_TUSB_OS == OPT_OS_FREERTOS
|
#elif CFG_TUSB_OS == OPT_OS_FREERTOS
|
||||||
// If freeRTOS is used, IRQ priority is limit by max syscall ( smaller is higher )
|
// If freeRTOS is used, IRQ priority is limit by max syscall ( smaller is higher )
|
||||||
NVIC_SetPriority(USB0_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY );
|
NVIC_SetPriority(USB0_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Reset USB */
|
/* Reset USB */
|
||||||
SYSCTL->SRCR2 |= (1u<<16);
|
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 */
|
/* Open the USB clock gate */
|
||||||
SYSCTL->RCGCUSB |= (1<<0);
|
SYSCTL->RCGCUSB |= (1 << 0);
|
||||||
|
|
||||||
/* Power-up USB PLL */
|
/* Power-up USB PLL */
|
||||||
SYSCTL->RCC2 &= ~(1u<<14);
|
SYSCTL->RCC2 &= ~(1u << 14);
|
||||||
|
|
||||||
/* USB IO Initialization */
|
/* USB IO Initialization */
|
||||||
SYSCTL->RCGCGPIO |= (1u<<3);
|
SYSCTL->RCGCGPIO |= (1u << 3);
|
||||||
|
|
||||||
/* Let the clock stabilize */
|
|
||||||
while(!(SYSCTL->PRGPIO & (1u<<3)));
|
|
||||||
|
|
||||||
/* USB IOs to Analog Mode */
|
/* Let the clock stabilize */
|
||||||
GPIOD->AFSEL &= ~ ( (1u<<4) | (1u<<5) );
|
while ( !(SYSCTL->PRGPIO & (1u << 3)) )
|
||||||
GPIOD->DEN &= ~ ( (1u<<4) | (1u<<5) );
|
;
|
||||||
GPIOD->AMSEL |= ( (1u<<4) | (1u<<5) );
|
|
||||||
|
|
||||||
uint8_t leds = (1<<LED_PIN_RED) | (1<<LED_PIN_BLUE) | (1<<LED_PIN_GREEN) ;
|
/* USB IOs to Analog Mode */
|
||||||
uint8_t dirmsk = (1<<LED_PIN_RED) | (1<<LED_PIN_BLUE) | (1<<LED_PIN_GREEN) ;
|
GPIOD->AFSEL &= ~((1u << 4) | (1u << 5));
|
||||||
|
GPIOD->DEN &= ~((1u << 4) | (1u << 5));
|
||||||
|
GPIOD->AMSEL |= ((1u << 4) | (1u << 5));
|
||||||
|
|
||||||
/* Configure GPIO for board LED */
|
uint8_t leds = (1 << LED_PIN_RED) | (1 << LED_PIN_BLUE) | (1 << LED_PIN_GREEN);
|
||||||
initialize_board_led(LED_PORT,leds, dirmsk);
|
uint8_t dirmsk = (1 << LED_PIN_RED) | (1 << LED_PIN_BLUE) | (1 << LED_PIN_GREEN);
|
||||||
|
|
||||||
/* Configure GPIO for board switch */
|
/* Configure GPIO for board LED */
|
||||||
board_switch_init();
|
initialize_board_led(LED_PORT, leds, dirmsk);
|
||||||
|
|
||||||
/* Initialize board UART */
|
/* Configure GPIO for board switch */
|
||||||
board_uart_init();
|
board_switch_init();
|
||||||
|
|
||||||
|
/* Initialize board UART */
|
||||||
|
board_uart_init();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void board_led_write(bool state)
|
void board_led_write (bool state)
|
||||||
{
|
{
|
||||||
WriteGPIOPin(LED_PORT, (1<<LED_PIN_BLUE), state);
|
WriteGPIOPin(LED_PORT, (1 << LED_PIN_BLUE), state);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t board_button_read(void)
|
uint32_t board_button_read (void)
|
||||||
{
|
{
|
||||||
uint32_t gpio_value = ReadGPIOPin(BOARD_BTN_PORT, BOARD_BTN_Msk);
|
uint32_t gpio_value = ReadGPIOPin(BOARD_BTN_PORT, BOARD_BTN_Msk);
|
||||||
return BUTTON_STATE_ACTIVE ? gpio_value : !gpio_value;
|
return BUTTON_STATE_ACTIVE ? gpio_value : !gpio_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
int board_uart_write(void const* buf, int len)
|
int board_uart_write (void const *buf, int len)
|
||||||
{
|
{
|
||||||
uint8_t const* data = buf;
|
uint8_t const * data = buf;
|
||||||
|
|
||||||
for(int i=0; i<len; i++)
|
for ( int i = 0; i < len; i++ )
|
||||||
{
|
{
|
||||||
while((UART0->FR &(1<<5)) != 0); // Poll until previous data was shofted out
|
while ( (UART0->FR & (1 << 5)) != 0 ) {} // Poll until previous data was shofted out
|
||||||
UART0->DR= data[i]; // Write UART0 DATA REGISTER
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if CFG_TUSB_OS == OPT_OS_NONE
|
#if CFG_TUSB_OS == OPT_OS_NONE
|
||||||
volatile uint32_t system_ticks = 0;
|
volatile uint32_t system_ticks = 0;
|
||||||
void SysTick_Handler (void)
|
void SysTick_Handler (void)
|
||||||
|
@ -159,7 +172,7 @@ void SysTick_Handler (void)
|
||||||
system_ticks++;
|
system_ticks++;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t board_millis(void)
|
uint32_t board_millis (void)
|
||||||
{
|
{
|
||||||
return system_ticks;
|
return system_ticks;
|
||||||
}
|
}
|
||||||
|
|
|
@ -143,7 +143,10 @@
|
||||||
#define DCD_ATTR_ENDPOINT_EXCLUSIVE_NUMBER
|
#define DCD_ATTR_ENDPOINT_EXCLUSIVE_NUMBER
|
||||||
|
|
||||||
//------------- TI -------------//
|
//------------- 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
|
#define DCD_ATTR_ENDPOINT_MAX 8
|
||||||
|
|
||||||
//------------- ValentyUSB -------------//
|
//------------- ValentyUSB -------------//
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
|
|
||||||
#include "tusb_option.h"
|
#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)
|
#if __GNUC__ > 8 && defined(__ARM_FEATURE_UNALIGNED)
|
||||||
/* GCC warns that an address may be unaligned, even though
|
/* GCC warns that an address may be unaligned, even though
|
||||||
|
@ -35,7 +35,21 @@ _Pragma("GCC diagnostic ignored \"-Waddress-of-packed-member\"");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "device/dcd.h"
|
#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
|
* MACRO TYPEDEF CONSTANT ENUM DECLARATION
|
||||||
|
|
|
@ -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
|
|
@ -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
|
|
@ -87,7 +87,8 @@
|
||||||
// TI MSP430
|
// TI MSP430
|
||||||
#define OPT_MCU_MSP430x5xx 500 ///< TI MSP430x5xx
|
#define OPT_MCU_MSP430x5xx 500 ///< TI MSP430x5xx
|
||||||
#define OPT_MCU_MSP432E4xx 510 ///< TI MSP432E4xx
|
#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
|
// ValentyUSB eptri
|
||||||
#define OPT_MCU_VALENTYUSB_EPTRI 600 ///< Fomu eptri config
|
#define OPT_MCU_VALENTYUSB_EPTRI 600 ///< Fomu eptri config
|
||||||
|
|
Loading…
Reference in New Issue