initial commit

This commit is contained in:
shell committed 2026-10-11 21:48:59 +08:00
commit b44ce7bd77
2716 files changed
+559005

No files matched your search

@@ -0,0 +1,155 @@
/*
* 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__
#ifdef TM4C123GH6PM
#include "TM4C123.h"
#elif TM4C1294NCPDT
#include "TM4C129.h"
#else
#error "Unknown TM4C device"
#endif
#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()
@@ -0,0 +1,63 @@
/*
* 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.
*/
/* metadata:
name: TM4C123G LaunchPad
url: https://www.ti.com/tool/EK-TM4C123GXL
*/
#ifndef _BOARD_H_
#define _BOARD_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "TM4C123.h"
#define BOARD_UART UART0
#define BOARD_UART_PORT GPIOA
#define BTN_PORT_CLK 5
#define BOARD_BTN_PORT GPIOF
#define BOARD_BTN 4
#define BOARD_BTN_Msk (1u<<4)
#define BUTTON_STATE_ACTIVE 0
#define LED_PORT_CLK 5
#define LED_PORT GPIOF
#define LED_PIN_RED 1
#define LED_PIN_BLUE 2
#define LED_PIN_GREEN 3
#define LED_STATE_ON 1
#define BOARD_LED_PIN LED_PIN_BLUE
#ifdef __cplusplus
}
#endif
#endif
@@ -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>
@@ -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) ;
KEEP(*(.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
}
@@ -0,0 +1,28 @@
/*###ICF### Section handled by ICF editor, don't touch! ****/
/*-Editor annotation file-*/
/* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml" */
/*-Specials-*/
define symbol __ICFEDIT_intvec_start__ = 0x00000000;
/*-Memory Regions-*/
define symbol __ICFEDIT_region_ROM_start__ = 0x00000000;
define symbol __ICFEDIT_region_ROM_end__ = 0x000FFFFF;
define symbol __ICFEDIT_region_RAM_start__ = 0x20000000;
define symbol __ICFEDIT_region_RAM_end__ = 0x2003FFFF;
/*-Sizes-*/
define symbol __ICFEDIT_size_cstack__ = 0x8000;
define symbol __ICFEDIT_size_heap__ = 0x10000;
/**** End of ICF editor section. ###ICF###*/
define memory mem with size = 4G;
define region ROM_region = mem:[from __ICFEDIT_region_ROM_start__ to __ICFEDIT_region_ROM_end__];
define region RAM_region = mem:[from __ICFEDIT_region_RAM_start__ to __ICFEDIT_region_RAM_end__];
define block CSTACK with alignment = 8, size = __ICFEDIT_size_cstack__ { };
define block HEAP with alignment = 8, size = __ICFEDIT_size_heap__ { };
initialize by copy { readwrite };
place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec };
place in ROM_region { readonly };
place in RAM_region { readwrite,
block CSTACK, block HEAP };
@@ -0,0 +1,13 @@
set(MCU_SUB_VARIANT 129)
set(JLINK_DEVICE TM4C1294NCPDT)
set(LD_FILE_GNU ${CMAKE_CURRENT_LIST_DIR}/tm4c1294nc.ld)
set(LD_FILE_IAR ${CMAKE_CURRENT_LIST_DIR}/TM4C1294NC.icf)
set(OPENOCD_OPTION "-f board/ti_ek-tm4c1294xl.cfg")
function(update_board TARGET)
target_compile_definitions(${TARGET} PUBLIC
TM4C1294NCPDT
)
endfunction()
@@ -0,0 +1,75 @@
/*
* 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.
*/
/* metadata:
name: TM4C1294 LaunchPad
url: https://www.ti.com/tool/EK-TM4C1294XL
*/
#ifndef _BOARD_H_
#define _BOARD_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "TM4C129.h"
#define BOARD_UART UART0
#define BOARD_UART_PORT GPIOA
#define BTN_PORT_CLK 8
#define BOARD_BTN_PORT GPIOJ
#define BOARD_BTN 0
#define BOARD_BTN_Msk (1u<<0)
#define BUTTON_STATE_ACTIVE 0
#define LED_PORT_CLK 12
#define LED_PORT GPION
#define LED_PIN_1 1
#define LED_PIN_2 0
#define LED_STATE_ON 1
#define BOARD_LED_PIN LED_PIN_2
#define GPIOA GPIOA_AHB
#define GPIOB GPIOB_AHB
#define GPIOC GPIOC_AHB
#define GPIOD GPIOD_AHB
#define GPIOE GPIOE_AHB
#define GPIOF GPIOF_AHB
#define GPIOG GPIOG_AHB
#define GPIOH GPIOH_AHB
#define GPIOI GPIOI_AHB
#define GPIOJ GPIOJ_AHB
#define GPIOA_Type GPIOA_AHB_Type
#ifdef __cplusplus
}
#endif
#endif
@@ -0,0 +1,15 @@
MCU_SUB_VARIANT = 129
CFLAGS += -DTM4C1294NCPDT
LD_FILE = $(BOARD_PATH)/tm4c1294nc.ld
# For flash-jlink target
JLINK_DEVICE = TM4C1294NCPDT
# flash using openocd
OPENOCD_OPTION = -f board/ti_ek-tm4c1294xl.cfg
UNIFLASH_OPTION = -c ${TOP}/${BOARD_PATH}/${BOARD}.ccxml -r 1
flash: flash-openocd
@@ -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 = 0x00100000
SRAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00040000
}
SECTIONS
{
.text :
{
. = ALIGN(4) ;
_text = . ;
KEEP(*(.isr_vector))
*(.text)
*(.text.*)
*(.init)
*(.fini)
*(.rodata)
*(.rodata.*)
*(.ARM.exidx*)
_etext = . ;
. = ALIGN(4) ;
} >FLASH
.data : AT(ADDR(.text) + SIZEOF(.text))
{
_data = .;
. = ALIGN(4);
_ldata = LOADADDR (.data);
*(.data)
*(.data.*)
_edata = .;
. = ALIGN(4);
} >SRAM
.bss :
{
. = ALIGN(4) ;
_bss = .;
*(.bss)
*(.bss.*)
*(.COMMON)
_ebss = .;
. = 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
}
+229
View File
@@ -0,0 +1,229 @@
/* metadata:
manufacturer: Texas Instruments
*/
#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
while (!(SYSCTL->PRGPIO & (1 << 0))) {} // Wait for the GPIOA clock to stabilize
while (!(SYSCTL->PRUART & (1 << 0))) {} // Wait for the UART0 clock to stabilize
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 &= ~(1U << 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 board_button_init(GPIOA_Type* port, uint8_t PinMsk) {
/* Enable Port Clock */
SYSCTL->RCGCGPIO |= (1 << BTN_PORT_CLK);
/* Let the clock stabilize */
while (!((SYSCTL->PRGPIO) & (1 << BTN_PORT_CLK))) {}
/* Port Digital Enable */
port->DEN |= PinMsk;
/* Set direction */
port->DIR &= ~PinMsk;
/* Enable internal pull so the idle state is deterministic. LaunchPad buttons
* connect the pin to GND when pressed (active-low) and require a pull-up. */
#if BUTTON_STATE_ACTIVE == 0
port->PUR |= PinMsk;
#else
port->PDR |= PinMsk;
#endif
}
static void board_led_init(GPIOA_Type* port, uint8_t PinMsk, uint8_t dirmsk) {
/* Enable Port Clock */
SYSCTL->RCGCGPIO |= (1 << LED_PORT_CLK);
/* Let the clock stabilize */
while (!((SYSCTL->PRGPIO) & (1 << LED_PORT_CLK))) {}
/* 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) {
#ifdef TM4C123_H
SystemCoreClockUpdate();
#endif
#if CFG_TUSB_OS == OPT_OS_NONE
// 1ms tick timer
SysTick_Config(SystemCoreClock / 1000);
#elif CFG_TUSB_OS == OPT_OS_FREERTOS
// Explicitly disable systick to prevent its ISR from running before scheduler start
SysTick->CTRL &= ~1U;
// If freeRTOS is used, IRQ priority is limit by max syscall ( smaller is higher )
NVIC_SetPriority(USB0_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY );
#endif
#ifdef TM4C123_H
/* 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));
#else // TM4C129
/* Reset USB */
SYSCTL->SRUSB = 1;
for (volatile uint8_t i = 0; i < 20; i++) {}
SYSCTL->SRUSB = 0;
/* Open the USB clock gate */
SYSCTL->RCGCUSB = 1;
/* Let the clock stabilize */
while(!(SYSCTL->PRUSB & 1)) {}
/* USB IO Initialization */
SYSCTL->RCGCGPIO |= (1u << 10);
/* Let the clock stabilize */
while (!(SYSCTL->PRGPIO & (1u << 10))) {}
/* USB IOs to Analog Mode */
GPIOL->AFSEL &= ~((1u << 6) | (1u << 7));
GPIOL->DEN &= ~((1u << 6) | (1u << 7));
GPIOL->AMSEL |= ((1u << 6) | (1u << 7));
/* USB Clock Configuration */
USB0->CC = 0x207;
#endif
uint8_t leds = 1 << BOARD_LED_PIN;
uint8_t dirmsk = 1 << BOARD_LED_PIN;
/* Configure GPIO for board button */
board_button_init(BOARD_BTN_PORT, BOARD_BTN_Msk);
/* Configure GPIO for board LED */
board_led_init(LED_PORT, leds, dirmsk);
/* Initialize board UART */
board_uart_init();
TU_LOG1_INT(SystemCoreClock);
}
void board_led_write(bool state) {
WriteGPIOPin(LED_PORT, (1 << BOARD_LED_PIN), 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;
int count = 0;
while (count < len) {
if ((UART0->FR & (1 << 5)) == 0) { // TX FIFO not full
UART0->DR = data[count];
count++;
} else {
break;
}
}
return count;
}
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 tusb_time_millis_api(void) {
return system_ticks;
}
#endif
+84
View File
@@ -0,0 +1,84 @@
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/tm4c)
set(CMSIS_DIR ${TOP}/lib/CMSIS_5)
# toolchain set up
set(CMAKE_SYSTEM_CPU cortex-m4 CACHE INTERNAL "System Processor")
set(CMAKE_TOOLCHAIN_FILE ${TOP}/examples/build_system/cmake/toolchain/arm_${TOOLCHAIN}.cmake)
set(FAMILY_MCUS TM4C CACHE INTERNAL "")
#------------------------------------
# Startup & Linker script
#------------------------------------
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})
set(STARTUP_FILE_IAR ${SDK_DIR}/Source/IAR/${MCU_VARIANT}_startup.c)
#------------------------------------
# Board Target
#------------------------------------
function(family_add_board BOARD_TARGET)
add_library(${BOARD_TARGET} STATIC
${SDK_DIR}/Source/system_${MCU_VARIANT_UPPER}.c
)
target_include_directories(${BOARD_TARGET} PUBLIC
${SDK_DIR}/Include
${CMSIS_DIR}/CMSIS/Core/Include
)
update_board(${BOARD_TARGET})
endfunction()
#------------------------------------
# Functions
#------------------------------------
function(family_configure_example TARGET RTOS)
family_configure_common(${TARGET} ${RTOS})
family_add_tinyusb(${TARGET} OPT_MCU_TM4C${MCU_SUB_VARIANT})
target_sources(${TARGET} PUBLIC
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/family.c
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../board.c
${TOP}/src/portable/mentor/musb/dcd_musb.c
${TOP}/src/portable/mentor/musb/hcd_musb.c
${STARTUP_FILE_${CMAKE_C_COMPILER_ID}}
)
target_include_directories(${TARGET} PUBLIC
${CMAKE_CURRENT_FUNCTION_LIST_DIR}
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../../
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/boards/${BOARD}
)
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
target_link_options(${TARGET} PUBLIC
"LINKER:--script=${LD_FILE_GNU}"
--specs=nosys.specs --specs=nano.specs
)
elseif (CMAKE_C_COMPILER_ID STREQUAL "Clang")
message(FATAL_ERROR "Clang is not supported")
elseif (CMAKE_C_COMPILER_ID STREQUAL "IAR")
target_link_options(${TARGET} PUBLIC
"LINKER:--config=${LD_FILE_IAR}"
)
endif ()
if (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "Clang")
set_source_files_properties(${CMAKE_CURRENT_FUNCTION_LIST_DIR}/family.c PROPERTIES COMPILE_FLAGS "-Wno-missing-prototypes")
set_source_files_properties(${STARTUP_FILE_${CMAKE_C_COMPILER_ID}} PROPERTIES
SKIP_LINTING ON
COMPILE_OPTIONS -w)
endif ()
# Flashing
family_add_bin_hex(${TARGET})
family_flash_jlink(${TARGET})
family_flash_lm4flash(${TARGET})
# family_flash_uniflash(${TARGET})
endfunction()
+28
View 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/tm4c
CFLAGS += \
-flto \
-DCFG_TUSB_MCU=OPT_MCU_TM4C${MCU_SUB_VARIANT} \
-uvectors \
# mcu driver cause following warnings
CFLAGS += -Wno-error=strict-prototypes -Wno-error=cast-qual
LDFLAGS += --specs=nosys.specs --specs=nano.specs
INC += \
$(TOP)/lib/CMSIS_5/CMSIS/Core/Include \
$(TOP)/$(SDK_DIR)/Include \
$(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