add flash-uniflash support for ti tm4c

This commit is contained in:
hathach 2024-08-15 14:36:31 +07:00
parent 0be427bae9
commit 1402e6ec0d
No known key found for this signature in database
GPG Key ID: 26FAB84F615C3C52
9 changed files with 85 additions and 48 deletions

View File

@ -1,4 +1,4 @@
|Build Status| |Documentation Status| |Fuzzing Status| |License| |Build Status| |CircleCI Status| |Documentation Status| |Fuzzing Status| |License|
Sponsors Sponsors
======== ========
@ -197,6 +197,8 @@ Docs
.. |Build Status| image:: https://github.com/hathach/tinyusb/actions/workflows/cmake_arm.yml/badge.svg .. |Build Status| image:: https://github.com/hathach/tinyusb/actions/workflows/cmake_arm.yml/badge.svg
:target: https://github.com/hathach/tinyusb/actions :target: https://github.com/hathach/tinyusb/actions
.. |CircleCI Status| image:: https://dl.circleci.com/status-badge/img/circleci/4AYHvUhFxdnY4rA7LEsdqW/QmrpoL2AjGqetvFQNqtWyq/tree/master.svg?style=svg
:target: https://dl.circleci.com/status-badge/redirect/circleci/4AYHvUhFxdnY4rA7LEsdqW/QmrpoL2AjGqetvFQNqtWyq/tree/master
.. |Documentation Status| image:: https://readthedocs.org/projects/tinyusb/badge/?version=latest .. |Documentation Status| image:: https://readthedocs.org/projects/tinyusb/badge/?version=latest
:target: https://docs.tinyusb.org/en/latest/?badge=latest :target: https://docs.tinyusb.org/en/latest/?badge=latest
.. |Fuzzing Status| image:: https://oss-fuzz-build-logs.storage.googleapis.com/badges/tinyusb.svg .. |Fuzzing Status| image:: https://oss-fuzz-build-logs.storage.googleapis.com/badges/tinyusb.svg

View File

@ -166,6 +166,11 @@ flash-bmp: $(BUILD)/$(PROJECT).elf
debug-bmp: $(BUILD)/$(PROJECT).elf debug-bmp: $(BUILD)/$(PROJECT).elf
$(GDB) -ex 'target extended-remote $(BMP)' -ex 'monitor swdp_scan' -ex 'attach 1' $< $(GDB) -ex 'target extended-remote $(BMP)' -ex 'monitor swdp_scan' -ex 'attach 1' $<
# --------------- TI Uniflash -----------------
DSLITE ?= dslite.sh
flash-uniflash: $(BUILD)/$(PROJECT).hex
${DSLITE} ${UNIFLASH_OPTION} -f $<
#-------------- Artifacts -------------- #-------------- Artifacts --------------
# Create binary directory # Create binary directory

View File

@ -573,6 +573,21 @@ function(family_flash_msp430flasher TARGET)
) )
endfunction() endfunction()
function(family_flash_uniflash TARGET)
if (NOT DEFINED DSLITE)
set(DSLITE dslite.sh)
endif ()
separate_arguments(OPTION_LIST UNIX_COMMAND ${UNIFLASH_OPTION})
add_custom_target(${TARGET}-uniflash
DEPENDS ${TARGET}
COMMAND ${DSLITE} ${UNIFLASH_OPTION} -f $<TARGET_FILE_DIR:${TARGET}>/${TARGET}.hex
VERBATIM
)
endfunction()
#---------------------------------- #----------------------------------
# Family specific # Family specific
#---------------------------------- #----------------------------------

View File

@ -4,6 +4,7 @@ set(JLINK_DEVICE TM4C123GH6PM)
set(LD_FILE_GNU ${CMAKE_CURRENT_LIST_DIR}/tm4c123.ld) set(LD_FILE_GNU ${CMAKE_CURRENT_LIST_DIR}/tm4c123.ld)
set(OPENOCD_OPTION "-f board/ti_ek-tm4c123gxl.cfg") 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) function(update_board TARGET)
target_compile_definitions(${TARGET} PUBLIC target_compile_definitions(${TARGET} PUBLIC

View File

@ -10,4 +10,6 @@ JLINK_DEVICE = TM4C123GH6PM
# flash using openocd # flash using openocd
OPENOCD_OPTION = -f board/ti_ek-tm4c123gxl.cfg OPENOCD_OPTION = -f board/ti_ek-tm4c123gxl.cfg
UNIFLASH_OPTION = -c ${TOP}/${BOARD_PATH}/${BOARD}.ccxml -r 1
flash: flash-openocd flash: flash-openocd

View File

@ -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>

View File

@ -5,8 +5,7 @@
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler // Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
void USB0_Handler(void) void USB0_Handler(void) {
{
#if CFG_TUH_ENABLED #if CFG_TUH_ENABLED
tuh_int_handler(0, true); tuh_int_handler(0, true);
#endif #endif
@ -20,8 +19,7 @@ void USB0_Handler(void)
// MACRO TYPEDEF CONSTANT ENUM // MACRO TYPEDEF CONSTANT ENUM
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
static void board_uart_init (void) static void board_uart_init(void) {
{
SYSCTL->RCGCUART |= (1 << 0); // Enable the clock to UART0 SYSCTL->RCGCUART |= (1 << 0); // Enable the clock to UART0
SYSCTL->RCGCGPIO |= (1 << 0); // Enable the clock to GPIOA SYSCTL->RCGCGPIO |= (1 << 0); // Enable the clock to GPIOA
@ -42,13 +40,12 @@ static void board_uart_init (void)
UART0->CTL = (1 << 0) | (1 << 8) | (1 << 9); // UART0 Enable, Transmit Enable, Receive Enable 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) static void initialize_board_led(GPIOA_Type* port, uint8_t PinMsk, uint8_t dirmsk) {
{
/* Enable PortF Clock */ /* Enable PortF Clock */
SYSCTL->RCGCGPIO |= (1 << 5); SYSCTL->RCGCGPIO |= (1 << 5);
/* Let the clock stabilize */ /* Let the clock stabilize */
while ( !((SYSCTL->PRGPIO) & (1 << 5)) ) {} while (!((SYSCTL->PRGPIO) & (1 << 5))) {}
/* Port Digital Enable */ /* Port Digital Enable */
port->DEN |= PinMsk; port->DEN |= PinMsk;
@ -57,46 +54,33 @@ static void initialize_board_led (GPIOA_Type *port, uint8_t PinMsk, uint8_t dirm
port->DIR = dirmsk; port->DIR = dirmsk;
} }
static void board_switch_init (void) static void WriteGPIOPin(GPIOA_Type* port, uint8_t PinMsk, bool state) {
{ if (state) {
GPIOF->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)
{
if ( state )
{
port->DATA |= PinMsk; port->DATA |= PinMsk;
} } else {
else
{
port->DATA &= ~(PinMsk); 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 #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);
@ -110,7 +94,7 @@ void board_init (void)
SYSCTL->RCGCGPIO |= (1u << 3); SYSCTL->RCGCGPIO |= (1u << 3);
/* Let the clock stabilize */ /* Let the clock stabilize */
while ( !(SYSCTL->PRGPIO & (1u << 3)) ) {} while (!(SYSCTL->PRGPIO & (1u << 3))) {}
/* USB IOs to Analog Mode */ /* USB IOs to Analog Mode */
GPIOD->AFSEL &= ~((1u << 4) | (1u << 5)); GPIOD->AFSEL &= ~((1u << 4) | (1u << 5));
@ -124,7 +108,9 @@ void board_init (void)
initialize_board_led(LED_PORT, leds, dirmsk); initialize_board_led(LED_PORT, leds, dirmsk);
/* Configure GPIO for board switch */ /* Configure GPIO for board switch */
board_switch_init(); GPIOF->DIR &= ~(1 << BOARD_BTN);
GPIOF->PUR |= (1 << BOARD_BTN);
GPIOF->DEN |= (1 << BOARD_BTN);
/* Initialize board UART */ /* Initialize board UART */
board_uart_init(); board_uart_init();
@ -132,32 +118,35 @@ void board_init (void)
TU_LOG1_INT(SystemCoreClock); TU_LOG1_INT(SystemCoreClock);
} }
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) size_t board_get_unique_id(uint8_t id[], size_t max_len) {
{ (void) max_len;
uint8_t const * data = buf; 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;
}
for ( int i = 0; i < len; i++ ) int board_uart_write(void const* buf, int len) {
{ uint8_t const* data = buf;
while ( (UART0->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) buf;
(void) len; (void) len;
return 0; return 0;
@ -165,13 +154,13 @@ int board_uart_read (uint8_t *buf, int len)
#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) {
system_ticks++; system_ticks++;
} }
uint32_t board_millis (void) uint32_t board_millis(void) {
{
return system_ticks; return system_ticks;
} }
#endif #endif

View File

@ -92,4 +92,5 @@ function(family_configure_example TARGET RTOS)
# Flashing # Flashing
family_add_bin_hex(${TARGET}) family_add_bin_hex(${TARGET})
family_flash_openocd(${TARGET}) family_flash_openocd(${TARGET})
family_flash_uniflash(${TARGET})
endfunction() endfunction()

View File

@ -196,6 +196,11 @@ def flash_esptool(board, firmware):
return ret return ret
def flash_uniflash(board, firmware):
ret = run_cmd(f'dslite.sh {board["flasher_args"]} -f {firmware}.hex')
return ret
# ------------------------------------------------------------- # -------------------------------------------------------------
# Tests # Tests
# ------------------------------------------------------------- # -------------------------------------------------------------