mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-24 16:55:36 +03:00
PICO: Adding tinyUSB library
This commit is contained in:
parent
1774693395
commit
0109f50909
1507 changed files with 299535 additions and 0 deletions
149
lib/main/tinyUSB/hw/bsp/tm4c/FreeRTOSConfig/FreeRTOSConfig.h
Normal file
149
lib/main/tinyUSB/hw/bsp/tm4c/FreeRTOSConfig/FreeRTOSConfig.h
Normal file
|
@ -0,0 +1,149 @@
|
|||
/*
|
||||
* FreeRTOS Kernel V10.0.0
|
||||
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
*
|
||||
* 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. If you wish to use our Amazon
|
||||
* FreeRTOS name, please do so in a fair use way that does not cause confusion.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* http://www.FreeRTOS.org
|
||||
* http://aws.amazon.com/freertos
|
||||
*
|
||||
* 1 tab == 4 spaces!
|
||||
*/
|
||||
|
||||
|
||||
#ifndef FREERTOS_CONFIG_H
|
||||
#define FREERTOS_CONFIG_H
|
||||
|
||||
/*-----------------------------------------------------------
|
||||
* Application specific definitions.
|
||||
*
|
||||
* These definitions should be adjusted for your particular hardware and
|
||||
* application requirements.
|
||||
*
|
||||
* THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE
|
||||
* FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE.
|
||||
*
|
||||
* See http://www.freertos.org/a00110.html.
|
||||
*----------------------------------------------------------*/
|
||||
|
||||
// skip if included from IAR assembler
|
||||
#ifndef __IASMARM__
|
||||
#include "TM4C123.h"
|
||||
#endif
|
||||
|
||||
/* Cortex M23/M33 port configuration. */
|
||||
#define configENABLE_MPU 0
|
||||
#define configENABLE_FPU 1
|
||||
#define configENABLE_TRUSTZONE 0
|
||||
#define configMINIMAL_SECURE_STACK_SIZE (1024)
|
||||
|
||||
#define configUSE_PREEMPTION 1
|
||||
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 0
|
||||
#define configCPU_CLOCK_HZ SystemCoreClock
|
||||
#define configTICK_RATE_HZ ( 1000 )
|
||||
#define configMAX_PRIORITIES ( 5 )
|
||||
#define configMINIMAL_STACK_SIZE ( 128 )
|
||||
#define configTOTAL_HEAP_SIZE ( configSUPPORT_DYNAMIC_ALLOCATION*4*1024 )
|
||||
#define configMAX_TASK_NAME_LEN 16
|
||||
#define configUSE_16_BIT_TICKS 0
|
||||
#define configIDLE_SHOULD_YIELD 1
|
||||
#define configUSE_MUTEXES 1
|
||||
#define configUSE_RECURSIVE_MUTEXES 1
|
||||
#define configUSE_COUNTING_SEMAPHORES 1
|
||||
#define configQUEUE_REGISTRY_SIZE 4
|
||||
#define configUSE_QUEUE_SETS 0
|
||||
#define configUSE_TIME_SLICING 0
|
||||
#define configUSE_NEWLIB_REENTRANT 0
|
||||
#define configENABLE_BACKWARD_COMPATIBILITY 1
|
||||
#define configSTACK_ALLOCATION_FROM_SEPARATE_HEAP 0
|
||||
|
||||
#define configSUPPORT_STATIC_ALLOCATION 1
|
||||
#define configSUPPORT_DYNAMIC_ALLOCATION 0
|
||||
|
||||
/* Hook function related definitions. */
|
||||
#define configUSE_IDLE_HOOK 0
|
||||
#define configUSE_TICK_HOOK 0
|
||||
#define configUSE_MALLOC_FAILED_HOOK 0 // cause nested extern warning
|
||||
#define configCHECK_FOR_STACK_OVERFLOW 2
|
||||
#define configCHECK_HANDLER_INSTALLATION 0
|
||||
|
||||
/* Run time and task stats gathering related definitions. */
|
||||
#define configGENERATE_RUN_TIME_STATS 0
|
||||
#define configRECORD_STACK_HIGH_ADDRESS 1
|
||||
#define configUSE_TRACE_FACILITY 1 // legacy trace
|
||||
#define configUSE_STATS_FORMATTING_FUNCTIONS 0
|
||||
|
||||
/* Co-routine definitions. */
|
||||
#define configUSE_CO_ROUTINES 0
|
||||
#define configMAX_CO_ROUTINE_PRIORITIES 2
|
||||
|
||||
/* Software timer related definitions. */
|
||||
#define configUSE_TIMERS 1
|
||||
#define configTIMER_TASK_PRIORITY (configMAX_PRIORITIES-2)
|
||||
#define configTIMER_QUEUE_LENGTH 32
|
||||
#define configTIMER_TASK_STACK_DEPTH configMINIMAL_STACK_SIZE
|
||||
|
||||
/* Optional functions - most linkers will remove unused functions anyway. */
|
||||
#define INCLUDE_vTaskPrioritySet 0
|
||||
#define INCLUDE_uxTaskPriorityGet 0
|
||||
#define INCLUDE_vTaskDelete 0
|
||||
#define INCLUDE_vTaskSuspend 1 // required for queue, semaphore, mutex to be blocked indefinitely with portMAX_DELAY
|
||||
#define INCLUDE_xResumeFromISR 0
|
||||
#define INCLUDE_vTaskDelayUntil 1
|
||||
#define INCLUDE_vTaskDelay 1
|
||||
#define INCLUDE_xTaskGetSchedulerState 0
|
||||
#define INCLUDE_xTaskGetCurrentTaskHandle 1
|
||||
#define INCLUDE_uxTaskGetStackHighWaterMark 0
|
||||
#define INCLUDE_xTaskGetIdleTaskHandle 0
|
||||
#define INCLUDE_xTimerGetTimerDaemonTaskHandle 0
|
||||
#define INCLUDE_pcTaskGetTaskName 0
|
||||
#define INCLUDE_eTaskGetState 0
|
||||
#define INCLUDE_xEventGroupSetBitFromISR 0
|
||||
#define INCLUDE_xTimerPendFunctionCall 0
|
||||
|
||||
/* FreeRTOS hooks to NVIC vectors */
|
||||
#define xPortPendSVHandler PendSV_Handler
|
||||
#define xPortSysTickHandler SysTick_Handler
|
||||
#define vPortSVCHandler SVC_Handler
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Interrupt nesting behavior configuration.
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// For Cortex-M specific: __NVIC_PRIO_BITS is defined in mcu header
|
||||
#define configPRIO_BITS 3
|
||||
|
||||
/* The lowest interrupt priority that can be used in a call to a "set priority" function. */
|
||||
#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY ((1<<configPRIO_BITS) - 1)
|
||||
|
||||
/* The highest interrupt priority that can be used by any interrupt service
|
||||
routine that makes calls to interrupt safe FreeRTOS API functions. DO NOT CALL
|
||||
INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER
|
||||
PRIORITY THAN THIS! (higher priorities are lower numeric values. */
|
||||
#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 2
|
||||
|
||||
/* Interrupt priorities used by the kernel port layer itself. These are generic
|
||||
to all Cortex-M ports, and do not rely on any particular library functions. */
|
||||
#define configKERNEL_INTERRUPT_PRIORITY ( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
|
||||
|
||||
/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!!
|
||||
See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */
|
||||
#define configMAX_SYSCALL_INTERRUPT_PRIORITY ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
|
||||
|
||||
#endif
|
|
@ -0,0 +1,13 @@
|
|||
set(MCU_SUB_VARIANT 123)
|
||||
|
||||
set(JLINK_DEVICE TM4C123GH6PM)
|
||||
set(LD_FILE_GNU ${CMAKE_CURRENT_LIST_DIR}/tm4c123.ld)
|
||||
|
||||
set(OPENOCD_OPTION "-f board/ti_ek-tm4c123gxl.cfg")
|
||||
set(UNIFLASH_OPTION "-c ${CMAKE_CURRENT_LIST_DIR}/${BOARD}.ccxml -r 1")
|
||||
|
||||
function(update_board TARGET)
|
||||
target_compile_definitions(${TARGET} PUBLIC
|
||||
TM4C123GH6PM
|
||||
)
|
||||
endfunction()
|
52
lib/main/tinyUSB/hw/bsp/tm4c/boards/ek_tm4c123gxl/board.h
Normal file
52
lib/main/tinyUSB/hw/bsp/tm4c/boards/ek_tm4c123gxl/board.h
Normal file
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* 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 _BOARD_H_
|
||||
#define _BOARD_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define BOARD_UART UART0
|
||||
#define BOARD_UART_PORT GPIOA
|
||||
|
||||
#define BOARD_BTN_PORT GPIOF
|
||||
#define BOARD_BTN 4
|
||||
#define BOARD_BTN_Msk (1u<<4)
|
||||
#define BUTTON_STATE_ACTIVE 0
|
||||
|
||||
#define LED_PORT GPIOF
|
||||
#define LED_PIN_RED 1
|
||||
#define LED_PIN_BLUE 2
|
||||
#define LED_PIN_GREEN 3
|
||||
#define LED_STATE_ON 1
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
15
lib/main/tinyUSB/hw/bsp/tm4c/boards/ek_tm4c123gxl/board.mk
Normal file
15
lib/main/tinyUSB/hw/bsp/tm4c/boards/ek_tm4c123gxl/board.mk
Normal file
|
@ -0,0 +1,15 @@
|
|||
MCU_SUB_VARIANT = 123
|
||||
|
||||
CFLAGS += -DTM4C123GH6PM
|
||||
|
||||
LD_FILE = $(BOARD_PATH)/tm4c123.ld
|
||||
|
||||
# For flash-jlink target
|
||||
JLINK_DEVICE = TM4C123GH6PM
|
||||
|
||||
# flash using openocd
|
||||
OPENOCD_OPTION = -f board/ti_ek-tm4c123gxl.cfg
|
||||
|
||||
UNIFLASH_OPTION = -c ${TOP}/${BOARD_PATH}/${BOARD}.ccxml -r 1
|
||||
|
||||
flash: flash-openocd
|
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<configurations XML_version="1.2" id="configurations_0">
|
||||
<configuration XML_version="1.2" id="configuration_0">
|
||||
<instance XML_version="1.2" desc="Stellaris In-Circuit Debug Interface" href="connections/Stellaris_ICDI_Connection.xml" id="Stellaris In-Circuit Debug Interface" xml="Stellaris_ICDI_Connection.xml" xmlpath="connections"/>
|
||||
<connection XML_version="1.2" id="Stellaris In-Circuit Debug Interface">
|
||||
|
||||
<instance XML_version="1.2" href="drivers/stellaris_cs_dap.xml" id="drivers" xml="stellaris_cs_dap.xml" xmlpath="drivers"/>
|
||||
|
||||
<instance XML_version="1.2" href="drivers/stellaris_cortex_m4.xml" id="drivers" xml="stellaris_cortex_m4.xml" xmlpath="drivers"/>
|
||||
|
||||
|
||||
<platform XML_version="1.2" id="platform_0">
|
||||
<instance XML_version="1.2" desc="Tiva TM4C123GH6PM" href="devices/tm4c123gh6pm.xml" id="Tiva TM4C123GH6PM" xml="tm4c123gh6pm.xml" xmlpath="devices"/>
|
||||
</platform>
|
||||
</connection>
|
||||
</configuration>
|
||||
</configurations>
|
66
lib/main/tinyUSB/hw/bsp/tm4c/boards/ek_tm4c123gxl/tm4c123.ld
Normal file
66
lib/main/tinyUSB/hw/bsp/tm4c/boards/ek_tm4c123gxl/tm4c123.ld
Normal file
|
@ -0,0 +1,66 @@
|
|||
ENTRY(Reset_Handler)
|
||||
|
||||
_estack = 0x20008000; /* end of RAM */
|
||||
/* Generate a link error if heap and stack don't fit into RAM */
|
||||
_Min_Heap_Size = 0; /* required amount of heap */
|
||||
_Min_Stack_Size = 0x1000; /* required amount of stack */
|
||||
|
||||
|
||||
MEMORY
|
||||
{
|
||||
FLASH(rx) : ORIGIN = 0x00000000, LENGTH = 256K
|
||||
SRAM(rwx) : ORIGIN = 0x20000000, LENGTH = 32K
|
||||
}
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
.text :
|
||||
{
|
||||
. = ALIGN(4) ;
|
||||
*(.vectors)
|
||||
*(.text)
|
||||
*(.text.*)
|
||||
*(.init)
|
||||
*(.fini)
|
||||
*(.rodata)
|
||||
*(.rodata.*)
|
||||
*(.ARM.exidx*)
|
||||
. = ALIGN(4) ;
|
||||
__end_text = . ;
|
||||
} >FLASH
|
||||
|
||||
.data : AT(ADDR(.text) + SIZEOF(.text))
|
||||
{
|
||||
. = ALIGN(4);
|
||||
__start_data = . ;
|
||||
__la_data = LOADADDR(.data);
|
||||
*(.data)
|
||||
*(.data.*)
|
||||
. = ALIGN(4);
|
||||
__end_data = . ;
|
||||
|
||||
} >SRAM
|
||||
|
||||
.bss :
|
||||
{
|
||||
. = ALIGN(4) ;
|
||||
__start_bss = . ;
|
||||
__bss_start__ = __start_bss;
|
||||
*(.bss)
|
||||
*(.bss.*)
|
||||
*(.COMMON)
|
||||
__end_bss = . ;
|
||||
. = ALIGN(4);
|
||||
}>SRAM
|
||||
|
||||
/* User_heap_stack section, used to check that there is enough RAM left */
|
||||
._user_heap_stack :
|
||||
{
|
||||
. = ALIGN(8);
|
||||
PROVIDE ( end = . );
|
||||
PROVIDE ( _end = . );
|
||||
. = . + _Min_Heap_Size;
|
||||
. = . + _Min_Stack_Size;
|
||||
. = ALIGN(8);
|
||||
} >SRAM
|
||||
}
|
166
lib/main/tinyUSB/hw/bsp/tm4c/family.c
Normal file
166
lib/main/tinyUSB/hw/bsp/tm4c/family.c
Normal file
|
@ -0,0 +1,166 @@
|
|||
#include "TM4C123.h"
|
||||
#include "bsp/board_api.h"
|
||||
#include "board.h"
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Forward USB interrupt events to TinyUSB IRQ Handler
|
||||
//--------------------------------------------------------------------+
|
||||
void USB0_Handler(void) {
|
||||
#if CFG_TUH_ENABLED
|
||||
tuh_int_handler(0, true);
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_ENABLED
|
||||
tud_int_handler(0);
|
||||
#endif
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// MACRO TYPEDEF CONSTANT ENUM
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
static void board_uart_init(void) {
|
||||
SYSCTL->RCGCUART |= (1 << 0); // Enable the clock to UART0
|
||||
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 = 115200, with SystemCoreClock = 50 Mhz refer manual for calculation
|
||||
// - BRDI = SystemCoreClock / (16* baud)
|
||||
// - BRDF = int(fraction*64 + 0.5)
|
||||
UART0->CTL &= ~(1 << 0); // Disable UART0 by clearing UARTEN bit in the UARTCTL register
|
||||
UART0->IBRD = 27; // Write the integer portion of the BRD to the UARTIRD register
|
||||
UART0->FBRD = 8; // 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, Receive Enable
|
||||
}
|
||||
|
||||
static void initialize_board_led(GPIOA_Type* port, uint8_t PinMsk, uint8_t dirmsk) {
|
||||
/* Enable PortF Clock */
|
||||
SYSCTL->RCGCGPIO |= (1 << 5);
|
||||
|
||||
/* 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) {
|
||||
if (state) {
|
||||
port->DATA |= PinMsk;
|
||||
} else {
|
||||
port->DATA &= ~(PinMsk);
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t ReadGPIOPin(GPIOA_Type* port, uint8_t pinMsk) {
|
||||
return (port->DATA & pinMsk);
|
||||
}
|
||||
|
||||
void board_init(void) {
|
||||
SystemCoreClockUpdate();
|
||||
|
||||
#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
|
||||
|
||||
/* Reset USB */
|
||||
SYSCTL->SRCR2 |= (1u << 16);
|
||||
|
||||
for (volatile uint8_t i = 0; i < 20; i++) {}
|
||||
|
||||
SYSCTL->SRCR2 &= ~(1u << 16);
|
||||
|
||||
/* Open the USB clock gate */
|
||||
SYSCTL->RCGCUSB |= (1 << 0);
|
||||
|
||||
/* Power-up USB PLL */
|
||||
SYSCTL->RCC2 &= ~(1u << 14);
|
||||
|
||||
/* USB IO Initialization */
|
||||
SYSCTL->RCGCGPIO |= (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));
|
||||
|
||||
uint8_t leds = (1 << LED_PIN_RED) | (1 << LED_PIN_BLUE) | (1 << LED_PIN_GREEN);
|
||||
uint8_t dirmsk = (1 << LED_PIN_RED) | (1 << LED_PIN_BLUE) | (1 << LED_PIN_GREEN);
|
||||
|
||||
/* Configure GPIO for board LED */
|
||||
initialize_board_led(LED_PORT, leds, dirmsk);
|
||||
|
||||
/* Configure GPIO for board switch */
|
||||
GPIOF->DIR &= ~(1 << BOARD_BTN);
|
||||
GPIOF->PUR |= (1 << BOARD_BTN);
|
||||
GPIOF->DEN |= (1 << BOARD_BTN);
|
||||
|
||||
/* Initialize board UART */
|
||||
board_uart_init();
|
||||
|
||||
TU_LOG1_INT(SystemCoreClock);
|
||||
}
|
||||
|
||||
void board_led_write(bool state) {
|
||||
WriteGPIOPin(LED_PORT, (1 << LED_PIN_BLUE), state);
|
||||
}
|
||||
|
||||
uint32_t board_button_read(void) {
|
||||
uint32_t gpio_value = ReadGPIOPin(BOARD_BTN_PORT, BOARD_BTN_Msk);
|
||||
return BUTTON_STATE_ACTIVE ? gpio_value : !gpio_value;
|
||||
}
|
||||
|
||||
size_t board_get_unique_id(uint8_t id[], size_t max_len) {
|
||||
(void) max_len;
|
||||
uint8_t const len = 8;
|
||||
// Note: DID0, DID1 are variant ID, they aer used since TM4C123 does not have unique ID
|
||||
memcpy(id, (void*)(uintptr_t) &SYSCTL->DID0, len);
|
||||
return len;
|
||||
}
|
||||
|
||||
int board_uart_write(void const* buf, int len) {
|
||||
uint8_t const* data = buf;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
int board_uart_read(uint8_t* 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
|
96
lib/main/tinyUSB/hw/bsp/tm4c/family.cmake
Normal file
96
lib/main/tinyUSB/hw/bsp/tm4c/family.cmake
Normal file
|
@ -0,0 +1,96 @@
|
|||
include_guard()
|
||||
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/boards/${BOARD}/board.cmake)
|
||||
|
||||
set(MCU_VARIANT tm4c${MCU_SUB_VARIANT})
|
||||
set(MCU_VARIANT_UPPER TM4C${MCU_SUB_VARIANT})
|
||||
|
||||
set(SDK_DIR ${TOP}/hw/mcu/ti/${MCU_VARIANT}xx)
|
||||
set(CMSIS_DIR ${TOP}/lib/CMSIS_5)
|
||||
|
||||
# toolchain set up
|
||||
set(CMAKE_SYSTEM_PROCESSOR cortex-m4 CACHE INTERNAL "System Processor")
|
||||
set(CMAKE_TOOLCHAIN_FILE ${TOP}/examples/build_system/cmake/toolchain/arm_${TOOLCHAIN}.cmake)
|
||||
|
||||
set(FAMILY_MCUS TM4C123 CACHE INTERNAL "")
|
||||
|
||||
#------------------------------------
|
||||
# BOARD_TARGET
|
||||
#------------------------------------
|
||||
# only need to be built ONCE for all examples
|
||||
function(add_board_target BOARD_TARGET)
|
||||
if (TARGET ${BOARD_TARGET})
|
||||
return()
|
||||
endif()
|
||||
|
||||
set(LD_FILE_Clang ${LD_FILE_GNU})
|
||||
|
||||
set(STARTUP_FILE_GNU ${SDK_DIR}/Source/GCC/${MCU_VARIANT}_startup.c)
|
||||
set(STARTUP_FILE_Clang ${STARTUP_FILE_GNU})
|
||||
|
||||
add_library(${BOARD_TARGET} STATIC
|
||||
${SDK_DIR}/Source/system_${MCU_VARIANT_UPPER}.c
|
||||
${STARTUP_FILE_${CMAKE_C_COMPILER_ID}}
|
||||
)
|
||||
target_include_directories(${BOARD_TARGET} PUBLIC
|
||||
${SDK_DIR}/Include/${MCU_VARIANT_UPPER}
|
||||
${CMSIS_DIR}/CMSIS/Core/Include
|
||||
)
|
||||
|
||||
update_board(${BOARD_TARGET})
|
||||
|
||||
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
|
||||
target_link_options(${BOARD_TARGET} PUBLIC
|
||||
"LINKER:--script=${LD_FILE_GNU}"
|
||||
--specs=nosys.specs --specs=nano.specs
|
||||
-uvectors
|
||||
)
|
||||
elseif (CMAKE_C_COMPILER_ID STREQUAL "Clang")
|
||||
message(FATAL_ERROR "Clang is not supported for MSP432E4")
|
||||
elseif (CMAKE_C_COMPILER_ID STREQUAL "IAR")
|
||||
target_link_options(${BOARD_TARGET} PUBLIC
|
||||
"LINKER:--config=${LD_FILE_IAR}"
|
||||
)
|
||||
endif ()
|
||||
endfunction()
|
||||
|
||||
|
||||
#------------------------------------
|
||||
# Functions
|
||||
#------------------------------------
|
||||
function(family_configure_example TARGET RTOS)
|
||||
family_configure_common(${TARGET} ${RTOS})
|
||||
|
||||
# Board target
|
||||
add_board_target(board_${BOARD})
|
||||
|
||||
#---------- Port Specific ----------
|
||||
# These files are built for each example since it depends on example's tusb_config.h
|
||||
target_sources(${TARGET} PUBLIC
|
||||
# BSP
|
||||
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/family.c
|
||||
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../board.c
|
||||
)
|
||||
target_include_directories(${TARGET} PUBLIC
|
||||
# family, hw, board
|
||||
${CMAKE_CURRENT_FUNCTION_LIST_DIR}
|
||||
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../../
|
||||
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/boards/${BOARD}
|
||||
)
|
||||
|
||||
# Add TinyUSB target and port source
|
||||
family_add_tinyusb(${TARGET} OPT_MCU_TM4C123 ${RTOS})
|
||||
target_sources(${TARGET}-tinyusb PUBLIC
|
||||
${TOP}/src/portable/mentor/musb/dcd_musb.c
|
||||
${TOP}/src/portable/mentor/musb/hcd_musb.c
|
||||
)
|
||||
target_link_libraries(${TARGET}-tinyusb PUBLIC board_${BOARD})
|
||||
|
||||
# Link dependencies
|
||||
target_link_libraries(${TARGET} PUBLIC board_${BOARD} ${TARGET}-tinyusb)
|
||||
|
||||
# Flashing
|
||||
family_add_bin_hex(${TARGET})
|
||||
family_flash_openocd(${TARGET})
|
||||
family_flash_uniflash(${TARGET})
|
||||
endfunction()
|
28
lib/main/tinyUSB/hw/bsp/tm4c/family.mk
Normal file
28
lib/main/tinyUSB/hw/bsp/tm4c/family.mk
Normal file
|
@ -0,0 +1,28 @@
|
|||
include $(TOP)/$(BOARD_PATH)/board.mk
|
||||
CPU_CORE ?= cortex-m4
|
||||
|
||||
MCU_VARIANT = tm4c${MCU_SUB_VARIANT}
|
||||
MCU_VARIANT_UPPER = TM4C${MCU_SUB_VARIANT}
|
||||
|
||||
SDK_DIR = hw/mcu/ti/${MCU_VARIANT}xx
|
||||
|
||||
CFLAGS += \
|
||||
-flto \
|
||||
-DCFG_TUSB_MCU=OPT_MCU_TM4C123 \
|
||||
-uvectors \
|
||||
|
||||
# mcu driver cause following warnings
|
||||
CFLAGS += -Wno-error=strict-prototypes -Wno-error=cast-qual
|
||||
|
||||
LDFLAGS_GCC += --specs=nosys.specs --specs=nano.specs
|
||||
|
||||
INC += \
|
||||
$(TOP)/lib/CMSIS_5/CMSIS/Core/Include \
|
||||
$(TOP)/$(SDK_DIR)/Include/${MCU_VARIANT_UPPER} \
|
||||
$(TOP)/$(BOARD_PATH)
|
||||
|
||||
SRC_C += \
|
||||
src/portable/mentor/musb/dcd_musb.c \
|
||||
src/portable/mentor/musb/hcd_musb.c \
|
||||
$(SDK_DIR)/Source/system_${MCU_VARIANT_UPPER}.c \
|
||||
$(SDK_DIR)/Source/GCC/${MCU_VARIANT}_startup.c
|
Loading…
Add table
Add a link
Reference in a new issue