summaryrefslogtreecommitdiff
path: root/hw
diff options
context:
space:
mode:
authorHiFiPhile <[email protected]>2026-02-27 11:47:58 +0100
committerHiFiPhile <[email protected]>2026-02-27 11:47:58 +0100
commitecc0e12dd5ab58cffafb03a8d1800dc68bed1c6f (patch)
tree6ced64f1cca39af4aaf77a3861785f5b21f71b1b /hw
parenta3fd3071c17bdc7392db1361f3a97019351af337 (diff)
parentbd1e79bc6cefbbbe981691c3a55e24cf25537301 (diff)
Merge remote-tracking branch 'tinyusb/master' into dwc2_deinit
Signed-off-by: HiFiPhile <[email protected]>
Diffstat (limited to 'hw')
-rw-r--r--hw/bsp/BoardPresets.json44
-rw-r--r--hw/bsp/at32f45x/FreeRTOSConfig/FreeRTOSConfig.h176
-rw-r--r--hw/bsp/at32f45x/at32f45x_clock.c114
-rw-r--r--hw/bsp/at32f45x/at32f45x_clock.h44
-rw-r--r--hw/bsp/at32f45x/at32f45x_conf.h174
-rw-r--r--hw/bsp/at32f45x/at32f45x_int.c100
-rw-r--r--hw/bsp/at32f45x/at32f45x_int.h59
-rw-r--r--hw/bsp/at32f45x/boards/at_start_f455/board.cmake8
-rw-r--r--hw/bsp/at32f45x/boards/at_start_f455/board.h96
-rw-r--r--hw/bsp/at32f45x/boards/at_start_f455/board.mk7
-rw-r--r--hw/bsp/at32f45x/boards/at_start_f456/board.cmake8
-rw-r--r--hw/bsp/at32f45x/boards/at_start_f456/board.h96
-rw-r--r--hw/bsp/at32f45x/boards/at_start_f456/board.mk7
-rw-r--r--hw/bsp/at32f45x/boards/at_start_f457/board.cmake8
-rw-r--r--hw/bsp/at32f45x/boards/at_start_f457/board.h96
-rw-r--r--hw/bsp/at32f45x/boards/at_start_f457/board.mk7
-rw-r--r--hw/bsp/at32f45x/family.c258
-rw-r--r--hw/bsp/at32f45x/family.cmake97
-rw-r--r--hw/bsp/at32f45x/family.mk40
-rw-r--r--hw/bsp/family_support.cmake116
-rw-r--r--hw/bsp/rp2040/family.cmake8
-rw-r--r--hw/bsp/stm32f2/family.c8
-rw-r--r--hw/bsp/stm32f4/boards/feather_stm32f405/board.h10
-rw-r--r--hw/bsp/stm32f4/boards/pyboardv11/board.h10
-rw-r--r--hw/bsp/stm32f4/boards/stm32f401blackpill/board.h11
-rw-r--r--hw/bsp/stm32f4/boards/stm32f407blackvet/board.h11
-rw-r--r--hw/bsp/stm32f4/boards/stm32f407disco/board.h10
-rw-r--r--hw/bsp/stm32f4/boards/stm32f411blackpill/board.h11
-rw-r--r--hw/bsp/stm32f4/boards/stm32f411disco/board.h10
-rw-r--r--hw/bsp/stm32f4/boards/stm32f412disco/board.h9
-rw-r--r--hw/bsp/stm32f4/boards/stm32f412nucleo/board.h9
-rw-r--r--hw/bsp/stm32f4/boards/stm32f439nucleo/board.h10
-rw-r--r--hw/bsp/stm32f4/family.c7
-rw-r--r--hw/bsp/stm32f7/boards/stm32f723disco/board.h2
-rw-r--r--hw/bsp/stm32f7/boards/stm32f746disco/board.h4
-rw-r--r--hw/bsp/stm32f7/family.c36
-rw-r--r--hw/bsp/stm32h7/boards/stm32h743eval/board.h2
-rw-r--r--hw/bsp/stm32h7/boards/stm32h747disco/board.cmake23
-rw-r--r--hw/bsp/stm32h7/boards/stm32h747disco/board.h169
-rw-r--r--hw/bsp/stm32h7/boards/stm32h747disco/board.mk15
-rw-r--r--hw/bsp/stm32h7/family.c42
-rw-r--r--hw/bsp/stm32h7/linker/stm32h747xx_flash_CM7.ld184
-rw-r--r--hw/bsp/stm32h7rs/boards/stm32h7s3nucleo/board.cmake2
-rw-r--r--hw/bsp/stm32h7rs/boards/stm32h7s3nucleo/board.h2
-rw-r--r--hw/bsp/stm32h7rs/family.c49
-rw-r--r--hw/bsp/stm32h7rs/family.cmake2
-rw-r--r--hw/bsp/stm32l4/boards/stm32l476disco/board.h11
-rw-r--r--hw/bsp/stm32l4/boards/stm32l496nucleo/board.h8
-rw-r--r--hw/bsp/stm32l4/boards/stm32l4p5nucleo/board.h8
-rw-r--r--hw/bsp/stm32l4/boards/stm32l4r5nucleo/board.h8
-rw-r--r--hw/bsp/stm32l4/family.c10
-rw-r--r--hw/bsp/stm32n6/boards/stm32n6570dk/board.cmake2
-rw-r--r--hw/bsp/stm32n6/boards/stm32n6570dk/board.h41
-rw-r--r--hw/bsp/stm32n6/boards/stm32n657nucleo/board.cmake9
-rw-r--r--hw/bsp/stm32n6/boards/stm32n657nucleo/board.h33
-rw-r--r--hw/bsp/stm32n6/boards/stm32n657nucleo/board.mk5
-rw-r--r--hw/bsp/stm32n6/family.c120
-rw-r--r--hw/bsp/stm32n6/family.cmake7
-rw-r--r--hw/bsp/stm32n6/family.mk6
-rw-r--r--hw/bsp/stm32n6/setup_iar.mac12
-rw-r--r--hw/bsp/stm32n6/stm32n6.jdebug362
-rw-r--r--hw/bsp/stm32n6/stm32n6xx_hal_conf.h2
-rw-r--r--hw/bsp/stm32u5/boards/b_u585i_iot2a/board.h5
-rw-r--r--hw/bsp/stm32u5/boards/stm32u545nucleo/board.h3
-rw-r--r--hw/bsp/stm32u5/boards/stm32u575eval/board.h5
-rw-r--r--hw/bsp/stm32u5/boards/stm32u575nucleo/board.h102
-rw-r--r--hw/bsp/stm32u5/boards/stm32u5a5nucleo/board.h106
-rw-r--r--hw/bsp/stm32u5/family.c30
-rw-r--r--hw/bsp/stm32u5/family.cmake5
-rw-r--r--hw/bsp/stm32u5/family.mk7
-rw-r--r--hw/bsp/stm32u5/stm32u5xx_hal_conf.h4
-rw-r--r--hw/bsp/stm32wba/family.c9
-rw-r--r--hw/bsp/tm4c/FreeRTOSConfig/FreeRTOSConfig.h8
-rw-r--r--hw/bsp/tm4c/boards/ek_tm4c123gxl/board.h6
-rw-r--r--hw/bsp/tm4c/boards/ek_tm4c123gxl/tm4c123.ld2
-rw-r--r--hw/bsp/tm4c/boards/ek_tm4c1294xl/TM4C1294NC.icf28
-rw-r--r--hw/bsp/tm4c/boards/ek_tm4c1294xl/board.cmake13
-rw-r--r--hw/bsp/tm4c/boards/ek_tm4c1294xl/board.h75
-rw-r--r--hw/bsp/tm4c/boards/ek_tm4c1294xl/board.mk16
-rw-r--r--hw/bsp/tm4c/boards/ek_tm4c1294xl/tm4c1294nc.ld66
-rw-r--r--hw/bsp/tm4c/family.c76
-rw-r--r--hw/bsp/tm4c/family.cmake17
-rw-r--r--hw/bsp/tm4c/family.mk6
83 files changed, 3132 insertions, 312 deletions
diff --git a/hw/bsp/BoardPresets.json b/hw/bsp/BoardPresets.json
index 440ef8733..fabbeed93 100644
--- a/hw/bsp/BoardPresets.json
+++ b/hw/bsp/BoardPresets.json
@@ -175,6 +175,10 @@
"inherits": "default"
},
{
+ "name": "ek_tm4c1294xl",
+ "inherits": "default"
+ },
+ {
"name": "f1c100s",
"inherits": "default"
},
@@ -719,6 +723,10 @@
"inherits": "default"
},
{
+ "name": "stm32h747disco",
+ "inherits": "default"
+ },
+ {
"name": "stm32h750_weact",
"inherits": "default"
},
@@ -1109,6 +1117,11 @@
"configurePreset": "ek_tm4c123gxl"
},
{
+ "name": "ek_tm4c1294xl",
+ "description": "Build preset for the ek_tm4c1294xl board",
+ "configurePreset": "ek_tm4c1294xl"
+ },
+ {
"name": "espressif_addax_1",
"description": "Build preset for the espressif_addax_1 board",
"configurePreset": "espressif_addax_1"
@@ -1834,6 +1847,11 @@
"configurePreset": "stm32h745disco"
},
{
+ "name": "stm32h747disco",
+ "description": "Build preset for the stm32h747disco board",
+ "configurePreset": "stm32h747disco"
+ },
+ {
"name": "stm32h750_weact",
"description": "Build preset for the stm32h750_weact board",
"configurePreset": "stm32h750_weact"
@@ -2543,6 +2561,19 @@
]
},
{
+ "name": "ek_tm4c1294xl",
+ "steps": [
+ {
+ "type": "configure",
+ "name": "ek_tm4c1294xl"
+ },
+ {
+ "type": "build",
+ "name": "ek_tm4c1294xl"
+ }
+ ]
+ },
+ {
"name": "espressif_addax_1",
"steps": [
{
@@ -4428,6 +4459,19 @@
]
},
{
+ "name": "stm32h747disco",
+ "steps": [
+ {
+ "type": "configure",
+ "name": "stm32h747disco"
+ },
+ {
+ "type": "build",
+ "name": "stm32h747disco"
+ }
+ ]
+ },
+ {
"name": "stm32h750_weact",
"steps": [
{
diff --git a/hw/bsp/at32f45x/FreeRTOSConfig/FreeRTOSConfig.h b/hw/bsp/at32f45x/FreeRTOSConfig/FreeRTOSConfig.h
new file mode 100644
index 000000000..c5b89452e
--- /dev/null
+++ b/hw/bsp/at32f45x/FreeRTOSConfig/FreeRTOSConfig.h
@@ -0,0 +1,176 @@
+/*
+ * 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 MCU header
+ #include "at32f45x.h"
+#endif
+
+/* Cortex-M4 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 system_core_clock
+#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 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
+
+#ifdef __RX__
+/* Renesas RX series */
+#define vSoftwareInterruptISR INT_Excep_ICU_SWINT
+#define vTickISR INT_Excep_CMT0_CMI0
+#define configPERIPHERAL_CLOCK_HZ (configCPU_CLOCK_HZ/2)
+#define configKERNEL_INTERRUPT_PRIORITY 1
+#define configMAX_SYSCALL_INTERRUPT_PRIORITY 4
+
+#else
+
+/* FreeRTOS hooks to NVIC vectors */
+#define xPortPendSVHandler PendSV_Handler
+#define xPortSysTickHandler SysTick_Handler
+#define vPortSVCHandler SVC_Handler
+
+//--------------------------------------------------------------------+
+// Interrupt nesting behavior configuration.
+//--------------------------------------------------------------------+
+#if defined(__NVIC_PRIO_BITS)
+ // For Cortex-M specific: __NVIC_PRIO_BITS is defined in core_cmx.h
+ #define configPRIO_BITS __NVIC_PRIO_BITS
+
+#elif defined(__ECLIC_INTCTLBITS)
+ // RISC-V Bumblebee core from nuclei
+ #define configPRIO_BITS __ECLIC_INTCTLBITS
+
+#elif defined(__IASMARM__)
+ // FIXME: IAR Assembler cannot include mcu header directly to get __NVIC_PRIO_BITS.
+ // Therefore we will hard coded it to minimum value of 2 to get pass ci build.
+ // IAR user must update this to correct value of the target MCU
+ #message "configPRIO_BITS is hard coded to 2 to pass IAR build only. User should update it per MCU"
+ #define configPRIO_BITS 2
+
+#else
+ #error "FreeRTOS configPRIO_BITS to be defined"
+#endif
+
+/* 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
+
+#endif /* __FREERTOS_CONFIG__H */
diff --git a/hw/bsp/at32f45x/at32f45x_clock.c b/hw/bsp/at32f45x/at32f45x_clock.c
new file mode 100644
index 000000000..a66a8b1aa
--- /dev/null
+++ b/hw/bsp/at32f45x/at32f45x_clock.c
@@ -0,0 +1,114 @@
+/**
+ **************************************************************************
+ * @file at32f45x_clock.c
+ * @brief system clock config program
+ **************************************************************************
+ *
+ * Copyright (c) 2025, Artery Technology, All rights reserved.
+ *
+ * The software Board Support Package (BSP) that is made available to
+ * download from Artery official website is the copyrighted work of Artery.
+ * Artery authorizes customers to use, copy, and distribute the BSP
+ * software and its related documentation for the purpose of design and
+ * development in conjunction with Artery microcontrollers. Use of the
+ * software is governed by this copyright notice and the following disclaimer.
+ *
+ * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
+ * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
+ * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
+ * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
+ * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
+ *
+ **************************************************************************
+ */
+
+/* includes ------------------------------------------------------------------*/
+#include "at32f45x_clock.h"
+
+/**
+ * @brief system clock config program
+ * @note the system clock is configured as follow:
+ * - system clock = (hext * pll_ns)/(pll_ms * pll_fp)
+ * - system clock source = pll (hext)
+ * - hext = 8000000
+ * - sclk = 192000000
+ * - ahbdiv = 1
+ * - ahbclk = 192000000
+ * - apb2div = 1
+ * - apb2clk = 192000000
+ * - apb1div = 1
+ * - apb1clk = 192000000
+ * - pll_ns = 96
+ * - pll_ms = 1
+ * - pll_fp = 4
+ * @param none
+ * @retval none
+ */
+void system_clock_config(void)
+{
+ /* reset crm */
+ crm_reset();
+
+ /* set the flash clock divider */
+ flash_psr_set(FLASH_WAIT_CYCLE_5);
+
+ /* enable pwc periph clock */
+ crm_periph_clock_enable(CRM_PWC_PERIPH_CLOCK, TRUE);
+
+ /* config ldo voltage */
+ pwc_ldo_output_voltage_set(PWC_LDO_OUTPUT_1V3);
+
+ crm_clock_source_enable(CRM_CLOCK_SOURCE_HEXT, TRUE);
+
+ /* wait till hext is ready */
+ while(crm_hext_stable_wait() == ERROR)
+ {
+ }
+
+ /* config pll clock resource */
+ crm_pll_config(CRM_PLL_SOURCE_HEXT, 96, 1, CRM_PLL_FP_4);
+
+ /* config pllu divider */
+ crm_pllu_div_set(CRM_PLL_FU_16);
+
+ /* pllu enable */
+ crm_pllu_output_set(TRUE);
+
+ /* enable pll */
+ crm_clock_source_enable(CRM_CLOCK_SOURCE_PLL, TRUE);
+
+ /* wait till pll is ready */
+ while(crm_flag_get(CRM_PLL_STABLE_FLAG) != SET)
+ {
+ }
+
+ /* config ahbclk */
+ crm_ahb_div_set(CRM_AHB_DIV_1);
+
+ /* config apb3clk, the maximum frequency of APB3 clock is 90 MHz */
+ crm_apb3_div_set(CRM_APB3_DIV_4);
+
+ /* config apb2clk, the maximum frequency of APB2 clock is 192 MHz */
+ crm_apb2_div_set(CRM_APB2_DIV_1);
+
+ /* config apb1clk, the maximum frequency of APB1 clock is 192 MHz */
+ crm_apb1_div_set(CRM_APB1_DIV_1);
+
+ /* enable auto step mode */
+ crm_auto_step_mode_enable(TRUE);
+
+ /* select pll as system clock source */
+ crm_sysclk_switch(CRM_SCLK_PLL);
+
+ /* wait till pll is used as system clock source */
+ while(crm_sysclk_switch_status_get() != CRM_SCLK_PLL)
+ {
+ }
+
+ /* disable auto step mode */
+ crm_auto_step_mode_enable(FALSE);
+
+ /* update system_core_clock global variable */
+ system_core_clock_update();
+}
diff --git a/hw/bsp/at32f45x/at32f45x_clock.h b/hw/bsp/at32f45x/at32f45x_clock.h
new file mode 100644
index 000000000..a372a605b
--- /dev/null
+++ b/hw/bsp/at32f45x/at32f45x_clock.h
@@ -0,0 +1,44 @@
+/**
+ **************************************************************************
+ * @file at32f45x_clock.h
+ * @brief header file of clock program
+ **************************************************************************
+ *
+ * Copyright (c) 2025, Artery Technology, All rights reserved.
+ *
+ * The software Board Support Package (BSP) that is made available to
+ * download from Artery official website is the copyrighted work of Artery.
+ * Artery authorizes customers to use, copy, and distribute the BSP
+ * software and its related documentation for the purpose of design and
+ * development in conjunction with Artery microcontrollers. Use of the
+ * software is governed by this copyright notice and the following disclaimer.
+ *
+ * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
+ * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
+ * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
+ * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
+ * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
+ *
+ **************************************************************************
+ */
+
+/* define to prevent recursive inclusion -------------------------------------*/
+#ifndef __AT32F45x_CLOCK_H
+#define __AT32F45x_CLOCK_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* includes ------------------------------------------------------------------*/
+#include "at32f45x.h"
+
+/* exported functions ------------------------------------------------------- */
+void system_clock_config(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/hw/bsp/at32f45x/at32f45x_conf.h b/hw/bsp/at32f45x/at32f45x_conf.h
new file mode 100644
index 000000000..90182437f
--- /dev/null
+++ b/hw/bsp/at32f45x/at32f45x_conf.h
@@ -0,0 +1,174 @@
+/**
+ **************************************************************************
+ * @file at32f45x_conf.h
+ * @brief at32f45x config header file
+ **************************************************************************
+ *
+ * Copyright (c) 2025, Artery Technology, All rights reserved.
+ *
+ * The software Board Support Package (BSP) that is made available to
+ * download from Artery official website is the copyrighted work of Artery.
+ * Artery authorizes customers to use, copy, and distribute the BSP
+ * software and its related documentation for the purpose of design and
+ * development in conjunction with Artery microcontrollers. Use of the
+ * software is governed by this copyright notice and the following disclaimer.
+ *
+ * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
+ * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
+ * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
+ * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
+ * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
+ *
+ **************************************************************************
+ */
+
+/* define to prevent recursive inclusion -------------------------------------*/
+#ifndef __AT32F45x_CONF_H
+#define __AT32F45x_CONF_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief in the following line adjust the value of high speed external crystal (hext)
+ * used in your application
+ *
+ * tip: to avoid modifying this file each time you need to use different hext, you
+ * can define the hext value in your toolchain compiler preprocessor.
+ *
+ */
+#if !defined HEXT_VALUE
+#define HEXT_VALUE ((uint32_t)8000000) /*!< value of the high speed external crystal in hz */
+#endif
+
+/**
+ * @brief in the following line adjust the high speed external crystal (hext) startup
+ * timeout value
+ */
+#define HEXT_STARTUP_TIMEOUT ((uint16_t)0x3000) /*!< time out for hext start up */
+#define HICK_VALUE ((uint32_t)8000000) /*!< value of the high speed internal clock in hz */
+#define LEXT_VALUE ((uint32_t)32768) /*!< value of the low speed external clock in hz */
+
+/* module define -------------------------------------------------------------*/
+#define ACC_MODULE_ENABLED
+#define ADC_MODULE_ENABLED
+#define AES_MODULE_ENABLED
+#define CAN_MODULE_ENABLED
+#define CRC_MODULE_ENABLED
+#define CRM_MODULE_ENABLED
+#define DAC_MODULE_ENABLED
+#define DEBUG_MODULE_ENABLED
+#define DMA_MODULE_ENABLED
+#define EMAC_MODULE_ENABLED
+#define ERTC_MODULE_ENABLED
+#define EXINT_MODULE_ENABLED
+#define FLASH_MODULE_ENABLED
+#define GPIO_MODULE_ENABLED
+#define I2C_MODULE_ENABLED
+#define MISC_MODULE_ENABLED
+#define PWC_MODULE_ENABLED
+#define QSPI_MODULE_ENABLED
+#define SCFG_MODULE_ENABLED
+#define SDIO_MODULE_ENABLED
+#define SPI_MODULE_ENABLED
+#define TMR_MODULE_ENABLED
+#define TRNG_MODULE_ENABLED
+#define USART_MODULE_ENABLED
+#define USB_MODULE_ENABLED
+#define WWDT_MODULE_ENABLED
+#define WDT_MODULE_ENABLED
+#define XMC_MODULE_ENABLED
+
+/* includes ------------------------------------------------------------------*/
+#ifdef ACC_MODULE_ENABLED
+#include "at32f45x_acc.h"
+#endif
+#ifdef ADC_MODULE_ENABLED
+#include "at32f45x_adc.h"
+#endif
+#ifdef AES_MODULE_ENABLED
+#include "at32f45x_aes.h"
+#endif
+#ifdef CAN_MODULE_ENABLED
+#include "at32f45x_can.h"
+#endif
+#ifdef CRC_MODULE_ENABLED
+#include "at32f45x_crc.h"
+#endif
+#ifdef CRM_MODULE_ENABLED
+#include "at32f45x_crm.h"
+#endif
+#ifdef DAC_MODULE_ENABLED
+#include "at32f45x_dac.h"
+#endif
+#ifdef DEBUG_MODULE_ENABLED
+#include "at32f45x_debug.h"
+#endif
+#ifdef DMA_MODULE_ENABLED
+#include "at32f45x_dma.h"
+#endif
+#ifdef EMAC_MODULE_ENABLED
+#include "at32f45x_emac.h"
+#endif
+#ifdef ERTC_MODULE_ENABLED
+#include "at32f45x_ertc.h"
+#endif
+#ifdef EXINT_MODULE_ENABLED
+#include "at32f45x_exint.h"
+#endif
+#ifdef FLASH_MODULE_ENABLED
+#include "at32f45x_flash.h"
+#endif
+#ifdef GPIO_MODULE_ENABLED
+#include "at32f45x_gpio.h"
+#endif
+#ifdef I2C_MODULE_ENABLED
+#include "at32f45x_i2c.h"
+#endif
+#ifdef MISC_MODULE_ENABLED
+#include "at32f45x_misc.h"
+#endif
+#ifdef PWC_MODULE_ENABLED
+#include "at32f45x_pwc.h"
+#endif
+#ifdef QSPI_MODULE_ENABLED
+#include "at32f45x_qspi.h"
+#endif
+#ifdef SCFG_MODULE_ENABLED
+#include "at32f45x_scfg.h"
+#endif
+#ifdef SDIO_MODULE_ENABLED
+#include "at32f45x_sdio.h"
+#endif
+#ifdef SPI_MODULE_ENABLED
+#include "at32f45x_spi.h"
+#endif
+#ifdef TMR_MODULE_ENABLED
+#include "at32f45x_tmr.h"
+#endif
+#ifdef TRNG_MODULE_ENABLED
+#include "at32f45x_trng.h"
+#endif
+#ifdef USART_MODULE_ENABLED
+#include "at32f45x_usart.h"
+#endif
+#ifdef USB_MODULE_ENABLED
+#include "at32f45x_usb.h"
+#endif
+#ifdef WDT_MODULE_ENABLED
+#include "at32f45x_wdt.h"
+#endif
+#ifdef WWDT_MODULE_ENABLED
+#include "at32f45x_wwdt.h"
+#endif
+#ifdef XMC_MODULE_ENABLED
+#include "at32f45x_xmc.h"
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/hw/bsp/at32f45x/at32f45x_int.c b/hw/bsp/at32f45x/at32f45x_int.c
new file mode 100644
index 000000000..b3ba6ad9c
--- /dev/null
+++ b/hw/bsp/at32f45x/at32f45x_int.c
@@ -0,0 +1,100 @@
+/**
+ **************************************************************************
+ * @file at32f45x_int.c
+ * @brief main interrupt service routines.
+ **************************************************************************
+ *
+ * Copyright (c) 2025, Artery Technology, All rights reserved.
+ *
+ * The software Board Support Package (BSP) that is made available to
+ * download from Artery official website is the copyrighted work of Artery.
+ * Artery authorizes customers to use, copy, and distribute the BSP
+ * software and its related documentation for the purpose of design and
+ * development in conjunction with Artery microcontrollers. Use of the
+ * software is governed by this copyright notice and the following disclaimer.
+ *
+ * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
+ * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
+ * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
+ * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
+ * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
+ *
+ **************************************************************************
+ */
+
+/* includes ------------------------------------------------------------------*/
+#include "at32f45x_int.h"
+
+/** @addtogroup AT32F45X_BSP
+ * @{
+ */
+
+/** @addtogroup AT32F45X_USB_Device_Keyboard
+ * @{
+ */
+
+/**
+ * @brief this function handles nmi exception.
+ * @param none
+ * @retval none
+ */
+void NMI_Handler(void)
+{
+}
+
+/**
+ * @brief this function handles memory manage exception.
+ * @param none
+ * @retval none
+ */
+void MemManage_Handler(void)
+{
+ /* go to infinite loop when memory manage exception occurs */
+ while(1)
+ {
+ }
+}
+
+/**
+ * @brief this function handles bus fault exception.
+ * @param none
+ * @retval none
+ */
+void BusFault_Handler(void)
+{
+ /* go to infinite loop when bus fault exception occurs */
+ while(1)
+ {
+ }
+}
+
+/**
+ * @brief this function handles usage fault exception.
+ * @param none
+ * @retval none
+ */
+void UsageFault_Handler(void)
+{
+ /* go to infinite loop when usage fault exception occurs */
+ while(1)
+ {
+ }
+}
+
+/**
+ * @brief this function handles debug monitor exception.
+ * @param none
+ * @retval none
+ */
+void DebugMon_Handler(void)
+{
+}
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
diff --git a/hw/bsp/at32f45x/at32f45x_int.h b/hw/bsp/at32f45x/at32f45x_int.h
new file mode 100644
index 000000000..3a2667e9d
--- /dev/null
+++ b/hw/bsp/at32f45x/at32f45x_int.h
@@ -0,0 +1,59 @@
+/**
+ **************************************************************************
+ * @file at32f45x_int.h
+ * @brief header file of main interrupt service routines.
+ **************************************************************************
+ *
+ * Copyright (c) 2025, Artery Technology, All rights reserved.
+ *
+ * The software Board Support Package (BSP) that is made available to
+ * download from Artery official website is the copyrighted work of Artery.
+ * Artery authorizes customers to use, copy, and distribute the BSP
+ * software and its related documentation for the purpose of design and
+ * development in conjunction with Artery microcontrollers. Use of the
+ * software is governed by this copyright notice and the following disclaimer.
+ *
+ * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
+ * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
+ * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
+ * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
+ * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
+ *
+ **************************************************************************
+ */
+
+/* define to prevent recursive inclusion -------------------------------------*/
+#ifndef __AT32F45x_INT_H
+#define __AT32F45x_INT_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* includes ------------------------------------------------------------------*/
+#include "at32f45x.h"
+
+/* exported types ------------------------------------------------------------*/
+/* exported constants --------------------------------------------------------*/
+/* exported macro ------------------------------------------------------------*/
+/* exported functions ------------------------------------------------------- */
+
+void NMI_Handler(void);
+void HardFault_Handler(void);
+void MemManage_Handler(void);
+void BusFault_Handler(void);
+void UsageFault_Handler(void);
+void SVC_Handler(void);
+void DebugMon_Handler(void);
+void PendSV_Handler(void);
+void SysTick_Handler(void);
+
+void OTGFS1_IRQHandler(void);
+void OTGFS1_WKUP_IRQHandler(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/hw/bsp/at32f45x/boards/at_start_f455/board.cmake b/hw/bsp/at32f45x/boards/at_start_f455/board.cmake
new file mode 100644
index 000000000..f06f9599e
--- /dev/null
+++ b/hw/bsp/at32f45x/boards/at_start_f455/board.cmake
@@ -0,0 +1,8 @@
+set(MCU_VARIANT AT32F455ZET7)
+set(MCU_LINKER_NAME AT32F455xE)
+
+set(JLINK_DEVICE ${MCU_VARIANT})
+
+function(update_board TARGET)
+ target_compile_definitions(${TARGET} PUBLIC ${MCU_VARIANT})
+endfunction()
diff --git a/hw/bsp/at32f45x/boards/at_start_f455/board.h b/hw/bsp/at32f45x/boards/at_start_f455/board.h
new file mode 100644
index 000000000..64e27c016
--- /dev/null
+++ b/hw/bsp/at32f45x/boards/at_start_f455/board.h
@@ -0,0 +1,96 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2020, 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: AT-START-F455
+ url: https://www.arterychip.com/en/product/AT32F455.jsp
+*/
+
+#ifndef BOARD_H_
+#define BOARD_H_
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+#define USB_VBUS_IGNORE
+
+// LED
+#define LED_PORT GPIOD
+#define LED_PIN GPIO_PINS_13
+#define LED_STATE_ON 0 // Active Low
+#define LED_GPIO_CLK_EN() crm_periph_clock_enable(CRM_GPIOD_PERIPH_CLOCK, TRUE)
+
+// Button
+#define BUTTON_PORT GPIOA
+#define BUTTON_PIN GPIO_PINS_0
+#define BUTTON_STATE_ACTIVE 1
+#define BUTTON_GPIO_CLK_EN() crm_periph_clock_enable(CRM_GPIOA_PERIPH_CLOCK, TRUE)
+
+// UART
+#define PRINT_UART USART1
+#define PRINT_UART_CRM_CLK CRM_USART1_PERIPH_CLOCK
+#define PRINT_UART_TX_PIN GPIO_PINS_9
+#define PRINT_UART_TX_GPIO GPIOA
+#define PRINT_UART_TX_GPIO_CRM_CLK CRM_GPIOA_PERIPH_CLOCK
+#define PRINT_UART_TX_PIN_SOURCE GPIO_PINS_SOURCE9
+#define PRINT_UART_TX_PIN_MUX_NUM GPIO_MUX_7
+
+//USB
+#define USB_ID 0
+#define OTG_CLOCK CRM_OTGFS1_PERIPH_CLOCK
+#define OTG_IRQ OTGFS1_IRQn
+#define OTG_IRQ_HANDLER OTGFS1_IRQHandler
+#define OTG_WKUP_IRQ OTGFS1_WKUP_IRQn
+#define OTG_WKUP_HANDLER OTGFS1_WKUP_IRQHandler
+#define OTG_WKUP_EXINT_LINE EXINT_LINE_18
+#define OTG_PIN_GPIO GPIOA
+#define OTG_PIN_GPIO_CLOCK CRM_GPIOA_PERIPH_CLOCK
+#define OTG_PIN_DP GPIO_PINS_12
+#define OTG_PIN_DP_SOURCE GPIO_PINS_SOURCE12
+#define OTG_PIN_DM GPIO_PINS_11
+#define OTG_PIN_DM_SOURCE GPIO_PINS_SOURCE11
+#define OTG_PIN_VBUS GPIO_PINS_9
+#define OTG_PIN_VBUS_SOURCE GPIO_PINS_SOURCE9
+#define OTG_PIN_ID GPIO_PINS_10
+#define OTG_PIN_ID_SOURCE GPIO_PINS_SOURCE10
+#define OTG_PIN_SOF_GPIO GPIOA
+#define OTG_PIN_SOF_GPIO_CLOCK CRM_GPIOA_PERIPH_CLOCK
+#define OTG_PIN_SOF GPIO_PINS_8
+#define OTG_PIN_SOF_SOURCE GPIO_PINS_SOURCE8
+#define OTG_PIN_MUX GPIO_MUX_10
+
+//Vbus
+static inline void board_vbus_sense_init(void)
+{
+ *(int*)(0x50000038) |= (1<<21);
+}
+
+#ifdef __cplusplus
+ }
+#endif
+
+#endif /* BOARD_H_ */
diff --git a/hw/bsp/at32f45x/boards/at_start_f455/board.mk b/hw/bsp/at32f45x/boards/at_start_f455/board.mk
new file mode 100644
index 000000000..7c24ad288
--- /dev/null
+++ b/hw/bsp/at32f45x/boards/at_start_f455/board.mk
@@ -0,0 +1,7 @@
+MCU_VARIANT = AT32F455ZET7
+MCU_LINKER_NAME = AT32F455xE
+
+JLINK_DEVICE = ${MCU_VARIANT}
+
+CFLAGS += \
+ -D${MCU_VARIANT}
diff --git a/hw/bsp/at32f45x/boards/at_start_f456/board.cmake b/hw/bsp/at32f45x/boards/at_start_f456/board.cmake
new file mode 100644
index 000000000..a5048d3b1
--- /dev/null
+++ b/hw/bsp/at32f45x/boards/at_start_f456/board.cmake
@@ -0,0 +1,8 @@
+set(MCU_VARIANT AT32F456ZET7)
+set(MCU_LINKER_NAME AT32F456xE)
+
+set(JLINK_DEVICE ${MCU_VARIANT})
+
+function(update_board TARGET)
+ target_compile_definitions(${TARGET} PUBLIC ${MCU_VARIANT})
+endfunction()
diff --git a/hw/bsp/at32f45x/boards/at_start_f456/board.h b/hw/bsp/at32f45x/boards/at_start_f456/board.h
new file mode 100644
index 000000000..d3d734a9b
--- /dev/null
+++ b/hw/bsp/at32f45x/boards/at_start_f456/board.h
@@ -0,0 +1,96 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2020, 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: AT-START-F456
+ url: https://www.arterychip.com/en/product/AT32F456.jsp
+*/
+
+#ifndef BOARD_H_
+#define BOARD_H_
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+#define USB_VBUS_IGNORE
+
+// LED
+#define LED_PORT GPIOD
+#define LED_PIN GPIO_PINS_13
+#define LED_STATE_ON 0 // Active Low
+#define LED_GPIO_CLK_EN() crm_periph_clock_enable(CRM_GPIOD_PERIPH_CLOCK, TRUE)
+
+// Button
+#define BUTTON_PORT GPIOA
+#define BUTTON_PIN GPIO_PINS_0
+#define BUTTON_STATE_ACTIVE 1
+#define BUTTON_GPIO_CLK_EN() crm_periph_clock_enable(CRM_GPIOA_PERIPH_CLOCK, TRUE)
+
+// UART
+#define PRINT_UART USART1
+#define PRINT_UART_CRM_CLK CRM_USART1_PERIPH_CLOCK
+#define PRINT_UART_TX_PIN GPIO_PINS_9
+#define PRINT_UART_TX_GPIO GPIOA
+#define PRINT_UART_TX_GPIO_CRM_CLK CRM_GPIOA_PERIPH_CLOCK
+#define PRINT_UART_TX_PIN_SOURCE GPIO_PINS_SOURCE9
+#define PRINT_UART_TX_PIN_MUX_NUM GPIO_MUX_7
+
+//USB
+#define USB_ID 0
+#define OTG_CLOCK CRM_OTGFS1_PERIPH_CLOCK
+#define OTG_IRQ OTGFS1_IRQn
+#define OTG_IRQ_HANDLER OTGFS1_IRQHandler
+#define OTG_WKUP_IRQ OTGFS1_WKUP_IRQn
+#define OTG_WKUP_HANDLER OTGFS1_WKUP_IRQHandler
+#define OTG_WKUP_EXINT_LINE EXINT_LINE_18
+#define OTG_PIN_GPIO GPIOA
+#define OTG_PIN_GPIO_CLOCK CRM_GPIOA_PERIPH_CLOCK
+#define OTG_PIN_DP GPIO_PINS_12
+#define OTG_PIN_DP_SOURCE GPIO_PINS_SOURCE12
+#define OTG_PIN_DM GPIO_PINS_11
+#define OTG_PIN_DM_SOURCE GPIO_PINS_SOURCE11
+#define OTG_PIN_VBUS GPIO_PINS_9
+#define OTG_PIN_VBUS_SOURCE GPIO_PINS_SOURCE9
+#define OTG_PIN_ID GPIO_PINS_10
+#define OTG_PIN_ID_SOURCE GPIO_PINS_SOURCE10
+#define OTG_PIN_SOF_GPIO GPIOA
+#define OTG_PIN_SOF_GPIO_CLOCK CRM_GPIOA_PERIPH_CLOCK
+#define OTG_PIN_SOF GPIO_PINS_8
+#define OTG_PIN_SOF_SOURCE GPIO_PINS_SOURCE8
+#define OTG_PIN_MUX GPIO_MUX_10
+
+//Vbus
+static inline void board_vbus_sense_init(void)
+{
+ *(int*)(0x50000038) |= (1<<21);
+}
+
+#ifdef __cplusplus
+ }
+#endif
+
+#endif /* BOARD_H_ */
diff --git a/hw/bsp/at32f45x/boards/at_start_f456/board.mk b/hw/bsp/at32f45x/boards/at_start_f456/board.mk
new file mode 100644
index 000000000..596d99d61
--- /dev/null
+++ b/hw/bsp/at32f45x/boards/at_start_f456/board.mk
@@ -0,0 +1,7 @@
+MCU_VARIANT = AT32F456ZET7
+MCU_LINKER_NAME = AT32F456xE
+
+JLINK_DEVICE = ${MCU_VARIANT}
+
+CFLAGS += \
+ -D${MCU_VARIANT}
diff --git a/hw/bsp/at32f45x/boards/at_start_f457/board.cmake b/hw/bsp/at32f45x/boards/at_start_f457/board.cmake
new file mode 100644
index 000000000..c8cd886be
--- /dev/null
+++ b/hw/bsp/at32f45x/boards/at_start_f457/board.cmake
@@ -0,0 +1,8 @@
+set(MCU_VARIANT AT32F457ZET7)
+set(MCU_LINKER_NAME AT32F457xE)
+
+set(JLINK_DEVICE ${MCU_VARIANT})
+
+function(update_board TARGET)
+ target_compile_definitions(${TARGET} PUBLIC ${MCU_VARIANT})
+endfunction()
diff --git a/hw/bsp/at32f45x/boards/at_start_f457/board.h b/hw/bsp/at32f45x/boards/at_start_f457/board.h
new file mode 100644
index 000000000..2216b1ed3
--- /dev/null
+++ b/hw/bsp/at32f45x/boards/at_start_f457/board.h
@@ -0,0 +1,96 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2020, 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: AT-START-F457
+ url: https://www.arterychip.com/en/product/AT32F457.jsp
+*/
+
+#ifndef BOARD_H_
+#define BOARD_H_
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+#define USB_VBUS_IGNORE
+
+// LED
+#define LED_PORT GPIOD
+#define LED_PIN GPIO_PINS_13
+#define LED_STATE_ON 0 // Active Low
+#define LED_GPIO_CLK_EN() crm_periph_clock_enable(CRM_GPIOD_PERIPH_CLOCK, TRUE)
+
+// Button
+#define BUTTON_PORT GPIOA
+#define BUTTON_PIN GPIO_PINS_0
+#define BUTTON_STATE_ACTIVE 1
+#define BUTTON_GPIO_CLK_EN() crm_periph_clock_enable(CRM_GPIOA_PERIPH_CLOCK, TRUE)
+
+// UART
+#define PRINT_UART USART1
+#define PRINT_UART_CRM_CLK CRM_USART1_PERIPH_CLOCK
+#define PRINT_UART_TX_PIN GPIO_PINS_9
+#define PRINT_UART_TX_GPIO GPIOA
+#define PRINT_UART_TX_GPIO_CRM_CLK CRM_GPIOA_PERIPH_CLOCK
+#define PRINT_UART_TX_PIN_SOURCE GPIO_PINS_SOURCE9
+#define PRINT_UART_TX_PIN_MUX_NUM GPIO_MUX_7
+
+//USB
+#define USB_ID 0
+#define OTG_CLOCK CRM_OTGFS1_PERIPH_CLOCK
+#define OTG_IRQ OTGFS1_IRQn
+#define OTG_IRQ_HANDLER OTGFS1_IRQHandler
+#define OTG_WKUP_IRQ OTGFS1_WKUP_IRQn
+#define OTG_WKUP_HANDLER OTGFS1_WKUP_IRQHandler
+#define OTG_WKUP_EXINT_LINE EXINT_LINE_18
+#define OTG_PIN_GPIO GPIOA
+#define OTG_PIN_GPIO_CLOCK CRM_GPIOA_PERIPH_CLOCK
+#define OTG_PIN_DP GPIO_PINS_12
+#define OTG_PIN_DP_SOURCE GPIO_PINS_SOURCE12
+#define OTG_PIN_DM GPIO_PINS_11
+#define OTG_PIN_DM_SOURCE GPIO_PINS_SOURCE11
+#define OTG_PIN_VBUS GPIO_PINS_9
+#define OTG_PIN_VBUS_SOURCE GPIO_PINS_SOURCE9
+#define OTG_PIN_ID GPIO_PINS_10
+#define OTG_PIN_ID_SOURCE GPIO_PINS_SOURCE10
+#define OTG_PIN_SOF_GPIO GPIOA
+#define OTG_PIN_SOF_GPIO_CLOCK CRM_GPIOA_PERIPH_CLOCK
+#define OTG_PIN_SOF GPIO_PINS_8
+#define OTG_PIN_SOF_SOURCE GPIO_PINS_SOURCE8
+#define OTG_PIN_MUX GPIO_MUX_10
+
+//Vbus
+static inline void board_vbus_sense_init(void)
+{
+ *(int*)(0x50000038) |= (1<<21);
+}
+
+#ifdef __cplusplus
+ }
+#endif
+
+#endif /* BOARD_H_ */
diff --git a/hw/bsp/at32f45x/boards/at_start_f457/board.mk b/hw/bsp/at32f45x/boards/at_start_f457/board.mk
new file mode 100644
index 000000000..4cb4adad5
--- /dev/null
+++ b/hw/bsp/at32f45x/boards/at_start_f457/board.mk
@@ -0,0 +1,7 @@
+MCU_VARIANT = AT32F457ZET7
+MCU_LINKER_NAME = AT32F457xE
+
+JLINK_DEVICE = ${MCU_VARIANT}
+
+CFLAGS += \
+ -D${MCU_VARIANT}
diff --git a/hw/bsp/at32f45x/family.c b/hw/bsp/at32f45x/family.c
new file mode 100644
index 000000000..0593e5115
--- /dev/null
+++ b/hw/bsp/at32f45x/family.c
@@ -0,0 +1,258 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2019 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:
+ manufacturer: Artery
+*/
+
+#include "at32f45x_clock.h"
+#include "at32f45x_int.h"
+#include "board.h"
+#include "bsp/board_api.h"
+
+void usb_clock48m_select(usb_clk48_s clk_s);
+void led_and_button_init(void);
+void uart_print_init(uint32_t baudrate);
+//--------------------------------------------------------------------+
+// Forward USB interrupt events to TinyUSB IRQ Handler
+//--------------------------------------------------------------------+
+void OTGFS1_IRQHandler(void) {
+ tusb_int_handler(0, true);
+}
+void OTGFS1_WKUP_IRQHandler(void) {
+ tusb_int_handler(0, true);
+}
+
+void board_init(void) {
+ /* config nvic priority group */
+ nvic_priority_group_config(NVIC_PRIORITY_GROUP_4);
+
+ /* config system clock */
+ system_clock_config();
+
+ /* enable usb clock */
+ crm_periph_clock_enable(OTG_CLOCK, TRUE);
+
+ /* select usb 48m clcok source */
+ usb_clock48m_select(USB_CLK_HEXT);
+
+ /* vbus ignore */
+ board_vbus_sense_init();
+
+ /* configure systick */
+ systick_clock_source_config(SYSTICK_CLOCK_SOURCE_AHBCLK_NODIV);
+ SysTick_Config(system_core_clock / 1000);
+#if CFG_TUSB_OS == OPT_OS_FREERTOS
+ // If freeRTOS is used, IRQ priority is limit by max syscall ( smaller is higher )
+ NVIC_SetPriority(OTG_IRQ, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY);
+#endif
+
+/* otgfs use vbus pin */
+#ifndef USB_VBUS_IGNORE
+ gpio_init_type gpio_init_struct;
+ crm_periph_clock_enable(OTG_PIN_GPIO_CLOCK, TRUE);
+ gpio_default_para_init(&gpio_init_struct);
+ gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
+ gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
+ gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
+ gpio_init_struct.gpio_pins = OTG_PIN_VBUS;
+ gpio_init_struct.gpio_pull = GPIO_PULL_DOWN;
+ gpio_pin_mux_config(OTG_PIN_GPIO, OTG_PIN_VBUS_SOURCE, OTG_PIN_MUX);
+ gpio_init(OTG_PIN_GPIO, &gpio_init_struct);
+#endif
+
+ /* config led and key */
+ led_and_button_init();
+
+ /* config usart printf */
+ uart_print_init(115200);
+ printf("usart printf config success!\r\n");
+}
+
+//--------------------------------------------------------------------+
+// Board porting API
+//--------------------------------------------------------------------+
+/**
+ * @brief usb 48M clock select
+ * @param clk_s:USB_CLK_HICK, USB_CLK_HEXT
+ * @retval none
+ */
+void usb_clock48m_select(usb_clk48_s clk_s)
+{
+ if(clk_s == USB_CLK_HICK)
+ {
+ crm_usb_clock_source_select(CRM_USB_CLOCK_SOURCE_HICK);
+
+ /* enable the acc calibration ready interrupt */
+ crm_periph_clock_enable(CRM_ACC_PERIPH_CLOCK, TRUE);
+
+ /* update the c1\c2\c3 value */
+ acc_write_c1(7980);
+ acc_write_c2(8000);
+ acc_write_c3(8020);
+
+ /* open acc calibration */
+ acc_calibration_mode_enable(ACC_CAL_HICKTRIM, TRUE);
+ }
+ else
+ {
+ crm_usb_clock_source_select(CRM_USB_CLOCK_SOURCE_PLLU);
+ }
+}
+
+void uart_print_init(uint32_t baudrate) {
+ gpio_init_type gpio_init_struct;
+ /* enable the uart and gpio clock */
+ crm_periph_clock_enable(PRINT_UART_CRM_CLK, TRUE);
+ crm_periph_clock_enable(PRINT_UART_TX_GPIO_CRM_CLK, TRUE);
+ gpio_default_para_init(&gpio_init_struct);
+ /* configure the uart tx pin */
+ gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
+ gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
+ gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
+ gpio_init_struct.gpio_pins = PRINT_UART_TX_PIN;
+ gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
+ gpio_init(PRINT_UART_TX_GPIO, &gpio_init_struct);
+ gpio_pin_mux_config(PRINT_UART_TX_GPIO, PRINT_UART_TX_PIN_SOURCE, PRINT_UART_TX_PIN_MUX_NUM);
+ /* configure uart param */
+ usart_init(PRINT_UART, baudrate, USART_DATA_8BITS, USART_STOP_1_BIT);
+ usart_transmitter_enable(PRINT_UART, TRUE);
+ usart_enable(PRINT_UART, TRUE);
+}
+
+void led_and_button_init(void) {
+ /* LED */
+ gpio_init_type gpio_led_init_struct;
+ /* enable the led clock */
+ LED_GPIO_CLK_EN();
+ /* set default parameter */
+ gpio_default_para_init(&gpio_led_init_struct);
+ /* configure the led gpio */
+ gpio_led_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
+ gpio_led_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
+ gpio_led_init_struct.gpio_mode = GPIO_MODE_OUTPUT;
+ gpio_led_init_struct.gpio_pins = LED_PIN;
+ gpio_led_init_struct.gpio_pull = GPIO_PULL_NONE;
+ gpio_init(LED_PORT, &gpio_led_init_struct);
+ /* Button */
+ gpio_init_type gpio_button_init_struct;
+ /* enable the button clock */
+ BUTTON_GPIO_CLK_EN();
+ /* set default parameter */
+ gpio_default_para_init(&gpio_button_init_struct);
+ /* configure the button gpio */
+ gpio_button_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
+ gpio_button_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
+ gpio_button_init_struct.gpio_mode = GPIO_MODE_INPUT;
+ gpio_button_init_struct.gpio_pins = BUTTON_PIN;
+ gpio_button_init_struct.gpio_pull = GPIO_PULL_DOWN;
+ gpio_init(BUTTON_PORT, &gpio_button_init_struct);
+}
+
+void board_led_write(bool state) {
+ gpio_bits_write(LED_PORT, LED_PIN, state ^ (!LED_STATE_ON));
+}
+
+uint32_t board_button_read(void) {
+ return gpio_input_data_bit_read(BUTTON_PORT, BUTTON_PIN);
+}
+
+size_t board_get_unique_id(uint8_t id[], size_t max_len) {
+ (void) max_len;
+ volatile uint32_t *at32_uuid = ((volatile uint32_t *) 0x1FFFF7E8);
+ uint32_t *id32 = (uint32_t *) (uintptr_t) id;
+ uint8_t const len = 12;
+
+ id32[0] = at32_uuid[0];
+ id32[1] = at32_uuid[1];
+ id32[2] = at32_uuid[2];
+
+ return len;
+}
+
+int board_uart_read(uint8_t *buf, int len) {
+ (void) buf;
+ (void) len;
+ return 0;
+}
+
+int board_uart_write(void const *buf, int len) {
+#if CFG_TUSB_OS == OPT_OS_NONE
+ int txsize = len;
+ uint16_t timeout = 0xffff;
+ while (txsize--) {
+ while (usart_flag_get(PRINT_UART, USART_TDBE_FLAG) == RESET) {
+ timeout--;
+ if (timeout == 0) {
+ return 0;
+ }
+ }
+ PRINT_UART->dt = (*((uint8_t const *) buf) & 0x01FF);
+ buf++;
+ }
+ return len;
+#else
+ (void) buf;
+ (void) len;
+ return 0;
+#endif
+}
+
+#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;
+}
+
+void SVC_Handler(void) {
+}
+
+void PendSV_Handler(void) {
+}
+#endif
+
+void HardFault_Handler(void) {
+ __asm("BKPT #0\n");
+}
+
+// Required by __libc_init_array in startup code if we are compiling using
+// -nostdlib/-nostartfiles.
+void _init(void);
+void _init(void) {
+}
+
+#ifdef USE_FULL_ASSERT
+void assert_failed(const char *file, uint32_t line) {
+ /* USER CODE BEGIN 6 */
+ /* User can add his own implementation to report the file name and line number,
+ e.g.: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
+ /* USER CODE END 6 */
+}
+#endif /* USE_FULL_ASSERT */
diff --git a/hw/bsp/at32f45x/family.cmake b/hw/bsp/at32f45x/family.cmake
new file mode 100644
index 000000000..fe13347af
--- /dev/null
+++ b/hw/bsp/at32f45x/family.cmake
@@ -0,0 +1,97 @@
+include_guard()
+
+set(AT32_FAMILY at32f45x)
+set(AT32_SDK_LIB ${TOP}/hw/mcu/artery/${AT32_FAMILY}/libraries)
+
+string(TOUPPER ${AT32_FAMILY} AT32_FAMILY_UPPER)
+
+# include board specific
+include(${CMAKE_CURRENT_LIST_DIR}/boards/${BOARD}/board.cmake)
+
+# 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 ${AT32_FAMILY_UPPER} CACHE INTERNAL "")
+
+#------------------------------------
+# Startup & Linker script
+#------------------------------------
+set(STARTUP_FILE_GNU ${AT32_SDK_LIB}/cmsis/cm4/device_support/startup/gcc/startup_${AT32_FAMILY}.s)
+set(STARTUP_FILE_Clang ${STARTUP_FILE_GNU})
+set(STARTUP_FILE_IAR ${AT32_SDK_LIB}/cmsis/cm4/device_support/startup/iar/startup_${AT32_FAMILY}.s)
+if (NOT DEFINED LD_FILE_GNU)
+set(LD_FILE_GNU ${AT32_SDK_LIB}/cmsis/cm4/device_support/startup/gcc/linker/${MCU_LINKER_NAME}_FLASH.ld)
+endif ()
+set(LD_FILE_Clang ${LD_FILE_GNU})
+set(LD_FILE_IAR ${AT32_SDK_LIB}/cmsis/cm4/device_support/startup/iar/linker/${MCU_LINKER_NAME}.icf)
+
+#------------------------------------
+# BOARD_TARGET
+#------------------------------------
+function(family_add_board BOARD_TARGET)
+ add_library(${BOARD_TARGET} STATIC
+ ${AT32_SDK_LIB}/cmsis/cm4/device_support/system_${AT32_FAMILY}.c
+ ${AT32_SDK_LIB}/drivers/src/${AT32_FAMILY}_gpio.c
+ ${AT32_SDK_LIB}/drivers/src/${AT32_FAMILY}_misc.c
+ ${AT32_SDK_LIB}/drivers/src/${AT32_FAMILY}_usart.c
+ ${AT32_SDK_LIB}/drivers/src/${AT32_FAMILY}_acc.c
+ ${AT32_SDK_LIB}/drivers/src/${AT32_FAMILY}_crm.c
+ )
+ target_include_directories(${BOARD_TARGET} PUBLIC
+ ${CMAKE_CURRENT_FUNCTION_LIST_DIR}
+ ${AT32_SDK_LIB}/cmsis/cm4/core_support
+ ${AT32_SDK_LIB}/cmsis/cm4/device_support
+ ${AT32_SDK_LIB}/drivers/inc
+ )
+
+ update_board(${BOARD_TARGET})
+endfunction()
+
+#------------------------------------
+# Functions
+#------------------------------------
+function(family_configure_example TARGET RTOS)
+ family_configure_common(${TARGET} ${RTOS})
+ family_add_tinyusb(${TARGET} OPT_MCU_${AT32_FAMILY_UPPER})
+
+ target_sources(${TARGET} PUBLIC
+ ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/family.c
+ ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../board.c
+ ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/${AT32_FAMILY}_clock.c
+ ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/${AT32_FAMILY}_int.c
+ ${TOP}/src/portable/synopsys/dwc2/dcd_dwc2.c
+ ${TOP}/src/portable/synopsys/dwc2/hcd_dwc2.c
+ ${TOP}/src/portable/synopsys/dwc2/dwc2_common.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}"
+ -nostartfiles
+ --specs=nosys.specs --specs=nano.specs
+ )
+ elseif (CMAKE_C_COMPILER_ID STREQUAL "Clang")
+ target_link_options(${TARGET} PUBLIC
+ "LINKER:--script=${LD_FILE_Clang}"
+ )
+ elseif (CMAKE_C_COMPILER_ID STREQUAL "IAR")
+ target_link_options(${TARGET} PUBLIC
+ "LINKER:--config=${LD_FILE_IAR}"
+ )
+ endif ()
+
+ set_source_files_properties(${STARTUP_FILE_${CMAKE_C_COMPILER_ID}} PROPERTIES
+ SKIP_LINTING ON
+ COMPILE_OPTIONS -w)
+
+ # Flashing
+ family_add_bin_hex(${TARGET})
+ family_flash_jlink(${TARGET})
+endfunction()
diff --git a/hw/bsp/at32f45x/family.mk b/hw/bsp/at32f45x/family.mk
new file mode 100644
index 000000000..e42f27557
--- /dev/null
+++ b/hw/bsp/at32f45x/family.mk
@@ -0,0 +1,40 @@
+AT32_FAMILY = at32f45x
+AT32_SDK_LIB = hw/mcu/artery/${AT32_FAMILY}/libraries
+
+include $(TOP)/$(BOARD_PATH)/board.mk
+
+CPU_CORE ?= cortex-m4
+
+CFLAGS_GCC += \
+ -flto
+
+CFLAGS += \
+ -DCFG_TUSB_MCU=OPT_MCU_AT32F45X \
+
+LDFLAGS_GCC += \
+ -flto --specs=nosys.specs -nostdlib -nostartfiles
+
+SRC_C += \
+ src/portable/synopsys/dwc2/dcd_dwc2.c \
+ src/portable/synopsys/dwc2/hcd_dwc2.c \
+ src/portable/synopsys/dwc2/dwc2_common.c \
+ $(AT32_SDK_LIB)/drivers/src/${AT32_FAMILY}_gpio.c \
+ $(AT32_SDK_LIB)/drivers/src/${AT32_FAMILY}_misc.c \
+ $(AT32_SDK_LIB)/drivers/src/${AT32_FAMILY}_usart.c \
+ $(AT32_SDK_LIB)/drivers/src/${AT32_FAMILY}_crm.c \
+ $(AT32_SDK_LIB)/drivers/src/${AT32_FAMILY}_acc.c \
+ $(AT32_SDK_LIB)/cmsis/cm4/device_support/system_${AT32_FAMILY}.c
+
+INC += \
+ $(TOP)/$(BOARD_PATH) \
+ $(TOP)/$(AT32_SDK_LIB)/drivers/inc \
+ $(TOP)/$(AT32_SDK_LIB)/cmsis/cm4/core_support \
+ $(TOP)/$(AT32_SDK_LIB)/cmsis/cm4/device_support
+
+SRC_S_GCC += ${AT32_SDK_LIB}/cmsis/cm4/device_support/startup/gcc/startup_${AT32_FAMILY}.s
+SRC_S_IAR += ${AT32_SDK_LIB}/cmsis/cm4/device_support/startup/iar/startup_${AT32_FAMILY}.s
+
+LD_FILE_GCC ?= ${AT32_SDK_LIB}/cmsis/cm4/device_support/startup/gcc/linker/${MCU_LINKER_NAME}_FLASH.ld
+LD_FILE_IAR ?= ${AT32_SDK_LIB}/cmsis/cm4/device_support/startup/iar/linker/${MCU_LINKER_NAME}.icf
+
+flash: flash-atlink
diff --git a/hw/bsp/family_support.cmake b/hw/bsp/family_support.cmake
index baa8422fe..699afda92 100644
--- a/hw/bsp/family_support.cmake
+++ b/hw/bsp/family_support.cmake
@@ -238,6 +238,7 @@ function(family_add_bloaty TARGET)
COMMAND ${BLOATY_EXE} ${OPTION_LIST} $<TARGET_FILE:${TARGET}>
VERBATIM)
+ set_property(TARGET ${TARGET}-bloaty PROPERTY FOLDER ${TARGET})
# post build
# add_custom_command(TARGET ${TARGET} POST_BUILD
# COMMAND ${BLOATY_EXE} --csv ${OPTION_LIST} $<TARGET_FILE:${TARGET}> > ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_bloaty.csv
@@ -258,12 +259,103 @@ function(family_add_linkermap TARGET)
VERBATIM
)
+ set_property(TARGET ${TARGET}-linkermap PROPERTY FOLDER ${TARGET})
+
# post build
add_custom_command(TARGET ${TARGET} POST_BUILD
COMMAND python ${LINKERMAP_PY} ${OPTION_LIST} $<TARGET_FILE:${TARGET}>.map
VERBATIM)
endfunction()
+# Add membrowse target (installed with pip install membrowse)
+function(family_add_membrowse TARGET)
+ find_program(MEMBROWSE_EXE membrowse)
+ if (MEMBROWSE_EXE STREQUAL MEMBROWSE_EXE-NOTFOUND)
+ # force anyway, bash login shell will find it from pip install path
+ set(MEMBROWSE_EXE membrowse)
+ endif ()
+
+ set(OPTION "")
+ if (DEFINED MEMBROWSE_OPTION)
+ string(APPEND OPTION " ${MEMBROWSE_OPTION}")
+ endif ()
+
+ # For Ninja generator, extract all linker scripts from Ninja commands (with INCLUDE) and pass them to membrowse.
+ if (CMAKE_GENERATOR MATCHES "Ninja")
+ set(TARGET_ELF_PATH "$<TARGET_FILE_DIR:${TARGET}>/$<TARGET_FILE_NAME:${TARGET}>")
+ set(MEMBROWSE_LD_SCRIPTS_CMD
+ "ld_scripts=\"$(${CMAKE_MAKE_PROGRAM} -C ${CMAKE_BINARY_DIR} -t commands ${TARGET} | grep -oP '(?:-Wl,--script=|-T\\s*)\\K[A-Za-z0-9_./-]+\\.ld' | xargs)\"; \
+all_ld_scripts=\"\"; \
+pending_ld_scripts=\"$ld_scripts\"; \
+while [ -n \"$pending_ld_scripts\" ]; do \
+ next_pending=\"\"; \
+ for script in $pending_ld_scripts; do \
+ case \" $all_ld_scripts \" in *\" $script \"*) continue ;; esac; \
+ all_ld_scripts=\"$all_ld_scripts $script\"; \
+ script_dir=$(dirname \"$script\"); \
+ include_scripts=$(grep -hoP '^\\s*INCLUDE\\s+[<\"]?\\K[^\">[:space:]]+\\.ld' \"$script\" 2>/dev/null | xargs); \
+ for include_script in $include_scripts; do \
+ resolved_script=\"\"; \
+ if [ -f \"$include_script\" ]; then \
+ resolved_script=\"$include_script\"; \
+ elif [ -f \"$script_dir/$include_script\" ]; then \
+ resolved_script=\"$script_dir/$include_script\"; \
+ fi; \
+ if [ -n \"$resolved_script\" ]; then \
+ case \" $all_ld_scripts $next_pending \" in *\" $resolved_script \"*) ;; *) next_pending=\"$next_pending $resolved_script\" ;; esac; \
+ fi; \
+ done; \
+ done; \
+ pending_ld_scripts=\"$(echo \"$next_pending\" | xargs)\"; \
+done; \
+ld_scripts=\"$(echo \"$all_ld_scripts\" | xargs)\"")
+ set(MEMBROWSE_LD_DEFS_CMD
+ "ld_symbols=\"$(${CMAKE_MAKE_PROGRAM} -C ${CMAKE_BINARY_DIR} -t commands ${TARGET} | grep -oP '(?<=--defsym[=,])[^[:space:]]+' | xargs)\"; \
+ld_defs=\"\"; \
+for symbol in $ld_symbols; do \
+ ld_defs=\"$ld_defs --def $symbol\"; \
+done; \
+ld_defs=\"$(echo \"$ld_defs\" | xargs)\"")
+ set(MEMBROWSE_PREPARE_CMD
+ "if [ -f \"${TARGET_ELF_PATH}\" ]; then \
+ ${MEMBROWSE_LD_SCRIPTS_CMD}; \
+ ${MEMBROWSE_LD_DEFS_CMD}; \
+ if [ \"$MEMBROWSE_UPLOAD\" = \"1\" ]; then \
+ MEMBROWSE_CMD=\"${MEMBROWSE_EXE} report ${OPTION} \\\"${TARGET_ELF_PATH}\\\" \\\"$ld_scripts\\\" $ld_defs --upload --github --target-name ${BOARD}/${TARGET} --api-key $ENV{MEMBROWSE_API_KEY}\"; \
+ else \
+ MEMBROWSE_CMD=\"${MEMBROWSE_EXE} report ${OPTION} \\\"${TARGET_ELF_PATH}\\\" \\\"$ld_scripts\\\" $ld_defs\"; \
+ fi; \
+else \
+ if [ \"$MEMBROWSE_UPLOAD\" = \"1\" ]; then \
+ MEMBROWSE_CMD=\"${MEMBROWSE_EXE} report ${OPTION} --identical --upload --github --target-name ${BOARD}/${TARGET} --api-key $ENV{MEMBROWSE_API_KEY}\"; \
+ else \
+ MEMBROWSE_CMD=\"${MEMBROWSE_EXE} report ${OPTION} --identical\"; \
+ fi; \
+fi; \
+echo \"$MEMBROWSE_CMD\"")
+
+ add_custom_target(${TARGET}-membrowse
+ DEPENDS ${TARGET}
+ COMMAND ${CMAKE_COMMAND} -E env MEMBROWSE_UPLOAD=0 bash -lc "${MEMBROWSE_PREPARE_CMD}; eval \"$MEMBROWSE_CMD\""
+ VERBATIM
+ )
+ set_property(TARGET ${TARGET}-membrowse PROPERTY FOLDER ${TARGET})
+
+ add_custom_target(${TARGET}-membrowse-upload
+ COMMAND ${CMAKE_COMMAND} -E env MEMBROWSE_UPLOAD=1 bash -lc "${MEMBROWSE_PREPARE_CMD}; eval \"$MEMBROWSE_CMD\""
+ VERBATIM
+ )
+
+ if (NOT TARGET examples-membrowse-upload)
+ add_custom_target(examples-membrowse-upload)
+ endif ()
+ add_dependencies(examples-membrowse-upload ${TARGET}-membrowse-upload)
+
+ set_property(TARGET ${TARGET}-membrowse-upload PROPERTY FOLDER ${TARGET})
+ endif ()
+endfunction()
+
+
#-------------------------------------------------------------
# Common Target Configure
# Most families use these settings except rp2040 and espressif
@@ -377,6 +469,7 @@ function(family_configure_common TARGET RTOS)
# Analyze size with bloaty and linkermap
family_add_bloaty(${TARGET})
family_add_linkermap(${TARGET})
+ family_add_membrowse(${TARGET})
endif ()
# run size after build
@@ -508,6 +601,8 @@ exit"
COMMAND ${JLINKEXE} -device ${JLINK_DEVICE} ${OPTION_LIST} -if ${JLINK_IF} -JTAGConf -1,-1 -speed auto -CommandFile $<TARGET_FILE_DIR:${BINARY_TARGET}>/${BINARY_TARGET}.jlink
VERBATIM
)
+
+ set_property(TARGET ${NAME_TARGET}-jlink PROPERTY FOLDER ${TARGET})
endfunction()
@@ -521,6 +616,8 @@ function(family_flash_stlink TARGET)
DEPENDS ${TARGET}
COMMAND ${STM32_PROGRAMMER_CLI} --connect port=swd --write $<TARGET_FILE:${TARGET}> --go
)
+
+ set_property(TARGET ${TARGET}-stlink PROPERTY FOLDER ${TARGET})
endfunction()
@@ -534,6 +631,8 @@ function(family_flash_stflash TARGET)
DEPENDS ${TARGET}
COMMAND ${ST_FLASH} write $<TARGET_FILE_DIR:${TARGET}>/${TARGET}.bin 0x8000000
)
+
+ set_property(TARGET ${TARGET}-stflash PROPERTY FOLDER ${TARGET})
endfunction()
@@ -560,6 +659,8 @@ function(family_flash_openocd TARGET)
COMMAND ${OPENOCD} -c "tcl_port disabled; gdb_port disabled" ${OPTION_LIST} -c "init; halt; program $<TARGET_FILE:${TARGET}>" -c reset ${OPTION_LIST2} -c exit
VERBATIM
)
+
+ set_property(TARGET ${TARGET}-openocd PROPERTY FOLDER ${TARGET})
endfunction()
@@ -621,6 +722,8 @@ function(family_flash_wlink_rs TARGET)
DEPENDS ${TARGET}
COMMAND ${WLINK_RS} flash $<TARGET_FILE:${TARGET}>
)
+
+ set_property(TARGET ${TARGET}-wlink-rs PROPERTY FOLDER ${TARGET})
endfunction()
@@ -634,6 +737,8 @@ function(family_flash_pyocd TARGET)
DEPENDS ${TARGET}
COMMAND ${PYOCD} flash -t ${PYOCD_TARGET} $<TARGET_FILE:${TARGET}>
)
+
+ set_property(TARGET ${TARGET}-pyocd PROPERTY FOLDER ${TARGET})
endfunction()
@@ -643,6 +748,7 @@ function(family_flash_uf2 TARGET FAMILY_ID)
DEPENDS ${TARGET}
COMMAND python ${UF2CONV_PY} -f ${FAMILY_ID} --deploy $<TARGET_FILE_DIR:${TARGET}>/${TARGET}.uf2
)
+ set_property(TARGET ${TARGET}-uf2 PROPERTY FOLDER ${TARGET})
endfunction()
@@ -657,6 +763,8 @@ function(family_flash_teensy TARGET)
COMMAND ${CMAKE_OBJCOPY} -Oihex $<TARGET_FILE:${TARGET}> $<TARGET_FILE_DIR:${TARGET}>/${TARGET}.hex
COMMAND ${TEENSY_CLI} --mcu=${TEENSY_MCU} -w -s $<TARGET_FILE_DIR:${TARGET}>/${TARGET}.hex
)
+
+ set_property(TARGET ${TARGET}-teensy PROPERTY FOLDER ${TARGET})
endfunction()
@@ -675,6 +783,8 @@ function(family_flash_nxplink TARGET)
DEPENDS ${TARGET}
COMMAND ${LINKSERVER_PATH} flash ${NXPLINK_DEVICE} load $<TARGET_FILE:${TARGET}>
)
+
+ set_property(TARGET ${TARGET}-nxplink PROPERTY FOLDER ${TARGET})
endfunction()
@@ -688,6 +798,8 @@ function(family_flash_dfu_util TARGET OPTION)
COMMAND ${DFU_UTIL} -R -d ${DFU_UTIL_VID_PID} -a 0 -D $<TARGET_FILE_DIR:${TARGET}>/${TARGET}.bin
VERBATIM
)
+
+ set_property(TARGET ${TARGET}-dfu-util PROPERTY FOLDER ${TARGET})
endfunction()
function(family_flash_msp430flasher TARGET)
@@ -703,6 +815,8 @@ function(family_flash_msp430flasher TARGET)
COMMAND ${CMAKE_COMMAND} -E env LD_LIBRARY_PATH=${MSP430FLASHER_PARENT_DIR}
${MSP430FLASHER} -w $<TARGET_FILE_DIR:${TARGET}>/${TARGET}.hex -z [VCC]
)
+
+ set_property(TARGET ${TARGET}-msp430flasher PROPERTY FOLDER ${TARGET})
endfunction()
function(family_flash_uniflash TARGET)
@@ -717,6 +831,8 @@ function(family_flash_uniflash TARGET)
COMMAND ${DSLITE} ${UNIFLASH_OPTION} -f $<TARGET_FILE_DIR:${TARGET}>/${TARGET}.hex
VERBATIM
)
+
+ set_property(TARGET ${TARGET}-uniflash PROPERTY FOLDER ${TARGET})
endfunction()
#----------------------------------
diff --git a/hw/bsp/rp2040/family.cmake b/hw/bsp/rp2040/family.cmake
index 1602e35eb..82d0034a1 100644
--- a/hw/bsp/rp2040/family.cmake
+++ b/hw/bsp/rp2040/family.cmake
@@ -157,10 +157,12 @@ target_link_libraries(tinyusb_bsp INTERFACE
# tinyusb_additions will hold our extra settings for examples
add_library(tinyusb_additions INTERFACE)
+if (PICO_PLATFORM STREQUAL rp2040)
target_compile_definitions(tinyusb_additions INTERFACE
PICO_RP2040_USB_DEVICE_ENUMERATION_FIX=1
PICO_RP2040_USB_DEVICE_UFRAME_FIX=1
-)
+ )
+endif ()
if(LOGGER STREQUAL "RTT" OR LOGGER STREQUAL "rtt")
target_compile_definitions(tinyusb_additions INTERFACE
@@ -248,8 +250,10 @@ function(family_configure_target TARGET RTOS)
family_flash_openocd(${TARGET})
family_flash_jlink(${TARGET})
- # Generate linkermap target and post build. LINKERMAP_OPTION can be set with -D to change default options
+ # Generate linkermap target and post build. LINKERMAP_OPTION can be set with -D to change default options
+ family_add_bloaty(${TARGET})
family_add_linkermap(${TARGET})
+ family_add_membrowse(${TARGET})
endfunction()
diff --git a/hw/bsp/stm32f2/family.c b/hw/bsp/stm32f2/family.c
index 9c78cf7dd..d6a0cb827 100644
--- a/hw/bsp/stm32f2/family.c
+++ b/hw/bsp/stm32f2/family.c
@@ -31,7 +31,6 @@
#include "stm32f2xx_hal.h"
#include "bsp/board_api.h"
#include "board.h"
-
//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
@@ -105,9 +104,12 @@ void board_init(void) {
/* Enable USB FS Clocks */
__HAL_RCC_USB_OTG_FS_CLK_ENABLE();
+#if CFG_TUD_ENABLED
// Enable VBUS sense (B device) via pin PA9
- USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_NOVBUSSENS;
- USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBUSBSEN;
+ tud_configure_dwc2_t cfg = CFG_TUD_CONFIGURE_DWC2_DEFAULT;
+ cfg.vbus_sensing = true;
+ tud_configure(0, TUD_CFGID_DWC2, &cfg);
+#endif
}
//--------------------------------------------------------------------+
diff --git a/hw/bsp/stm32f4/boards/feather_stm32f405/board.h b/hw/bsp/stm32f4/boards/feather_stm32f405/board.h
index 11e976a42..2db42b98a 100644
--- a/hw/bsp/stm32f4/boards/feather_stm32f405/board.h
+++ b/hw/bsp/stm32f4/boards/feather_stm32f405/board.h
@@ -43,6 +43,8 @@
#define PINID_UART_TX 2
#define PINID_UART_RX 3
+#define VBUS_SENSE_EN 1
+
static board_pindef_t board_pindef[] = {
{ // LED
.port = GPIOC,
@@ -106,14 +108,6 @@ static inline void board_clock_init(void)
__HAL_RCC_USART3_CLK_ENABLE();
}
-static inline void board_vbus_sense_init(uint8_t rhport) {
- if (rhport == 0) {
- // Enable VBUS sense (B device) via pin PA9
- USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_NOVBUSSENS;
- USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBUSBSEN;
- }
-}
-
static inline void board_vbus_set(uint8_t rhport, bool state) {
(void) rhport; (void) state;
}
diff --git a/hw/bsp/stm32f4/boards/pyboardv11/board.h b/hw/bsp/stm32f4/boards/pyboardv11/board.h
index 9583a924b..319d2336a 100644
--- a/hw/bsp/stm32f4/boards/pyboardv11/board.h
+++ b/hw/bsp/stm32f4/boards/pyboardv11/board.h
@@ -43,6 +43,8 @@
#define PINID_UART_TX 2
#define PINID_UART_RX 3
+#define VBUS_SENSE_EN 1
+
static board_pindef_t board_pindef[] = {
{ // LED
.port = GPIOB,
@@ -106,14 +108,6 @@ static inline void board_clock_init(void)
__HAL_RCC_USART2_CLK_ENABLE();
}
-static inline void board_vbus_sense_init(uint8_t rhport) {
- if (rhport == 0) {
- // Enable VBUS sense (B device) via pin PA9
- USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_NOVBUSSENS;
- USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBUSBSEN;
- }
-}
-
static inline void board_vbus_set(uint8_t rhport, bool state) {
(void) rhport; (void) state;
}
diff --git a/hw/bsp/stm32f4/boards/stm32f401blackpill/board.h b/hw/bsp/stm32f4/boards/stm32f401blackpill/board.h
index 8a3fe8409..b69ebbeaf 100644
--- a/hw/bsp/stm32f4/boards/stm32f401blackpill/board.h
+++ b/hw/bsp/stm32f4/boards/stm32f401blackpill/board.h
@@ -44,6 +44,8 @@
#define PINID_UART_TX 2
#define PINID_UART_RX 3
+#define VBUS_SENSE_EN 0
+
static board_pindef_t board_pindef[] = {
{ // LED
.port = GPIOC,
@@ -107,15 +109,6 @@ static inline void board_clock_init(void)
__HAL_RCC_USART2_CLK_ENABLE();
}
-static inline void board_vbus_sense_init(uint8_t rhport) {
- // Blackpill doesn't use VBUS sense (B device) explicitly disable it
- if (rhport == 0) {
- USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_NOVBUSSENS;
- USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_VBUSBSEN;
- USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_VBUSASEN;
- }
-}
-
static inline void board_vbus_set(uint8_t rhport, bool state) {
(void) rhport; (void) state;
}
diff --git a/hw/bsp/stm32f4/boards/stm32f407blackvet/board.h b/hw/bsp/stm32f4/boards/stm32f407blackvet/board.h
index effbf2be8..ebefeb988 100644
--- a/hw/bsp/stm32f4/boards/stm32f407blackvet/board.h
+++ b/hw/bsp/stm32f4/boards/stm32f407blackvet/board.h
@@ -44,6 +44,8 @@
#define PINID_UART_TX 2
#define PINID_UART_RX 3
+#define VBUS_SENSE_EN 0
+
static board_pindef_t board_pindef[] = {
{ // LED
.port = GPIOA,
@@ -106,15 +108,6 @@ static inline void board_clock_init(void)
__HAL_RCC_USART2_CLK_ENABLE();
}
-static inline void board_vbus_sense_init(uint8_t rhport) {
- if (rhport == 0) {
- // Black F407VET6 doesn't use VBUS sense (B device) explicitly disable it
- USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_NOVBUSSENS;
- USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_VBUSBSEN;
- USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_VBUSASEN;
- }
-}
-
static inline void board_vbus_set(uint8_t rhport, bool state) {
(void) rhport; (void) state;
}
diff --git a/hw/bsp/stm32f4/boards/stm32f407disco/board.h b/hw/bsp/stm32f4/boards/stm32f407disco/board.h
index 19a029768..bcfa6059a 100644
--- a/hw/bsp/stm32f4/boards/stm32f407disco/board.h
+++ b/hw/bsp/stm32f4/boards/stm32f407disco/board.h
@@ -46,6 +46,8 @@
#define PINID_UART_RX 3
#define PINID_VBUS0_EN 4
+#define VBUS_SENSE_EN 1
+
static board_pindef_t board_pindef[] = {
{ // LED
.port = GPIOD,
@@ -114,14 +116,6 @@ static inline void board_clock_init(void)
__HAL_RCC_USART2_CLK_ENABLE();
}
-static inline void board_vbus_sense_init(uint8_t rhport) {
- if (rhport == 0) {
- // Enable VBUS sense (B device) via pin PA9
- USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_NOVBUSSENS;
- USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBUSBSEN;
- }
-}
-
static inline void board_vbus_set(uint8_t rhport, bool state) {
if (rhport == 0) {
board_pindef_t* pindef = &board_pindef[PINID_VBUS0_EN];
diff --git a/hw/bsp/stm32f4/boards/stm32f411blackpill/board.h b/hw/bsp/stm32f4/boards/stm32f411blackpill/board.h
index 61e5de70d..0faf6fe11 100644
--- a/hw/bsp/stm32f4/boards/stm32f411blackpill/board.h
+++ b/hw/bsp/stm32f4/boards/stm32f411blackpill/board.h
@@ -43,6 +43,8 @@
#define PINID_UART_TX 2
#define PINID_UART_RX 3
+#define VBUS_SENSE_EN 0
+
static board_pindef_t board_pindef[] = {
{ // LED
.port = GPIOC,
@@ -106,15 +108,6 @@ static inline void board_clock_init(void)
__HAL_RCC_USART2_CLK_ENABLE();
}
-static inline void board_vbus_sense_init(uint8_t rhport) {
- // Blackpill doesn't use VBUS sense (B device) explicitly disable it
- if (rhport == 0) {
- USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_NOVBUSSENS;
- USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_VBUSBSEN;
- USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_VBUSASEN;
- }
-}
-
static inline void board_vbus_set(uint8_t rhport, bool state) {
(void) rhport; (void) state;
}
diff --git a/hw/bsp/stm32f4/boards/stm32f411disco/board.h b/hw/bsp/stm32f4/boards/stm32f411disco/board.h
index d7b02e79d..1a289dfb5 100644
--- a/hw/bsp/stm32f4/boards/stm32f411disco/board.h
+++ b/hw/bsp/stm32f4/boards/stm32f411disco/board.h
@@ -44,6 +44,8 @@
#define PINID_UART_RX 3
#define PINID_VBUS0_EN 4
+#define VBUS_SENSE_EN 1
+
static board_pindef_t board_pindef[] = {
{ // LED
.port = GPIOD,
@@ -111,14 +113,6 @@ static inline void board_clock_init(void) {
__HAL_RCC_USART2_CLK_ENABLE();
}
-static inline void board_vbus_sense_init(uint8_t rhport) {
- // Enable VBUS sense (B device) via pin PA9
- if (rhport == 0) {
- USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_NOVBUSSENS;
- USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBUSBSEN;
- }
-}
-
static inline void board_vbus_set(uint8_t rhport, bool state) {
if (rhport == 0) {
board_pindef_t* pindef = &board_pindef[PINID_VBUS0_EN];
diff --git a/hw/bsp/stm32f4/boards/stm32f412disco/board.h b/hw/bsp/stm32f4/boards/stm32f412disco/board.h
index d5146ae3c..0689dfe87 100644
--- a/hw/bsp/stm32f4/boards/stm32f412disco/board.h
+++ b/hw/bsp/stm32f4/boards/stm32f412disco/board.h
@@ -45,6 +45,8 @@
#define PINID_UART_RX 3
#define PINID_VBUS0_EN 4
+#define VBUS_SENSE_EN 1
+
static board_pindef_t board_pindef[] = {
{ // LED
.port = GPIOE,
@@ -127,13 +129,6 @@ static inline void board_clock_init(void) {
__HAL_RCC_USART2_CLK_ENABLE();
}
-static inline void board_vbus_sense_init(uint8_t rhport) {
- if (rhport == 0) {
- // Enable VBUS sense (B device) via pin PA9
- USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBDEN;
- }
-}
-
static inline void board_vbus_set(uint8_t rhport, bool state) {
if (rhport == 0) {
board_pindef_t* pindef = &board_pindef[PINID_VBUS0_EN];
diff --git a/hw/bsp/stm32f4/boards/stm32f412nucleo/board.h b/hw/bsp/stm32f4/boards/stm32f412nucleo/board.h
index f7026ce61..be58f8ae7 100644
--- a/hw/bsp/stm32f4/boards/stm32f412nucleo/board.h
+++ b/hw/bsp/stm32f4/boards/stm32f412nucleo/board.h
@@ -45,6 +45,8 @@
#define PINID_UART_RX 3
#define PINID_VBUS0_EN 4
+#define VBUS_SENSE_EN 1
+
static board_pindef_t board_pindef[] = {
{ // LED
.port = GPIOB,
@@ -128,13 +130,6 @@ static inline void board_clock_init(void)
__HAL_RCC_USART3_CLK_ENABLE();
}
-static inline void board_vbus_sense_init(uint8_t rhport) {
- if (rhport == 0) {
- // Enable VBUS sense (B device) via pin PA9
- USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBDEN;
- }
-}
-
static inline void board_vbus_set(uint8_t rhport, bool state) {
if (rhport == 0) {
board_pindef_t* pindef = &board_pindef[PINID_VBUS0_EN];
diff --git a/hw/bsp/stm32f4/boards/stm32f439nucleo/board.h b/hw/bsp/stm32f4/boards/stm32f439nucleo/board.h
index 9a348f33f..b1633b395 100644
--- a/hw/bsp/stm32f4/boards/stm32f439nucleo/board.h
+++ b/hw/bsp/stm32f4/boards/stm32f439nucleo/board.h
@@ -46,6 +46,8 @@
#define PINID_UART_RX 3
#define PINID_VBUS0_EN 4
+#define VBUS_SENSE_EN 1
+
static board_pindef_t board_pindef[] = {
{ // LED
.port = GPIOB,
@@ -117,14 +119,6 @@ static inline void board_clock_init(void)
__HAL_RCC_USART3_CLK_ENABLE();
}
-static inline void board_vbus_sense_init(uint8_t rhport) {
- if (rhport == 0) {
- // Enable VBUS sense (B device) via pin PA9
- USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_NOVBUSSENS;
- USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBUSBSEN;
- }
-}
-
static inline void board_vbus_set(uint8_t rhport, bool state) {
if (rhport == 0) {
board_pindef_t* pindef = &board_pindef[PINID_VBUS0_EN];
diff --git a/hw/bsp/stm32f4/family.c b/hw/bsp/stm32f4/family.c
index 025f6a08c..f0e9620f2 100644
--- a/hw/bsp/stm32f4/family.c
+++ b/hw/bsp/stm32f4/family.c
@@ -180,11 +180,14 @@ void board_init(void) {
#endif
#if CFG_TUD_ENABLED
- board_vbus_sense_init(BOARD_TUD_RHPORT);
+ tud_configure_dwc2_t cfg = CFG_TUD_CONFIGURE_DWC2_DEFAULT;
+ cfg.vbus_sensing = VBUS_SENSE_EN;
+ tud_configure(BOARD_TUD_RHPORT, TUD_CFGID_DWC2, &cfg);
+ board_vbus_set(BOARD_TUD_RHPORT, false);
#endif
#if CFG_TUH_ENABLED
- board_vbus_set(BOARD_TUD_RHPORT, true);
+ board_vbus_set(BOARD_TUH_RHPORT, true);
#endif
}
diff --git a/hw/bsp/stm32f7/boards/stm32f723disco/board.h b/hw/bsp/stm32f7/boards/stm32f723disco/board.h
index 35102c1f2..ca9641c68 100644
--- a/hw/bsp/stm32f7/boards/stm32f723disco/board.h
+++ b/hw/bsp/stm32f7/boards/stm32f723disco/board.h
@@ -41,7 +41,7 @@
// VBUS Sense detection
#define OTG_FS_VBUS_SENSE 1
-#define OTG_HS_VBUS_SENSE 0
+#define OTG_HS_VBUS_SENSE 1
#define PINID_LED 0
#define PINID_BUTTON 1
diff --git a/hw/bsp/stm32f7/boards/stm32f746disco/board.h b/hw/bsp/stm32f7/boards/stm32f746disco/board.h
index 2964ebada..f57ffb317 100644
--- a/hw/bsp/stm32f7/boards/stm32f746disco/board.h
+++ b/hw/bsp/stm32f7/boards/stm32f746disco/board.h
@@ -40,8 +40,8 @@
#define UART_CLK_EN __HAL_RCC_USART1_CLK_ENABLE
// VBUS Sense detection
-#define OTG_FS_VBUS_SENSE 0
-#define OTG_HS_VBUS_SENSE 0
+#define OTG_FS_VBUS_SENSE 1
+#define OTG_HS_VBUS_SENSE 1
#define PINID_LED 0
#define PINID_BUTTON 1
diff --git a/hw/bsp/stm32f7/family.c b/hw/bsp/stm32f7/family.c
index ac22c606f..d8f0da201 100644
--- a/hw/bsp/stm32f7/family.c
+++ b/hw/bsp/stm32f7/family.c
@@ -154,18 +154,14 @@ void board_init(void) {
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
-
- // Enable VBUS sense (B device) via pin PA9
- USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBDEN;
-#else
- // Disable VBUS sense (B device) via pin PA9
- USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_VBDEN;
-
- // B-peripheral session valid override enable
- USB_OTG_FS->GOTGCTL |= USB_OTG_GOTGCTL_BVALOEN;
- USB_OTG_FS->GOTGCTL |= USB_OTG_GOTGCTL_BVALOVAL;
#endif // vbus sense
+#if CFG_TUD_ENABLED && BOARD_TUD_RHPORT == 0
+ tud_configure_dwc2_t cfg = CFG_TUD_CONFIGURE_DWC2_DEFAULT;
+ cfg.vbus_sensing = OTG_FS_VBUS_SENSE;
+ tud_configure(0, TUD_CFGID_DWC2, &cfg);
+#endif
+
//------------- rhport1: OTG_HS -------------//
#ifdef USB_HS_PHYC
// MCU with built-in HS PHY such as F723, F733, F730
@@ -178,9 +174,6 @@ void board_init(void) {
GPIO_InitStruct.Alternate = GPIO_AF12_OTG_HS_FS;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
- // Enable HS VBUS sense (B device) via pin PB13
- USB_OTG_HS->GCCFG |= USB_OTG_GCCFG_VBDEN;
-
/* Configure OTG-HS ID pin */
GPIO_InitStruct.Pin = GPIO_PIN_13;
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
@@ -243,17 +236,16 @@ void board_init(void) {
__HAL_RCC_USB_OTG_HS_ULPI_CLK_ENABLE();
__HAL_RCC_USB_OTG_HS_CLK_ENABLE();
-#if OTG_HS_VBUS_SENSE
- #error OTG HS VBUS Sense enabled is not implemented
-#else
- // No VBUS sense
- USB_OTG_HS->GCCFG &= ~USB_OTG_GCCFG_VBDEN;
-
- // B-peripheral session valid override enable
- USB_OTG_HS->GOTGCTL |= USB_OTG_GOTGCTL_BVALOEN;
- USB_OTG_HS->GOTGCTL |= USB_OTG_GOTGCTL_BVALOVAL;
+#if CFG_TUD_ENABLED && BOARD_TUD_RHPORT == 1
+ tud_configure_dwc2_t cfg = CFG_TUD_CONFIGURE_DWC2_DEFAULT;
+ cfg.vbus_sensing = OTG_HS_VBUS_SENSE;
+ tud_configure(1, TUD_CFGID_DWC2, &cfg);
#endif
+ // Turn off device vbus
+#if CFG_TUD_ENABLED
+ board_vbus_set(BOARD_TUD_RHPORT, false);
+#endif
// Turn on host vbus
#if CFG_TUH_ENABLED
board_vbus_set(BOARD_TUH_RHPORT, true);
diff --git a/hw/bsp/stm32h7/boards/stm32h743eval/board.h b/hw/bsp/stm32h7/boards/stm32h743eval/board.h
index 96bfc24e1..44ca58dc5 100644
--- a/hw/bsp/stm32h7/boards/stm32h743eval/board.h
+++ b/hw/bsp/stm32h7/boards/stm32h743eval/board.h
@@ -44,7 +44,7 @@
// VBUS Sense detection
#define OTG_FS_VBUS_SENSE 1
-#define OTG_HS_VBUS_SENSE 0
+#define OTG_HS_VBUS_SENSE 1
// USB HS External PHY Pin: CLK, STP, DIR, NXT, D0-D7
#define ULPI_PINS \
diff --git a/hw/bsp/stm32h7/boards/stm32h747disco/board.cmake b/hw/bsp/stm32h7/boards/stm32h747disco/board.cmake
new file mode 100644
index 000000000..8bce542a5
--- /dev/null
+++ b/hw/bsp/stm32h7/boards/stm32h747disco/board.cmake
@@ -0,0 +1,23 @@
+set(MCU_VARIANT stm32h747xx)
+set(JLINK_DEVICE stm32h747xi_m7)
+
+set(LD_FILE_GNU ${CMAKE_CURRENT_LIST_DIR}/../../linker/${MCU_VARIANT}_flash_CM7.ld)
+set(LD_FILE_IAR ${ST_CMSIS}/Source/Templates/iar/linker/${MCU_VARIANT}_flash_CM7.icf)
+
+set(RHPORT_SPEED OPT_MODE_FULL_SPEED OPT_MODE_HIGH_SPEED)
+
+# device default to PORT 1 High Speed
+if (NOT DEFINED RHPORT_DEVICE)
+ set(RHPORT_DEVICE 1)
+endif()
+if (NOT DEFINED RHPORT_HOST)
+ set(RHPORT_HOST 1)
+endif()
+
+function(update_board TARGET)
+ target_compile_definitions(${TARGET} PUBLIC
+ STM32H747xx
+ HSE_VALUE=25000000
+ CORE_CM7
+ )
+endfunction()
diff --git a/hw/bsp/stm32h7/boards/stm32h747disco/board.h b/hw/bsp/stm32h7/boards/stm32h747disco/board.h
new file mode 100644
index 000000000..458aa48b6
--- /dev/null
+++ b/hw/bsp/stm32h7/boards/stm32h747disco/board.h
@@ -0,0 +1,169 @@
+/*
+ * 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: STM32 H745 Discovery
+ url: https://www.st.com/en/evaluation-tools/stm32h745i-disco.html
+*/
+
+#ifndef BOARD_H_
+#define BOARD_H_
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+// UART
+#define UART_DEV USART3
+#define UART_CLK_EN __HAL_RCC_USART3_CLK_ENABLE
+
+// VBUS Sense detection
+#define OTG_FS_VBUS_SENSE 1
+#define OTG_HS_VBUS_SENSE 1
+
+// USB HS External PHY Pin: CLK, STP, DIR, NXT, D0-D7
+#define ULPI_PINS \
+ {GPIOA, GPIO_PIN_3 }, {GPIOA, GPIO_PIN_5 }, {GPIOB, GPIO_PIN_0 }, {GPIOB, GPIO_PIN_1 }, \
+ {GPIOB, GPIO_PIN_5 }, {GPIOB, GPIO_PIN_10}, {GPIOB, GPIO_PIN_11}, {GPIOB, GPIO_PIN_12}, \
+ {GPIOB, GPIO_PIN_13}, {GPIOC, GPIO_PIN_0 }, {GPIOH, GPIO_PIN_4 }, {GPIOI, GPIO_PIN_11}
+
+#define PINID_LED 0
+#define PINID_BUTTON 1
+#define PINID_UART_TX 2
+#define PINID_UART_RX 3
+
+static board_pindef_t board_pindef[] = {
+ { // LED
+ .port = GPIOI,
+ .pin_init = { .Pin = GPIO_PIN_12, .Mode = GPIO_MODE_OUTPUT_PP, .Pull = GPIO_PULLDOWN, .Speed = GPIO_SPEED_HIGH, .Alternate = 0 },
+ .active_state = 0
+ },
+ { // Button
+ .port = GPIOC,
+ .pin_init = { .Pin = GPIO_PIN_13, .Mode = GPIO_MODE_INPUT, .Pull = GPIO_PULLUP, .Speed = GPIO_SPEED_HIGH, .Alternate = 0 },
+ .active_state = 1
+ },
+ { // UART TX
+ .port = GPIOA,
+ .pin_init = { .Pin = GPIO_PIN_9, .Mode = GPIO_MODE_AF_PP, .Pull = GPIO_PULLUP, .Speed = GPIO_SPEED_HIGH, .Alternate = GPIO_AF7_USART3 },
+ .active_state = 0
+ },
+ { // UART RX
+ .port = GPIOA,
+ .pin_init = { .Pin = GPIO_PIN_10, .Mode = GPIO_MODE_AF_PP, .Pull = GPIO_PULLUP, .Speed = GPIO_SPEED_HIGH, .Alternate = GPIO_AF7_USART3 },
+ .active_state = 0
+ }
+};
+
+//--------------------------------------------------------------------+
+// RCC Clock
+//--------------------------------------------------------------------+
+static inline void SystemClock_Config(void)
+{
+ RCC_ClkInitTypeDef RCC_ClkInitStruct = { 0 };
+ RCC_OscInitTypeDef RCC_OscInitStruct = { 0 };
+ RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = { 0 };
+
+ /*!< Supply configuration update enable */
+ /* For STM32H750XB, use "HAL_PWREx_ConfigSupply(PWR_LDO_SUPPLY);" */
+ HAL_PWREx_ConfigSupply(PWR_DIRECT_SMPS_SUPPLY);
+
+ /* The voltage scaling allows optimizing the power consumption when the
+ device is clocked below the maximum system frequency, to update the
+ voltage scaling value regarding system frequency refer to product
+ datasheet. */
+ __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
+
+ while ((PWR->D3CR & (PWR_D3CR_VOSRDY)) != PWR_D3CR_VOSRDY) {}
+
+ /* Enable HSE Oscillator and activate PLL with HSE as source */
+ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
+ RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS;
+ RCC_OscInitStruct.HSIState = RCC_HSI_OFF;
+ RCC_OscInitStruct.CSIState = RCC_CSI_OFF;
+ RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
+ RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
+
+ /* PLL1 for System Clock */
+ RCC_OscInitStruct.PLL.PLLM = 5;
+ RCC_OscInitStruct.PLL.PLLN = 160;
+ RCC_OscInitStruct.PLL.PLLFRACN = 0;
+ RCC_OscInitStruct.PLL.PLLP = 2;
+ RCC_OscInitStruct.PLL.PLLR = 2;
+ RCC_OscInitStruct.PLL.PLLQ = 4;
+
+ RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOMEDIUM;
+ RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_2;
+ HAL_RCC_OscConfig(&RCC_OscInitStruct);
+
+ /* PLL3 for USB Clock */
+ PeriphClkInitStruct.PLL3.PLL3M = 25;
+ PeriphClkInitStruct.PLL3.PLL3N = 336;
+ PeriphClkInitStruct.PLL3.PLL3FRACN = 0;
+ PeriphClkInitStruct.PLL3.PLL3P = 2;
+ PeriphClkInitStruct.PLL3.PLL3R = 2;
+ PeriphClkInitStruct.PLL3.PLL3Q = 7;
+
+ PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USB;
+ PeriphClkInitStruct.UsbClockSelection = RCC_USBCLKSOURCE_PLL3;
+ HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
+
+ /* Select PLL as system clock source and configure bus clocks dividers */
+ RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_D1PCLK1 | RCC_CLOCKTYPE_PCLK1 | \
+ RCC_CLOCKTYPE_PCLK2 | RCC_CLOCKTYPE_D3PCLK1);
+
+ RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
+ RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1;
+ RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV2;
+ RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV2;
+ RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV2;
+ RCC_ClkInitStruct.APB3CLKDivider = RCC_APB3_DIV1;
+ HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4);
+
+ /*activate CSI clock mondatory for I/O Compensation Cell*/
+ __HAL_RCC_CSI_ENABLE() ;
+
+ /* Enable SYSCFG clock mondatory for I/O Compensation Cell */
+ __HAL_RCC_SYSCFG_CLK_ENABLE() ;
+
+ /* Enables the I/O Compensation Cell */
+ HAL_EnableCompensationCell();
+}
+
+static inline void board_init2(void) {
+ // For this board does nothing
+}
+
+void board_vbus_set(uint8_t rhport, bool state) {
+ (void) rhport;
+ (void) state;
+}
+
+#ifdef __cplusplus
+ }
+#endif
+
+#endif
diff --git a/hw/bsp/stm32h7/boards/stm32h747disco/board.mk b/hw/bsp/stm32h7/boards/stm32h747disco/board.mk
new file mode 100644
index 000000000..4b17246e2
--- /dev/null
+++ b/hw/bsp/stm32h7/boards/stm32h747disco/board.mk
@@ -0,0 +1,15 @@
+# STM32H747I-DISCO uses OTG_FS
+# FIXME: Reset enumerates, un/replug USB plug does not enumerate
+MCU_VARIANT = stm32h747xx
+CFLAGS += -DSTM32H747xx -DCORE_CM7 -DHSE_VALUE=25000000
+
+# Default is FulSpeed port
+PORT ?= 0
+
+LD_FILE_GCC = $(FAMILY_PATH)/linker/${MCU_VARIANT}_flash_CM7.ld
+LD_FILE_IAR = $(ST_CMSIS)/Source/Templates/iar/linker/stm32h747xx_flash_CM7.icf
+
+# For flash-jlink target
+JLINK_DEVICE = stm32h747xi_m7
+# flash target using on-board stlink
+flash: flash-stlink
diff --git a/hw/bsp/stm32h7/family.c b/hw/bsp/stm32h7/family.c
index 054d7855f..a320a7e72 100644
--- a/hw/bsp/stm32h7/family.c
+++ b/hw/bsp/stm32h7/family.c
@@ -180,18 +180,14 @@ void board_init(void) {
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
-
- // Enable VBUS sense (B device) via pin PA9
- USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBDEN;
-#else
- // Disable VBUS sense (B device) via pin PA9
- USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_VBDEN;
-
- // B-peripheral session valid override enable
- USB_OTG_FS->GOTGCTL |= USB_OTG_GOTGCTL_BVALOEN;
- USB_OTG_FS->GOTGCTL |= USB_OTG_GOTGCTL_BVALOVAL;
#endif // vbus sense
+#if CFG_TUD_ENABLED && BOARD_TUD_RHPORT == 0
+ tud_configure_dwc2_t cfg = CFG_TUD_CONFIGURE_DWC2_DEFAULT;
+ cfg.vbus_sensing = OTG_FS_VBUS_SENSE;
+ tud_configure(0, TUD_CFGID_DWC2, &cfg);
+#endif
+
//------------- USB HS -------------//
#if (CFG_TUD_ENABLED && BOARD_TUD_RHPORT == 1) || (CFG_TUH_ENABLED && BOARD_TUH_RHPORT == 1)
// Despite being call USB2_OTG
@@ -216,28 +212,24 @@ void board_init(void) {
__HAL_RCC_USB1_OTG_HS_ULPI_CLK_ENABLE();
__HAL_RCC_USB1_OTG_HS_CLK_ENABLE();
-#if OTG_HS_VBUS_SENSE
- #error OTG HS VBUS Sense enabled is not implemented
-#else
- // No VBUS sense
- USB_OTG_HS->GCCFG &= ~USB_OTG_GCCFG_VBDEN;
-
- // B-peripheral session valid override enable
- USB_OTG_HS->GOTGCTL |= USB_OTG_GOTGCTL_BVALOEN;
- USB_OTG_HS->GOTGCTL |= USB_OTG_GOTGCTL_BVALOVAL;
-#endif
-
- // Force device mode
- USB_OTG_HS->GUSBCFG &= ~USB_OTG_GUSBCFG_FHMOD;
- USB_OTG_HS->GUSBCFG |= USB_OTG_GUSBCFG_FDMOD;
+ #if CFG_TUD_ENABLED && BOARD_TUD_RHPORT == 1
+ tud_configure_dwc2_t cfg = CFG_TUD_CONFIGURE_DWC2_DEFAULT;
+ cfg.vbus_sensing = OTG_HS_VBUS_SENSE;
+ tud_configure(1, TUD_CFGID_DWC2, &cfg);
+ #endif
#endif
HAL_PWREx_EnableUSBVoltageDetector();
board_init2(); // optional init
+ // Turn off device vbus
+#if CFG_TUD_ENABLED
+ board_vbus_set(BOARD_TUD_RHPORT, false);
+#endif
+ // Turn on host vbus
#if CFG_TUH_ENABLED
- board_vbus_set(BOARD_TUH_RHPORT, 1);
+ board_vbus_set(BOARD_TUH_RHPORT, true);
#endif
}
diff --git a/hw/bsp/stm32h7/linker/stm32h747xx_flash_CM7.ld b/hw/bsp/stm32h7/linker/stm32h747xx_flash_CM7.ld
new file mode 100644
index 000000000..5b7fe4528
--- /dev/null
+++ b/hw/bsp/stm32h7/linker/stm32h747xx_flash_CM7.ld
@@ -0,0 +1,184 @@
+/*
+******************************************************************************
+**
+
+** File : LinkerScript.ld
+**
+**
+** Abstract : Linker script for STM32H7 series
+** 1024Kbytes FLASH and 192Kbytes RAM
+**
+** Set heap size, stack size and stack location according
+** to application requirements.
+**
+** Set memory bank area and size if external memory is used.
+**
+** Target : STMicroelectronics STM32
+**
+** Distribution: The file is distributed as is without any warranty
+** of any kind.
+**
+*****************************************************************************
+** @attention
+**
+** Copyright (c) 2019 STMicroelectronics.
+** All rights reserved.
+**
+** This software is licensed under terms that can be found in the LICENSE file
+** in the root directory of this software component.
+** If no LICENSE file comes with this software, it is provided AS-IS.
+**
+******************************************************************************
+*/
+
+/* Entry Point */
+ENTRY(Reset_Handler)
+
+/* Highest address of the user mode stack */
+_estack = 0x20020000; /* end of RAM */
+/* Generate a link error if heap and stack don't fit into RAM */
+_Min_Heap_Size = 0x200; /* required amount of heap */
+_Min_Stack_Size = 0x400; /* required amount of stack */
+
+/* Specify the memory areas */
+MEMORY
+{
+FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 1024K
+RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
+ITCMRAM (xrw) : ORIGIN = 0x00000000, LENGTH = 64K
+}
+
+/* Define output sections */
+SECTIONS
+{
+ /* The startup code goes first into FLASH */
+ .isr_vector :
+ {
+ . = ALIGN(4);
+ KEEP(*(.isr_vector)) /* Startup code */
+ . = ALIGN(4);
+ } >FLASH
+
+ /* The program code and other data goes into FLASH */
+ .text :
+ {
+ . = ALIGN(4);
+ *(.text) /* .text sections (code) */
+ *(.text*) /* .text* sections (code) */
+ *(.glue_7) /* glue arm to thumb code */
+ *(.glue_7t) /* glue thumb to arm code */
+ *(.eh_frame)
+
+ KEEP (*(.init))
+ KEEP (*(.fini))
+
+ . = ALIGN(4);
+ _etext = .; /* define a global symbols at end of code */
+ } >FLASH
+
+ /* Constant data goes into FLASH */
+ .rodata :
+ {
+ . = ALIGN(4);
+ *(.rodata) /* .rodata sections (constants, strings, etc.) */
+ *(.rodata*) /* .rodata* sections (constants, strings, etc.) */
+ . = ALIGN(4);
+ } >FLASH
+
+ .ARM.extab :
+ {
+ . = ALIGN(4);
+ *(.ARM.extab* .gnu.linkonce.armextab.*)
+ . = ALIGN(4);
+ } >FLASH
+ .ARM :
+ {
+ . = ALIGN(4);
+ __exidx_start = .;
+ *(.ARM.exidx*)
+ __exidx_end = .;
+ . = ALIGN(4);
+ } >FLASH
+
+ .preinit_array :
+ {
+ . = ALIGN(4);
+ PROVIDE_HIDDEN (__preinit_array_start = .);
+ KEEP (*(.preinit_array*))
+ PROVIDE_HIDDEN (__preinit_array_end = .);
+ . = ALIGN(4);
+ } >FLASH
+ .init_array :
+ {
+ . = ALIGN(4);
+ PROVIDE_HIDDEN (__init_array_start = .);
+ KEEP (*(SORT(.init_array.*)))
+ KEEP (*(.init_array*))
+ PROVIDE_HIDDEN (__init_array_end = .);
+ . = ALIGN(4);
+ } >FLASH
+ .fini_array :
+ {
+ . = ALIGN(4);
+ PROVIDE_HIDDEN (__fini_array_start = .);
+ KEEP (*(SORT(.fini_array.*)))
+ KEEP (*(.fini_array*))
+ PROVIDE_HIDDEN (__fini_array_end = .);
+ . = ALIGN(4);
+ } >FLASH
+
+ /* used by the startup to initialize data */
+ _sidata = LOADADDR(.data);
+
+ /* Initialized data sections goes into RAM, load LMA copy after code */
+ .data :
+ {
+ . = ALIGN(4);
+ _sdata = .; /* create a global symbol at data start */
+ *(.data) /* .data sections */
+ *(.data*) /* .data* sections */
+
+ . = ALIGN(4);
+ _edata = .; /* define a global symbol at data end */
+ } >RAM AT> FLASH
+
+
+ /* Uninitialized data section */
+ . = ALIGN(4);
+ .bss :
+ {
+ /* This is used by the startup in order to initialize the .bss section */
+ _sbss = .; /* define a global symbol at bss start */
+ __bss_start__ = _sbss;
+ *(.bss)
+ *(.bss*)
+ *(COMMON)
+
+ . = ALIGN(4);
+ _ebss = .; /* define a global symbol at bss end */
+ __bss_end__ = _ebss;
+ } >RAM
+
+ /* 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);
+ } >RAM
+
+
+
+ /* Remove information from the standard libraries */
+ /DISCARD/ :
+ {
+ libc.a ( * )
+ libm.a ( * )
+ libgcc.a ( * )
+ }
+
+ .ARM.attributes 0 : { *(.ARM.attributes) }
+}
diff --git a/hw/bsp/stm32h7rs/boards/stm32h7s3nucleo/board.cmake b/hw/bsp/stm32h7rs/boards/stm32h7s3nucleo/board.cmake
index 7b3456585..189c175dd 100644
--- a/hw/bsp/stm32h7rs/boards/stm32h7s3nucleo/board.cmake
+++ b/hw/bsp/stm32h7rs/boards/stm32h7s3nucleo/board.cmake
@@ -2,6 +2,8 @@ set(MCU_VARIANT stm32h7s3xx)
set(JLINK_DEVICE stm32h7s3l8)
set(LD_FILE_Clang ${LD_FILE_GNU})
+set(RHPORT_DEVICE 1)
+set(RHPORT_HOST 1)
function(update_board TARGET)
target_compile_definitions(${TARGET} PUBLIC
diff --git a/hw/bsp/stm32h7rs/boards/stm32h7s3nucleo/board.h b/hw/bsp/stm32h7rs/boards/stm32h7s3nucleo/board.h
index 58adf2664..4b8564709 100644
--- a/hw/bsp/stm32h7rs/boards/stm32h7s3nucleo/board.h
+++ b/hw/bsp/stm32h7rs/boards/stm32h7s3nucleo/board.h
@@ -44,7 +44,7 @@
#define UART_CLK_EN __HAL_RCC_USART3_CLK_ENABLE
// VBUS Sense detection
-#define OTG_FS_VBUS_SENSE 1
+#define OTG_FS_VBUS_SENSE 0
#define OTG_HS_VBUS_SENSE 0
#define PINID_LED 0
diff --git a/hw/bsp/stm32h7rs/family.c b/hw/bsp/stm32h7rs/family.c
index 784c92465..2cc39b7ac 100644
--- a/hw/bsp/stm32h7rs/family.c
+++ b/hw/bsp/stm32h7rs/family.c
@@ -356,17 +356,14 @@ void board_init(void) {
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
HAL_GPIO_Init(GPIOM, &GPIO_InitStruct);
+#endif // vbus sense
- // Enable VBUS sense (B device) via pin PM14
- USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBDEN;
-#else
- // Disable VBUS sense (B device)
- USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_VBDEN;
+#if CFG_TUD_ENABLED && BOARD_TUD_RHPORT == 0
+ tud_configure_dwc2_t cfg = CFG_TUD_CONFIGURE_DWC2_DEFAULT;
+ cfg.vbus_sensing = OTG_FS_VBUS_SENSE;
+ tud_configure(0, TUD_CFGID_DWC2, &cfg);
+#endif
- // B-peripheral session valid override enable
- USB_OTG_FS->GOTGCTL |= USB_OTG_GOTGCTL_BVALOEN;
- USB_OTG_FS->GOTGCTL |= USB_OTG_GOTGCTL_BVALOVAL;
-#endif // vbus sense
#endif
//------------- USB HS -------------//
@@ -382,33 +379,31 @@ void board_init(void) {
#if OTG_HS_VBUS_SENSE
// Configure VBUS Pin
- GPIO_InitStruct.Pin = GPIO_PIN_9;
- GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS;
- HAL_GPIO_Init(GPIOM, &GPIO_InitStruct);
-
- // Enable VBUS sense (B device) via pin PM9
- USB_OTG_HS->GCCFG |= USB_OTG_GCCFG_VBDEN;
-#else
- // Disable VBUS sense (B device)
- USB_OTG_HS->GCCFG &= ~USB_OTG_GCCFG_VBDEN;
+ GPIO_InitTypeDef GPIO_InitStruct2;
+ GPIO_InitStruct2.Pin = GPIO_PIN_8;
+ GPIO_InitStruct2.Mode = GPIO_MODE_INPUT;
+ GPIO_InitStruct2.Pull = GPIO_NOPULL;
+ GPIO_InitStruct2.Alternate = GPIO_AF10_OTG_HS;
+ HAL_GPIO_Init(GPIOM, &GPIO_InitStruct2);
+#endif
#if CFG_TUD_ENABLED && BOARD_TUD_RHPORT == 1
- // B-peripheral session valid override enable
- USB_OTG_HS->GCCFG |= USB_OTG_GCCFG_VBVALEXTOEN;
- USB_OTG_HS->GCCFG |= USB_OTG_GCCFG_VBVALOVAL;
-#else
- USB_OTG_HS->GCCFG |= USB_OTG_GCCFG_PULLDOWNEN;
+ tud_configure_dwc2_t cfg = CFG_TUD_CONFIGURE_DWC2_DEFAULT;
+ cfg.vbus_sensing = OTG_HS_VBUS_SENSE;
+ tud_configure(1, TUD_CFGID_DWC2, &cfg);
#endif
#endif
-#endif
board_init2();
+ // Turn off device vbus
+#if CFG_TUD_ENABLED
+ board_vbus_set(BOARD_TUD_RHPORT, false);
+#endif
+ // Turn on host vbus
#if CFG_TUH_ENABLED
- board_vbus_set(BOARD_TUH_RHPORT, 1);
+ board_vbus_set(BOARD_TUH_RHPORT, true);
#endif
}
diff --git a/hw/bsp/stm32h7rs/family.cmake b/hw/bsp/stm32h7rs/family.cmake
index 1fd1cb057..3b9dbf5cf 100644
--- a/hw/bsp/stm32h7rs/family.cmake
+++ b/hw/bsp/stm32h7rs/family.cmake
@@ -24,7 +24,7 @@ if (NOT DEFINED RHPORT_DEVICE)
set(RHPORT_DEVICE 1)
endif ()
if (NOT DEFINED RHPORT_HOST)
- set(RHPORT_HOST 1)
+ set(RHPORT_HOST 0)
endif ()
if (NOT DEFINED RHPORT_SPEED)
diff --git a/hw/bsp/stm32l4/boards/stm32l476disco/board.h b/hw/bsp/stm32l4/boards/stm32l476disco/board.h
index 8c766d8ea..cf84d3e66 100644
--- a/hw/bsp/stm32l4/boards/stm32l476disco/board.h
+++ b/hw/bsp/stm32l4/boards/stm32l476disco/board.h
@@ -51,6 +51,8 @@
#define UART_TX_PIN GPIO_PIN_5
#define UART_RX_PIN GPIO_PIN_6
+#define VBUS_SENSE_EN 0
+
//--------------------------------------------------------------------+
// RCC Clock
//--------------------------------------------------------------------+
@@ -128,15 +130,6 @@ static inline void board_clock_init(void)
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4);
}
-static inline void board_vbus_sense_init(void)
-{
- // L476Disco use general GPIO PC11 for VBUS sensing instead of dedicated PA9 as others
- // Disable VBUS Sense and force device mode
- USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_VBDEN;
-
- USB_OTG_FS->GOTGCTL |= USB_OTG_GOTGCTL_BVALOEN | USB_OTG_GOTGCTL_BVALOVAL;
-}
-
#ifdef __cplusplus
}
#endif
diff --git a/hw/bsp/stm32l4/boards/stm32l496nucleo/board.h b/hw/bsp/stm32l4/boards/stm32l496nucleo/board.h
index 607210cec..3b031e00f 100644
--- a/hw/bsp/stm32l4/boards/stm32l496nucleo/board.h
+++ b/hw/bsp/stm32l4/boards/stm32l496nucleo/board.h
@@ -52,6 +52,8 @@
#define UART_TX_PIN GPIO_PIN_7
#define UART_RX_PIN GPIO_PIN_8
+#define VBUS_SENSE_EN 1
+
//--------------------------------------------------------------------+
// RCC Clock
//--------------------------------------------------------------------+
@@ -145,12 +147,6 @@ static inline void board_clock_init(void)
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
}
-static inline void board_vbus_sense_init(void)
-{
- // Enable VBUS sense (B device) via pin PA9
- USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBDEN;
-}
-
#ifdef __cplusplus
}
#endif
diff --git a/hw/bsp/stm32l4/boards/stm32l4p5nucleo/board.h b/hw/bsp/stm32l4/boards/stm32l4p5nucleo/board.h
index f522e7522..94978638e 100644
--- a/hw/bsp/stm32l4/boards/stm32l4p5nucleo/board.h
+++ b/hw/bsp/stm32l4/boards/stm32l4p5nucleo/board.h
@@ -51,6 +51,8 @@
#define UART_TX_PIN GPIO_PIN_7
#define UART_RX_PIN GPIO_PIN_8
+#define VBUS_SENSE_EN 1
+
//--------------------------------------------------------------------+
// RCC Clock
//--------------------------------------------------------------------+
@@ -129,12 +131,6 @@ static inline void board_clock_init(void)
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5);
}
-static inline void board_vbus_sense_init(void)
-{
- // Enable VBUS sense (B device) via pin PA9
- USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBDEN;
-}
-
#ifdef __cplusplus
}
#endif
diff --git a/hw/bsp/stm32l4/boards/stm32l4r5nucleo/board.h b/hw/bsp/stm32l4/boards/stm32l4r5nucleo/board.h
index c181f5d4a..f603ae855 100644
--- a/hw/bsp/stm32l4/boards/stm32l4r5nucleo/board.h
+++ b/hw/bsp/stm32l4/boards/stm32l4r5nucleo/board.h
@@ -51,6 +51,8 @@
#define UART_TX_PIN GPIO_PIN_7
#define UART_RX_PIN GPIO_PIN_8
+#define VBUS_SENSE_EN 1
+
//--------------------------------------------------------------------+
// RCC Clock
//--------------------------------------------------------------------+
@@ -129,12 +131,6 @@ static inline void board_clock_init(void)
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5);
}
-static inline void board_vbus_sense_init(void)
-{
- // Enable VBUS sense (B device) via pin PA9
- USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBDEN;
-}
-
#ifdef __cplusplus
}
#endif
diff --git a/hw/bsp/stm32l4/family.c b/hw/bsp/stm32l4/family.c
index e69ae8e3b..65f6b9ab3 100644
--- a/hw/bsp/stm32l4/family.c
+++ b/hw/bsp/stm32l4/family.c
@@ -170,10 +170,16 @@ void board_init(void) {
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
#endif
- /* Enable USB FS Clocks */
#if defined(USB_OTG_FS)
+ /* Enable USB FS Clocks */
__HAL_RCC_USB_OTG_FS_CLK_ENABLE();
- board_vbus_sense_init();
+
+ #if CFG_TUD_ENABLED
+ /* Set Vbus sense */
+ tud_configure_dwc2_t cfg = CFG_TUD_CONFIGURE_DWC2_DEFAULT;
+ cfg.vbus_sensing = VBUS_SENSE_EN;
+ tud_configure(0, TUD_CFGID_DWC2, &cfg);
+ #endif
#else
__HAL_RCC_USB_CLK_ENABLE();
#endif
diff --git a/hw/bsp/stm32n6/boards/stm32n6570dk/board.cmake b/hw/bsp/stm32n6/boards/stm32n6570dk/board.cmake
index e88efefb9..00efc974c 100644
--- a/hw/bsp/stm32n6/boards/stm32n6570dk/board.cmake
+++ b/hw/bsp/stm32n6/boards/stm32n6570dk/board.cmake
@@ -1,5 +1,5 @@
set(MCU_VARIANT stm32n657xx)
-set(JLINK_DEVICE stm32n6xx)
+set(JLINK_DEVICE stm32n657x0)
set(LD_FILE_GNU ${CMAKE_CURRENT_LIST_DIR}/STM32N657XX_AXISRAM2_fsbl.ld)
diff --git a/hw/bsp/stm32n6/boards/stm32n6570dk/board.h b/hw/bsp/stm32n6/boards/stm32n6570dk/board.h
index bbcad6340..8c2ec66dc 100644
--- a/hw/bsp/stm32n6/boards/stm32n6570dk/board.h
+++ b/hw/bsp/stm32n6/boards/stm32n6570dk/board.h
@@ -44,17 +44,16 @@ extern "C" {
#define UART_DEV USART1
#define UART_CLK_EN __HAL_RCC_USART1_CLK_ENABLE
-#define BOARD_TUD_RHPORT 1
-
// VBUS Sense detection
-#define OTG_FS_VBUS_SENSE 1
-#define OTG_HS_VBUS_SENSE 1
+#define OTG_FS_VBUS_SENSE 0
+#define OTG_HS_VBUS_SENSE 0
#define PINID_LED 0
#define PINID_BUTTON 1
#define PINID_UART_TX 2
#define PINID_UART_RX 3
#define PINID_TCPP0203_EN 4
+#define PINID_PWR_USB2 8
static board_pindef_t board_pindef[] = {
{// LED
@@ -77,21 +76,22 @@ static board_pindef_t board_pindef[] = {
.port = GPIOA,
.pin_init = {.Pin = GPIO_PIN_4, .Mode = GPIO_MODE_OUTPUT_PP, .Pull = GPIO_PULLDOWN, .Speed = GPIO_SPEED_FREQ_HIGH, .Alternate = 0},
.active_state = 0},
- {
- // I2C SCL for TCPP0203
- .port = GPIOD,
- .pin_init = {.Pin = GPIO_PIN_14, .Mode = GPIO_MODE_AF_OD, .Pull = GPIO_NOPULL, .Speed = GPIO_SPEED_FREQ_LOW, .Alternate = GPIO_AF4_I2C2},
+ { // I2C SCL for TCPP0203
+ .port = GPIOD,
+ .pin_init = {.Pin = GPIO_PIN_14, .Mode = GPIO_MODE_AF_OD, .Pull = GPIO_NOPULL, .Speed = GPIO_SPEED_FREQ_LOW, .Alternate = GPIO_AF4_I2C2},
},
- {
- // I2C SDA for TCPP0203
- .port = GPIOD,
- .pin_init = {.Pin = GPIO_PIN_4, .Mode = GPIO_MODE_AF_OD, .Pull = GPIO_NOPULL, .Speed = GPIO_SPEED_FREQ_LOW, .Alternate = GPIO_AF4_I2C2},
+ {// I2C SDA for TCPP0203
+ .port = GPIOD,
+ .pin_init = {.Pin = GPIO_PIN_4, .Mode = GPIO_MODE_AF_OD, .Pull = GPIO_NOPULL, .Speed = GPIO_SPEED_FREQ_LOW, .Alternate = GPIO_AF4_I2C2},
},
- {
- // INT for TCPP0203
- .port = GPIOD,
- .pin_init = {.Pin = GPIO_PIN_10, .Mode = GPIO_MODE_IT_FALLING, .Pull = GPIO_PULLUP, .Speed = GPIO_SPEED_FREQ_HIGH, .Alternate = 0},
+ {// INT for TCPP0203
+ .port = GPIOD,
+ .pin_init = {.Pin = GPIO_PIN_10, .Mode = GPIO_MODE_IT_FALLING, .Pull = GPIO_PULLUP, .Speed = GPIO_SPEED_FREQ_HIGH, .Alternate = 0},
},
+ {// PWR for USB2
+ .port = GPIOB,
+ .pin_init = {.Pin = GPIO_PIN_9, .Mode = GPIO_MODE_OUTPUT_PP, .Pull = GPIO_NOPULL, .Speed = GPIO_SPEED_FREQ_HIGH, .Alternate = 0},
+ }
};
//--------------------------------------------------------------------+
@@ -262,9 +262,12 @@ static inline void board_init2(void) {
}
void board_vbus_set(uint8_t rhport, bool state) {
- (void) state;
- if (rhport == 1) {
- TU_ASSERT(TCPP0203_SetGateDriverProvider(&tcpp0203_obj, TCPP0203_GD_PROVIDER_SWITCH_CLOSED) == TCPP0203_OK, );
+ if (rhport == 0) {
+ uint8_t switch_state = state ? TCPP0203_GD_PROVIDER_SWITCH_CLOSED : TCPP0203_GD_PROVIDER_SWITCH_OPEN;
+ TU_ASSERT(TCPP0203_SetGateDriverProvider(&tcpp0203_obj, switch_state) == TCPP0203_OK, );
+ } else if (rhport == 1) {
+ board_pindef_t *pindef = &board_pindef[PINID_PWR_USB2];
+ HAL_GPIO_WritePin(pindef->port, pindef->pin_init.Pin, state ? GPIO_PIN_SET : GPIO_PIN_RESET);
}
}
diff --git a/hw/bsp/stm32n6/boards/stm32n657nucleo/board.cmake b/hw/bsp/stm32n6/boards/stm32n657nucleo/board.cmake
index e88efefb9..e682cabcb 100644
--- a/hw/bsp/stm32n6/boards/stm32n657nucleo/board.cmake
+++ b/hw/bsp/stm32n6/boards/stm32n657nucleo/board.cmake
@@ -1,8 +1,15 @@
set(MCU_VARIANT stm32n657xx)
-set(JLINK_DEVICE stm32n6xx)
+set(JLINK_DEVICE stm32n657x0)
set(LD_FILE_GNU ${CMAKE_CURRENT_LIST_DIR}/STM32N657XX_AXISRAM2_fsbl.ld)
+if (NOT DEFINED RHPORT_DEVICE)
+ set(RHPORT_DEVICE 0)
+endif ()
+if (NOT DEFINED RHPORT_HOST)
+ set(RHPORT_HOST 0)
+endif ()
+
function(update_board TARGET)
target_compile_definitions(${TARGET} PUBLIC
STM32N657xx
diff --git a/hw/bsp/stm32n6/boards/stm32n657nucleo/board.h b/hw/bsp/stm32n6/boards/stm32n657nucleo/board.h
index 33c68f7cf..5bdbaff3c 100644
--- a/hw/bsp/stm32n6/boards/stm32n657nucleo/board.h
+++ b/hw/bsp/stm32n6/boards/stm32n657nucleo/board.h
@@ -44,11 +44,9 @@ extern "C" {
#define UART_DEV USART1
#define UART_CLK_EN __HAL_RCC_USART1_CLK_ENABLE
-#define BOARD_TUD_RHPORT 1
-
// VBUS Sense detection
-#define OTG_FS_VBUS_SENSE 1
-#define OTG_HS_VBUS_SENSE 1
+#define OTG_FS_VBUS_SENSE 0
+#define OTG_HS_VBUS_SENSE 0
#define PINID_LED 0
#define PINID_BUTTON 1
@@ -77,20 +75,17 @@ static board_pindef_t board_pindef[] = {
.port = GPIOA,
.pin_init = {.Pin = GPIO_PIN_7, .Mode = GPIO_MODE_OUTPUT_PP, .Pull = GPIO_PULLDOWN, .Speed = GPIO_SPEED_FREQ_HIGH, .Alternate = 0},
.active_state = 0},
- {
- // I2C SCL for TCPP0203
- .port = GPIOB,
- .pin_init = {.Pin = GPIO_PIN_10, .Mode = GPIO_MODE_AF_OD, .Pull = GPIO_NOPULL, .Speed = GPIO_SPEED_FREQ_LOW, .Alternate = GPIO_AF4_I2C2},
+ {// I2C SCL for TCPP0203
+ .port = GPIOB,
+ .pin_init = {.Pin = GPIO_PIN_10, .Mode = GPIO_MODE_AF_OD, .Pull = GPIO_NOPULL, .Speed = GPIO_SPEED_FREQ_LOW, .Alternate = GPIO_AF4_I2C2},
},
- {
- // I2C SDA for TCPP0203
- .port = GPIOB,
- .pin_init = {.Pin = GPIO_PIN_11, .Mode = GPIO_MODE_AF_OD, .Pull = GPIO_NOPULL, .Speed = GPIO_SPEED_FREQ_LOW, .Alternate = GPIO_AF4_I2C2},
+ {// I2C SDA for TCPP0203
+ .port = GPIOB,
+ .pin_init = {.Pin = GPIO_PIN_11, .Mode = GPIO_MODE_AF_OD, .Pull = GPIO_NOPULL, .Speed = GPIO_SPEED_FREQ_LOW, .Alternate = GPIO_AF4_I2C2},
},
- {
- // INT for TCPP0203
- .port = GPIOD,
- .pin_init = {.Pin = GPIO_PIN_2, .Mode = GPIO_MODE_IT_FALLING, .Pull = GPIO_PULLUP, .Speed = GPIO_SPEED_FREQ_HIGH, .Alternate = 0},
+ {// INT for TCPP0203
+ .port = GPIOD,
+ .pin_init = {.Pin = GPIO_PIN_2, .Mode = GPIO_MODE_IT_FALLING, .Pull = GPIO_PULLUP, .Speed = GPIO_SPEED_FREQ_HIGH, .Alternate = 0},
},
};
@@ -262,9 +257,9 @@ static inline void board_init2(void) {
}
void board_vbus_set(uint8_t rhport, bool state) {
- (void) state;
- if (rhport == 1) {
- TU_ASSERT(TCPP0203_SetGateDriverProvider(&tcpp0203_obj, TCPP0203_GD_PROVIDER_SWITCH_CLOSED) == TCPP0203_OK, );
+ if (rhport == 0) {
+ uint8_t switch_state = state ? TCPP0203_GD_PROVIDER_SWITCH_CLOSED : TCPP0203_GD_PROVIDER_SWITCH_OPEN;
+ TU_ASSERT(TCPP0203_SetGateDriverProvider(&tcpp0203_obj, switch_state) == TCPP0203_OK, );
}
}
diff --git a/hw/bsp/stm32n6/boards/stm32n657nucleo/board.mk b/hw/bsp/stm32n6/boards/stm32n657nucleo/board.mk
index 05717699c..efbb82611 100644
--- a/hw/bsp/stm32n6/boards/stm32n657nucleo/board.mk
+++ b/hw/bsp/stm32n6/boards/stm32n657nucleo/board.mk
@@ -1,9 +1,12 @@
MCU_VARIANT = stm32n657xx
CFLAGS += -DSTM32N657xx
-JLINK_DEVICE = stm32n6xx
+JLINK_DEVICE = stm32n657x0
LD_FILE_GCC = $(BOARD_PATH)/STM32N657XX_AXISRAM2_fsbl.ld
+RHPORT_DEVICE ?= 0
+RHPORT_HOST ?= 0
+
# flash target using on-board stlink
flash: flash-stlink
diff --git a/hw/bsp/stm32n6/family.c b/hw/bsp/stm32n6/family.c
index 567bb7294..c839e6b3e 100644
--- a/hw/bsp/stm32n6/family.c
+++ b/hw/bsp/stm32n6/family.c
@@ -48,7 +48,8 @@
TU_ATTR_UNUSED static void Error_Handler(void) { }
void HardFault_Handler(void);
-
+static void MPU_Config(void);
+static void SystemIsolation_Config(void);
typedef struct {
GPIO_TypeDef* port;
GPIO_InitTypeDef pin_init;
@@ -87,20 +88,25 @@ static UART_HandleTypeDef UartHandle = {
// Despite being call USB2_OTG_FS on some MCUs
// OTG_FS is marked as RHPort0 by TinyUSB to be consistent across stm32 port
void USB2_OTG_HS_IRQHandler(void) {
- tusb_int_handler(0, true);
+ tusb_int_handler(1, true);
}
// Despite being call USB1_OTG_HS on some MCUs
// OTG_HS is marked as RHPort1 by TinyUSB to be consistent across stm32 port
void USB1_OTG_HS_IRQHandler(void) {
- tusb_int_handler(1, true);
+ tusb_int_handler(0, true);
}
void board_init(void) {
-
/* Enable BusFault and SecureFault handlers (HardFault is default) */
SCB->SHCSR |= (SCB_SHCSR_BUSFAULTENA_Msk | SCB_SHCSR_SECUREFAULTENA_Msk);
+ MPU_Config();
+ SystemIsolation_Config();
+
+ SCB_EnableICache();
+ SCB_EnableDCache();
+
HAL_PWREx_EnableVddA();
HAL_PWREx_EnableVddIO2();
HAL_PWREx_EnableVddIO3();
@@ -126,8 +132,6 @@ void board_init(void) {
__HAL_RCC_GPIOP_CLK_ENABLE();
__HAL_RCC_GPIOQ_CLK_ENABLE();
- // HAL_ICACHE_Enable();
-
for (uint8_t i = 0; i < TU_ARRAY_SIZE(board_pindef); i++) {
HAL_GPIO_Init(board_pindef[i].port, &board_pindef[i].pin_init);
}
@@ -155,7 +159,7 @@ void board_init(void) {
HAL_UART_Init(&UartHandle);
#endif
-
+#if (CFG_TUD_ENABLED && BOARD_TUD_RHPORT == 0) || (CFG_TUH_ENABLED && BOARD_TUH_RHPORT == 0)
__HAL_RCC_USB1_OTG_HS_CLK_ENABLE();
__HAL_RCC_PWR_CLK_ENABLE();
HAL_PWREx_EnableVddUSBVMEN();
@@ -196,11 +200,109 @@ void board_init(void) {
/* Peripheral PHY clock enable */
__HAL_RCC_USB1_OTG_HS_PHY_CLK_ENABLE();
- board_init2();
+#if CFG_TUH_ENABLED && BOARD_TUH_RHPORT == 0
+ board_vbus_set(BOARD_TUH_RHPORT, 1);
+#endif
+#endif
+
+#if (CFG_TUD_ENABLED && BOARD_TUD_RHPORT == 1) || (CFG_TUH_ENABLED && BOARD_TUH_RHPORT == 1)
+ __HAL_RCC_USB2_OTG_HS_CLK_ENABLE();
+ __HAL_RCC_PWR_CLK_ENABLE();
+ HAL_PWREx_EnableVddUSBVMEN();
+ while(__HAL_PWR_GET_FLAG(PWR_FLAG_USB33RDY));
+ HAL_PWREx_EnableVddUSB();
+
+ LL_AHB5_GRP1_ForceReset(0x00800000);
+ __HAL_RCC_USB2_OTG_HS_FORCE_RESET();
+ __HAL_RCC_USB2_OTG_HS_PHY_FORCE_RESET();
+
+ LL_RCC_HSE_SelectHSEDiv2AsDiv2Clock();
+ LL_AHB5_GRP1_ReleaseReset(0x00800000);
+
+ /* Peripheral clock enable */
+ __HAL_RCC_USB2_OTG_HS_CLK_ENABLE();
+
+ /* Required few clock cycles before accessing USB PHY Controller Registers */
+ for (volatile uint32_t i = 0; i < 10; i++) {
+ __NOP(); // No Operation instruction to create a delay
+ }
+
+ USB2_HS_PHYC->USBPHYC_CR &= ~(0x7 << 0x4);
+
+ USB2_HS_PHYC->USBPHYC_CR |= (0x1 << 16) |
+ (0x2 << 4) |
+ (0x1 << 2) |
+ 0x1U;
+
+ __HAL_RCC_USB2_OTG_HS_PHY_RELEASE_RESET();
+
+ /* Required few clock cycles before Releasing Reset */
+ for (volatile uint32_t i = 0; i < 10; i++) {
+ __NOP(); // No Operation instruction to create a delay
+ }
+
+ __HAL_RCC_USB2_OTG_HS_RELEASE_RESET();
+
+ /* Peripheral PHY clock enable */
+ __HAL_RCC_USB2_OTG_HS_PHY_CLK_ENABLE();
-#if CFG_TUH_ENABLED
+#if CFG_TUH_ENABLED && BOARD_TUH_RHPORT == 1
board_vbus_set(BOARD_TUH_RHPORT, 1);
#endif
+#endif
+
+ board_init2();
+}
+
+static void MPU_Config(void)
+{
+ MPU_Region_InitTypeDef default_config = {0};
+ MPU_Attributes_InitTypeDef attr_config = {0};
+ uint32_t primask_bit = __get_PRIMASK();
+ __disable_irq();
+
+ /* disable the MPU */
+ HAL_MPU_Disable();
+
+ /* create an attribute configuration for the MPU */
+ attr_config.Attributes = INNER_OUTER(MPU_NOT_CACHEABLE);
+ attr_config.Number = MPU_ATTRIBUTES_NUMBER0;
+
+ HAL_MPU_ConfigMemoryAttributes(&attr_config);
+
+ /* Create a non cacheable region */
+ /*Normal memory type, code execution allowed */
+ default_config.Enable = MPU_REGION_ENABLE;
+ default_config.Number = MPU_REGION_NUMBER0;
+ default_config.BaseAddress = __NON_CACHEABLE_SECTION_BEGIN;
+ default_config.LimitAddress = __NON_CACHEABLE_SECTION_END;
+ default_config.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
+ default_config.AccessPermission = MPU_REGION_ALL_RW;
+ default_config.IsShareable = MPU_ACCESS_NOT_SHAREABLE;
+ default_config.AttributesIndex = MPU_ATTRIBUTES_NUMBER0;
+ HAL_MPU_ConfigRegion(&default_config);
+
+ /* enable the MPU */
+ HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT);
+
+ /* Exit critical section to lock the system and avoid any issue around MPU mechanisme */
+ __set_PRIMASK(primask_bit);
+}
+
+static void SystemIsolation_Config(void) {
+ /* set all required IPs as secure privileged */
+ __HAL_RCC_RIFSC_CLK_ENABLE();
+ RIMC_MasterConfig_t RIMC_master = {0};
+ RIMC_master.MasterCID = RIF_CID_1;
+ RIMC_master.SecPriv = RIF_ATTRIBUTE_SEC | RIF_ATTRIBUTE_PRIV;
+
+ /*RIMC configuration*/
+ HAL_RIF_RIMC_ConfigMasterAttributes(RIF_MASTER_INDEX_OTG1, &RIMC_master);
+ HAL_RIF_RIMC_ConfigMasterAttributes(RIF_MASTER_INDEX_OTG2, &RIMC_master);
+
+ /*RISUP configuration*/
+ HAL_RIF_RISC_SetSlaveSecureAttributes(RIF_RISC_PERIPH_INDEX_OTG1HS , RIF_ATTRIBUTE_SEC | RIF_ATTRIBUTE_PRIV);
+ HAL_RIF_RISC_SetSlaveSecureAttributes(RIF_RISC_PERIPH_INDEX_OTG2HS , RIF_ATTRIBUTE_SEC | RIF_ATTRIBUTE_PRIV);
}
//--------------------------------------------------------------------+
diff --git a/hw/bsp/stm32n6/family.cmake b/hw/bsp/stm32n6/family.cmake
index 6c7aaea61..972138018 100644
--- a/hw/bsp/stm32n6/family.cmake
+++ b/hw/bsp/stm32n6/family.cmake
@@ -21,7 +21,7 @@ set(FAMILY_MCUS STM32N6 CACHE INTERNAL "")
# Port & Speed Selection
# ----------------------
if (NOT DEFINED RHPORT_DEVICE)
- set(RHPORT_DEVICE 1)
+ set(RHPORT_DEVICE 0)
endif ()
if (NOT DEFINED RHPORT_HOST)
set(RHPORT_HOST 1)
@@ -68,6 +68,7 @@ function(family_add_board BOARD_TARGET)
${ST_HAL_DRIVER}/Src/${ST_PREFIX}_hal_rcc_ex.c
${ST_HAL_DRIVER}/Src/${ST_PREFIX}_hal_uart.c
${ST_HAL_DRIVER}/Src/${ST_PREFIX}_hal_uart_ex.c
+ ${ST_HAL_DRIVER}/Src/${ST_PREFIX}_hal_rif.c
)
target_include_directories(${BOARD_TARGET} PUBLIC
${CMAKE_CURRENT_FUNCTION_LIST_DIR}
@@ -80,8 +81,8 @@ function(family_add_board BOARD_TARGET)
BOARD_TUD_MAX_SPEED=${RHPORT_DEVICE_SPEED}
BOARD_TUH_RHPORT=${RHPORT_HOST}
BOARD_TUH_MAX_SPEED=${RHPORT_HOST_SPEED}
- SEGGER_RTT_SECTION="noncacheable_buffer"
- BUFFER_SIZE_UP=0x3000
+ SEGGER_RTT_SECTION=".noncacheable"
+ BUFFER_SIZE_UP=0x4000
)
update_board(${BOARD_TARGET})
diff --git a/hw/bsp/stm32n6/family.mk b/hw/bsp/stm32n6/family.mk
index 45554e251..9fef533b1 100644
--- a/hw/bsp/stm32n6/family.mk
+++ b/hw/bsp/stm32n6/family.mk
@@ -12,7 +12,7 @@ CPU_CORE ?= cortex-m55
# ----------------------
# Port & Speed Selection
# ----------------------
-RHPORT_DEVICE ?= 1
+RHPORT_DEVICE ?= 0
RHPORT_HOST ?= 1
ifndef RHPORT_DEVICE_SPEED
@@ -32,8 +32,8 @@ CFLAGS += \
-DBOARD_TUD_MAX_SPEED=${RHPORT_DEVICE_SPEED} \
-DBOARD_TUH_RHPORT=${RHPORT_HOST} \
-DBOARD_TUH_MAX_SPEED=${RHPORT_HOST_SPEED} \
- -DSEGGER_RTT_SECTION=\"noncacheable_buffer\" \
- -DBUFFER_SIZE_UP=0x3000 \
+ -DSEGGER_RTT_SECTION="\".noncacheable\"" \
+ -DBUFFER_SIZE_UP=0x4000 \
# GCC Flags
CFLAGS_GCC += \
diff --git a/hw/bsp/stm32n6/setup_iar.mac b/hw/bsp/stm32n6/setup_iar.mac
new file mode 100644
index 000000000..b6f2bc97a
--- /dev/null
+++ b/hw/bsp/stm32n6/setup_iar.mac
@@ -0,0 +1,12 @@
+/* Called once after the target reset. */
+execUserReset()
+{
+ /* Re-load image as AIXRAM2 is erased after CPU reset */
+ __loadImage("$EXE_DIR$\\$TARGET_BNAME$.hex", 0, 0);
+
+ __restoreSoftwareBreakpoints();
+
+ #PC = __readMemory32(0x34180404, "Memory");
+
+ #SP = 0x341FFD00;
+}
diff --git a/hw/bsp/stm32n6/stm32n6.jdebug b/hw/bsp/stm32n6/stm32n6.jdebug
new file mode 100644
index 000000000..81490db5d
--- /dev/null
+++ b/hw/bsp/stm32n6/stm32n6.jdebug
@@ -0,0 +1,362 @@
+/*********************************************************************
+* (c) SEGGER Microcontroller GmbH *
+* The Embedded Experts *
+* www.segger.com *
+**********************************************************************
+
+File :
+Created : 31. Jan 2026 16:34
+Ozone Version : V3.40e
+*/
+
+/*********************************************************************
+*
+* OnProjectLoad
+*
+* Function description
+* Project load routine. Required.
+*
+**********************************************************************
+*/
+void OnProjectLoad (void) {
+ //
+ // Dialog-generated settings
+ //
+ Project.SetDevice ("STM32N657X0");
+ Project.SetHostIF ("USB", "");
+ Project.SetTargetIF ("SWD");
+ Project.SetTIFSpeed ("4 MHz");
+ Project.AddSvdFile ("$(InstallDir)/Config/CPU/Cortex-M55F.svd");
+ //
+ // User settings
+ //
+ File.Open ("$(ProjectDir)/../../../examples/device/cdc_msc/build/stm32n6570dk/RelWithDebInfo/cdc_msc.elf");
+}
+
+/*********************************************************************
+*
+* OnStartupComplete
+*
+* Function description
+* Called when program execution has reached/passed
+* the startup completion point. Optional.
+*
+**********************************************************************
+*/
+//void OnStartupComplete (void) {
+//}
+
+/*********************************************************************
+*
+* TargetReset
+*
+* Function description
+* Replaces the default target device reset routine. Optional.
+*
+* Notes
+* This example demonstrates the usage when
+* debugging an application in RAM on a Cortex-M target device.
+*
+**********************************************************************
+*/
+//void TargetReset (void) {
+//
+// unsigned int SP;
+// unsigned int PC;
+// unsigned int VectorTableAddr;
+//
+// VectorTableAddr = Elf.GetBaseAddr();
+// //
+// // Set up initial stack pointer
+// //
+// if (VectorTableAddr != 0xFFFFFFFF) {
+// SP = Target.ReadU32(VectorTableAddr);
+// Target.SetReg("SP", SP);
+// }
+// //
+// // Set up entry point PC
+// //
+// PC = Elf.GetEntryPointPC();
+//
+// if (PC != 0xFFFFFFFF) {
+// Target.SetReg("PC", PC);
+// } else if (VectorTableAddr != 0xFFFFFFFF) {
+// PC = Target.ReadU32(VectorTableAddr + 4);
+// Target.SetReg("PC", PC);
+// } else {
+// Util.Error("Project file error: failed to set entry point PC", 1);
+// }
+//}
+
+/*********************************************************************
+*
+* BeforeTargetReset
+*
+* Function description
+* Event handler routine. Optional.
+*
+**********************************************************************
+*/
+//void BeforeTargetReset (void) {
+//}
+
+/*********************************************************************
+*
+* AfterTargetReset
+*
+* Function description
+* Event handler routine. Optional.
+* The default implementation initializes SP and PC to reset values.
+**
+**********************************************************************
+*/
+void AfterTargetReset (void) {
+ _SetupTarget();
+}
+
+/*********************************************************************
+*
+* DebugStart
+*
+* Function description
+* Replaces the default debug session startup routine. Optional.
+*
+**********************************************************************
+*/
+//void DebugStart (void) {
+//}
+
+/*********************************************************************
+*
+* TargetConnect
+*
+* Function description
+* Replaces the default target IF connection routine. Optional.
+*
+**********************************************************************
+*/
+//void TargetConnect (void) {
+//}
+
+/*********************************************************************
+*
+* BeforeTargetConnect
+*
+* Function description
+* Event handler routine. Optional.
+*
+**********************************************************************
+*/
+//void BeforeTargetConnect (void) {
+//}
+
+/*********************************************************************
+*
+* AfterTargetConnect
+*
+* Function description
+* Event handler routine. Optional.
+*
+**********************************************************************
+*/
+//void AfterTargetConnect (void) {
+//}
+
+/*********************************************************************
+*
+* TargetDownload
+*
+* Function description
+* Replaces the default program download routine. Optional.
+*
+**********************************************************************
+*/
+//void TargetDownload (void) {
+//}
+
+/*********************************************************************
+*
+* BeforeTargetDownload
+*
+* Function description
+* Event handler routine. Optional.
+*
+**********************************************************************
+*/
+//void BeforeTargetDownload (void) {
+//}
+
+/*********************************************************************
+*
+* AfterTargetDownload
+*
+* Function description
+* Event handler routine. Optional.
+* The default implementation initializes SP and PC to reset values.
+*
+**********************************************************************
+*/
+void AfterTargetDownload (void) {
+ //_SetupTarget();
+}
+
+/*********************************************************************
+*
+* BeforeTargetDisconnect
+*
+* Function description
+* Event handler routine. Optional.
+*
+**********************************************************************
+*/
+//void BeforeTargetDisconnect (void) {
+//}
+
+/*********************************************************************
+*
+* AfterTargetDisconnect
+*
+* Function description
+* Event handler routine. Optional.
+*
+**********************************************************************
+*/
+//void AfterTargetDisconnect (void) {
+//}
+
+/*********************************************************************
+*
+* AfterTargetHalt
+*
+* Function description
+* Event handler routine. Optional.
+*
+**********************************************************************
+*/
+//void AfterTargetHalt (void) {
+//}
+
+/*********************************************************************
+*
+* BeforeTargetResume
+*
+* Function description
+* Event handler routine. Optional.
+*
+**********************************************************************
+*/
+//void BeforeTargetResume (void) {
+//}
+
+/*********************************************************************
+*
+* OnSnapshotLoad
+*
+* Function description
+* Called upon loading a snapshot. Optional.
+*
+* Additional information
+* This function is used to restore the target state in cases
+* where values cannot simply be written to the target.
+* Typical use: GPIO clock needs to be enabled, before
+* GPIO is configured.
+*
+**********************************************************************
+*/
+//void OnSnapshotLoad (void) {
+//}
+
+/*********************************************************************
+*
+* OnSnapshotSave
+*
+* Function description
+* Called upon saving a snapshot. Optional.
+*
+* Additional information
+* This function is usually used to save values of the target
+* state which can either not be trivially read,
+* or need to be restored in a specific way or order.
+* Typically use: Memory Mapped Registers,
+* such as PLL and GPIO configuration.
+*
+**********************************************************************
+*/
+//void OnSnapshotSave (void) {
+//}
+
+/*********************************************************************
+*
+* OnError
+*
+* Function description
+* Called when an error occurred. Optional.
+*
+**********************************************************************
+*/
+//void OnError (void) {
+//}
+
+/*********************************************************************
+*
+* AfterProjectLoad
+*
+* Function description
+* After Project load routine. Optional.
+*
+**********************************************************************
+*/
+//void AfterProjectLoad (void) {
+//}
+
+/*********************************************************************
+*
+* OnDebugStartBreakSymbolReached
+*
+* Function description
+* Called when program execution has reached/passed
+* the symbol to be breaked at during debug start. Optional.
+*
+**********************************************************************
+*/
+//void OnDebugStartBreakSymReached (void) {
+//}
+
+/*********************************************************************
+*
+* _SetupTarget
+*
+* Function description
+* Setup the target.
+* Called by AfterTargetReset() and AfterTargetDownload().
+*
+* Auto-generated function. May be overridden by Ozone.
+*
+**********************************************************************
+*/
+void _SetupTarget(void) {
+ unsigned int SP;
+ unsigned int PC;
+ unsigned int VectorTableAddr;
+
+ Debug.Download();
+ Debug.Halt();
+
+ VectorTableAddr = Elf.GetBaseAddr();
+ //
+ // Set up initial stack pointer
+ //
+ SP = Target.ReadU32(VectorTableAddr);
+ if (SP != 0xFFFFFFFF) {
+ Target.SetReg("SP", SP);
+ }
+ //
+ // Set up entry point PC
+ //
+ PC = Elf.GetEntryPointPC();
+ if (PC != 0xFFFFFFFF) {
+ Target.SetReg("PC", PC);
+ } else {
+ Util.Error("Project script error: failed to set up entry point PC", 1);
+ }
+}
diff --git a/hw/bsp/stm32n6/stm32n6xx_hal_conf.h b/hw/bsp/stm32n6/stm32n6xx_hal_conf.h
index 00cb31159..49ca767fe 100644
--- a/hw/bsp/stm32n6/stm32n6xx_hal_conf.h
+++ b/hw/bsp/stm32n6/stm32n6xx_hal_conf.h
@@ -67,7 +67,7 @@
/*#define HAL_PKA_MODULE_ENABLED */
/*#define HAL_PSSI_MODULE_ENABLED */
/*#define HAL_RAMCFG_MODULE_ENABLED */
-/*#define HAL_RIF_MODULE_ENABLED */
+#define HAL_RIF_MODULE_ENABLED
/*#define HAL_RNG_MODULE_ENABLED */
/*#define HAL_RTC_MODULE_ENABLED */
/*#define HAL_SAI_MODULE_ENABLED */
diff --git a/hw/bsp/stm32u5/boards/b_u585i_iot2a/board.h b/hw/bsp/stm32u5/boards/b_u585i_iot2a/board.h
index cf3f63ea5..c99743738 100644
--- a/hw/bsp/stm32u5/boards/b_u585i_iot2a/board.h
+++ b/hw/bsp/stm32u5/boards/b_u585i_iot2a/board.h
@@ -55,6 +55,8 @@ extern "C"
#define UART_TX_PIN GPIO_PIN_9
#define UART_RX_PIN GPIO_PIN_10
+#define VBUS_SENSE_EN 0
+
//--------------------------------------------------------------------+
// RCC Clock
//--------------------------------------------------------------------+
@@ -110,6 +112,9 @@ static void SystemClock_Config(void) {
static void SystemPower_Config(void) {
}
+static inline void board_vbus_sense_init(void) {
+}
+
#ifdef __cplusplus
}
#endif
diff --git a/hw/bsp/stm32u5/boards/stm32u545nucleo/board.h b/hw/bsp/stm32u5/boards/stm32u545nucleo/board.h
index 0c3439b2c..eb2b63721 100644
--- a/hw/bsp/stm32u5/boards/stm32u545nucleo/board.h
+++ b/hw/bsp/stm32u5/boards/stm32u545nucleo/board.h
@@ -110,6 +110,9 @@ static void SystemClock_Config(void) {
static void SystemPower_Config(void) {
}
+static inline void board_vbus_sense_init(void) {
+}
+
#ifdef __cplusplus
}
#endif
diff --git a/hw/bsp/stm32u5/boards/stm32u575eval/board.h b/hw/bsp/stm32u5/boards/stm32u575eval/board.h
index b11f6a747..cce3e38b3 100644
--- a/hw/bsp/stm32u5/boards/stm32u575eval/board.h
+++ b/hw/bsp/stm32u5/boards/stm32u575eval/board.h
@@ -56,6 +56,8 @@ extern "C"
#define UART_TX_PIN GPIO_PIN_9
#define UART_RX_PIN GPIO_PIN_10
+#define VBUS_SENSE_EN 0
+
//--------------------------------------------------------------------+
// RCC Clock
//--------------------------------------------------------------------+
@@ -111,6 +113,9 @@ static void SystemClock_Config(void) {
static void SystemPower_Config(void) {
}
+static inline void board_vbus_sense_init(void) {
+}
+
#ifdef __cplusplus
}
#endif
diff --git a/hw/bsp/stm32u5/boards/stm32u575nucleo/board.h b/hw/bsp/stm32u5/boards/stm32u575nucleo/board.h
index be037b68a..b6b60f021 100644
--- a/hw/bsp/stm32u5/boards/stm32u575nucleo/board.h
+++ b/hw/bsp/stm32u5/boards/stm32u575nucleo/board.h
@@ -37,6 +37,8 @@ extern "C"
{
#endif
+#include "stm32u5xx_ll_tim.h"
+
// LED GREEN
#define LED_PORT GPIOC
#define LED_PIN GPIO_PIN_7
@@ -55,6 +57,8 @@ extern "C"
#define UART_TX_PIN GPIO_PIN_7
#define UART_RX_PIN GPIO_PIN_8
+#define VBUS_SENSE_EN 0
+
//--------------------------------------------------------------------+
// RCC Clock
//--------------------------------------------------------------------+
@@ -110,6 +114,104 @@ static void SystemClock_Config(void) {
static void SystemPower_Config(void) {
}
+static inline void board_vbus_sense_init(void) {
+ /* ADC config */
+ GPIO_InitTypeDef GPIO_InitStruct = {0};
+ RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
+ PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADCDAC;
+ PeriphClkInit.AdcDacClockSelection = RCC_ADCDACCLKSOURCE_HSE;
+ if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
+ {
+ Error_Handler();
+ }
+ __HAL_RCC_ADC12_CLK_ENABLE();
+ __HAL_RCC_GPIOC_CLK_ENABLE();
+ GPIO_InitStruct.Pin = GPIO_PIN_2;
+ GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
+
+ ADC_HandleTypeDef hadc1;
+ hadc1.Instance = ADC1;
+ hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;
+ hadc1.Init.Resolution = ADC_RESOLUTION_14B;
+ hadc1.Init.GainCompensation = 0;
+ hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
+ hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;
+ hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
+ hadc1.Init.LowPowerAutoWait = DISABLE;
+ hadc1.Init.ContinuousConvMode = DISABLE;
+ hadc1.Init.NbrOfConversion = 1;
+ hadc1.Init.DiscontinuousConvMode = DISABLE;
+ hadc1.Init.ExternalTrigConv = ADC_EXTERNALTRIG_T1_TRGO;
+ hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_RISING;
+ hadc1.Init.DMAContinuousRequests = DISABLE;
+ hadc1.Init.TriggerFrequencyMode = ADC_TRIGGER_FREQ_HIGH;
+ hadc1.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN;
+ hadc1.Init.LeftBitShift = ADC_LEFTBITSHIFT_NONE;
+ hadc1.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DR;
+ hadc1.Init.OversamplingMode = DISABLE;
+ if (HAL_ADC_Init(&hadc1) != HAL_OK) {
+ Error_Handler();
+ }
+
+ ADC_ChannelConfTypeDef sConfig = {0};
+ sConfig.Channel = ADC_CHANNEL_3;
+ sConfig.Rank = ADC_REGULAR_RANK_1;
+ sConfig.SamplingTime = ADC_SAMPLETIME_68CYCLES;
+ sConfig.SingleDiff = ADC_SINGLE_ENDED;
+ sConfig.OffsetNumber = ADC_OFFSET_NONE;
+ sConfig.Offset = 0;
+ if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) {
+ Error_Handler();
+ }
+ HAL_NVIC_EnableIRQ(ADC1_IRQn);
+
+ /* TIM1 init for TRGO */
+ __HAL_RCC_TIM1_CLK_ENABLE();
+ TIM_HandleTypeDef htim1;
+ TIM_ClockConfigTypeDef sClockSourceConfig = {0};
+ htim1.Instance = TIM1;
+ htim1.Init.Prescaler = 159;
+ htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
+ htim1.Init.Period = 999;
+ htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
+ htim1.Init.RepetitionCounter = 0;
+ htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
+ if (HAL_TIM_Base_Init(&htim1) != HAL_OK) {
+ Error_Handler();
+ }
+ sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
+ if (HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK) {
+ Error_Handler();
+ }
+ LL_TIM_SetTriggerOutput(htim1.Instance, LL_TIM_TRGO_UPDATE);
+
+ HAL_ADCEx_Calibration_Start(&hadc1, ADC_CALIB_OFFSET, ADC_SINGLE_ENDED);
+ HAL_ADC_Start_IT(&hadc1);
+ HAL_TIM_Base_Start(&htim1);
+}
+
+void ADC1_IRQHandler(void) {
+ if(LL_ADC_IsActiveFlag_EOC(ADC1) != 0) {
+ /* Clear flag ADC group regular end of unitary conversion */
+ LL_ADC_ClearFlag_EOC(ADC1);
+ /* ADC code = 4.5V * R2 / (R1 + R2) * (2^14) / 3.3V
+ * with R1 = 330kOhm and R2 = 50kOhm
+ */
+ const uint32_t threshold = 4500 * 50 / (50 + 330) * 16384 / 3300;
+ if((ADC1->DR > threshold) && (USB_OTG_FS->GOTGCTL & USB_OTG_GOTGCTL_BVALOEN)) {
+ USB_OTG_FS->GOTGCTL |= USB_OTG_GOTGCTL_BVALOVAL;
+ } else {
+ USB_OTG_FS->GOTGCTL &= ~USB_OTG_GOTGCTL_BVALOVAL;
+ }
+ }
+ if(LL_ADC_IsActiveFlag_OVR(ADC1) != 0) {
+ /* Clear flag ADC group regular overrun */
+ LL_ADC_ClearFlag_OVR(ADC1);
+ }
+}
+
#ifdef __cplusplus
}
#endif
diff --git a/hw/bsp/stm32u5/boards/stm32u5a5nucleo/board.h b/hw/bsp/stm32u5/boards/stm32u5a5nucleo/board.h
index 0785fb36b..15106aee6 100644
--- a/hw/bsp/stm32u5/boards/stm32u5a5nucleo/board.h
+++ b/hw/bsp/stm32u5/boards/stm32u5a5nucleo/board.h
@@ -37,6 +37,8 @@ extern "C"
{
#endif
+#include "stm32u5xx_ll_tim.h"
+
// LED GREEN
#define LED_PORT GPIOC
#define LED_PIN GPIO_PIN_7
@@ -55,11 +57,13 @@ extern "C"
#define UART_TX_PIN GPIO_PIN_9
#define UART_RX_PIN GPIO_PIN_10
+#define VBUS_SENSE_EN 0
+
//--------------------------------------------------------------------+
// RCC Clock
//--------------------------------------------------------------------+
-static void SystemClock_Config(void) {
+static inline void SystemClock_Config(void) {
RCC_OscInitTypeDef RCC_OscInitStruct = { 0 };
RCC_ClkInitTypeDef RCC_ClkInitStruct = { 0 };
@@ -128,7 +132,7 @@ static void SystemClock_Config(void) {
}
}
-static void SystemPower_Config(void) {
+static inline void SystemPower_Config(void) {
HAL_PWREx_EnableVddIO2();
/*
@@ -141,7 +145,105 @@ static void SystemPower_Config(void) {
/* USER CODE END PWR */
}
+static inline void board_vbus_sense_init(void) {
+ /* ADC config */
+ GPIO_InitTypeDef GPIO_InitStruct = {0};
+ RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
+ PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADCDAC;
+ PeriphClkInit.AdcDacClockSelection = RCC_ADCDACCLKSOURCE_HSE;
+ if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
+ {
+ Error_Handler();
+ }
+ __HAL_RCC_ADC12_CLK_ENABLE();
+ __HAL_RCC_GPIOC_CLK_ENABLE();
+ GPIO_InitStruct.Pin = GPIO_PIN_2;
+ GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
+
+ ADC_HandleTypeDef hadc1;
+ hadc1.Instance = ADC1;
+ hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;
+ hadc1.Init.Resolution = ADC_RESOLUTION_14B;
+ hadc1.Init.GainCompensation = 0;
+ hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
+ hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;
+ hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
+ hadc1.Init.LowPowerAutoWait = DISABLE;
+ hadc1.Init.ContinuousConvMode = DISABLE;
+ hadc1.Init.NbrOfConversion = 1;
+ hadc1.Init.DiscontinuousConvMode = DISABLE;
+ hadc1.Init.ExternalTrigConv = ADC_EXTERNALTRIG_T1_TRGO;
+ hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_RISING;
+ hadc1.Init.DMAContinuousRequests = DISABLE;
+ hadc1.Init.TriggerFrequencyMode = ADC_TRIGGER_FREQ_HIGH;
+ hadc1.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN;
+ hadc1.Init.LeftBitShift = ADC_LEFTBITSHIFT_NONE;
+ hadc1.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DR;
+ hadc1.Init.OversamplingMode = DISABLE;
+ if (HAL_ADC_Init(&hadc1) != HAL_OK) {
+ Error_Handler();
+ }
+
+ ADC_ChannelConfTypeDef sConfig = {0};
+ sConfig.Channel = ADC_CHANNEL_3;
+ sConfig.Rank = ADC_REGULAR_RANK_1;
+ sConfig.SamplingTime = ADC_SAMPLETIME_68CYCLES;
+ sConfig.SingleDiff = ADC_SINGLE_ENDED;
+ sConfig.OffsetNumber = ADC_OFFSET_NONE;
+ sConfig.Offset = 0;
+ if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) {
+ Error_Handler();
+ }
+ HAL_NVIC_EnableIRQ(ADC1_2_IRQn);
+
+ /* TIM1 init for TRGO */
+ __HAL_RCC_TIM1_CLK_ENABLE();
+ TIM_HandleTypeDef htim1;
+ TIM_ClockConfigTypeDef sClockSourceConfig = {0};
+ htim1.Instance = TIM1;
+ htim1.Init.Prescaler = 159;
+ htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
+ htim1.Init.Period = 999;
+ htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
+ htim1.Init.RepetitionCounter = 0;
+ htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
+ if (HAL_TIM_Base_Init(&htim1) != HAL_OK) {
+ Error_Handler();
+ }
+ sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
+ if (HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK) {
+ Error_Handler();
+ }
+ LL_TIM_SetTriggerOutput(htim1.Instance, LL_TIM_TRGO_UPDATE);
+
+ HAL_ADCEx_Calibration_Start(&hadc1, ADC_CALIB_OFFSET, ADC_SINGLE_ENDED);
+ HAL_ADC_Start_IT(&hadc1);
+ HAL_TIM_Base_Start(&htim1);
+}
+void ADC1_2_IRQHandler(void) {
+ if(LL_ADC_IsActiveFlag_EOC(ADC1) != 0) {
+ /* Clear flag ADC group regular end of unitary conversion */
+ LL_ADC_ClearFlag_EOC(ADC1);
+ /* ADC code = 4.5V * R2 / (R1 + R2) * (2^14) / 3.3V
+ * with R1 = 330kOhm and R2 = 50kOhm
+ */
+ const uint32_t threshold = 4500 * 50 / (50 + 330) * 16384 / 3300;
+ if((ADC1->DR > threshold) && (USB_OTG_HS->GOTGCTL & USB_OTG_GOTGCTL_BVALOEN)) {
+ USB_OTG_HS->GOTGCTL |= USB_OTG_GOTGCTL_BVALOVAL;
+ USB_OTG_HS->GCCFG |= USB_OTG_GCCFG_VBVALOVAL;
+ } else {
+ USB_OTG_HS->GOTGCTL &= ~USB_OTG_GOTGCTL_BVALOVAL;
+ USB_OTG_HS->GCCFG &= ~USB_OTG_GCCFG_VBVALOVAL;
+ }
+ }
+ if(LL_ADC_IsActiveFlag_OVR(ADC1) != 0) {
+ /* Clear flag ADC group regular overrun */
+ LL_ADC_ClearFlag_OVR(ADC1);
+ }
+}
#ifdef __cplusplus
}
#endif
diff --git a/hw/bsp/stm32u5/family.c b/hw/bsp/stm32u5/family.c
index 26d72d6a0..dfcf5c537 100644
--- a/hw/bsp/stm32u5/family.c
+++ b/hw/bsp/stm32u5/family.c
@@ -179,18 +179,14 @@ void board_init(void) {
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
-
- // Enable VBUS sense (B device) via pin PA9
- USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBDEN;
- #else
- // Disable VBUS sense (B device) via pin PA9
- USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_VBDEN;
-
- // B-peripheral session valid override enable
- USB_OTG_FS->GOTGCTL |= USB_OTG_GOTGCTL_BVALOEN;
- USB_OTG_FS->GOTGCTL |= USB_OTG_GOTGCTL_BVALOVAL;
#endif // vbus sense
+#if CFG_TUD_ENABLED
+ tud_configure_dwc2_t cfg = CFG_TUD_CONFIGURE_DWC2_DEFAULT;
+ cfg.vbus_sensing = VBUS_SENSE_EN;
+ tud_configure(0, TUD_CFGID_DWC2, &cfg);
+#endif
+
/* Enable USB power on Pwrctrl CR2 register */
HAL_PWREx_EnableVddUSB();
@@ -218,13 +214,15 @@ void board_init(void) {
/*Configuring the SYSCFG registers OTG_HS PHY*/
HAL_SYSCFG_EnableOTGPHY(SYSCFG_OTG_HS_PHY_ENABLE);
- // Disable VBUS sense (B device)
- USB_OTG_HS->GCCFG &= ~USB_OTG_GCCFG_VBDEN;
-
- // B-peripheral session valid override enable
- USB_OTG_HS->GCCFG |= USB_OTG_GCCFG_VBVALEXTOEN;
- USB_OTG_HS->GCCFG |= USB_OTG_GCCFG_VBVALOVAL;
+#if CFG_TUD_ENABLED
+ tud_configure_dwc2_t cfg = CFG_TUD_CONFIGURE_DWC2_DEFAULT;
+ cfg.vbus_sensing = VBUS_SENSE_EN;
+ tud_configure(0, TUD_CFGID_DWC2, &cfg);
+#endif
#endif // USB_OTG_FS
+
+ /* Non-standard VBus sense settings */
+ board_vbus_sense_init();
}
//--------------------------------------------------------------------+
diff --git a/hw/bsp/stm32u5/family.cmake b/hw/bsp/stm32u5/family.cmake
index 58dc63ae3..3d23c554d 100644
--- a/hw/bsp/stm32u5/family.cmake
+++ b/hw/bsp/stm32u5/family.cmake
@@ -45,6 +45,9 @@ function(family_add_board BOARD_TARGET)
${ST_HAL_DRIVER}/Src/${ST_PREFIX}_hal_rcc_ex.c
${ST_HAL_DRIVER}/Src/${ST_PREFIX}_hal_uart.c
${ST_HAL_DRIVER}/Src/${ST_PREFIX}_hal_uart_ex.c
+ ${ST_HAL_DRIVER}/Src/${ST_PREFIX}_hal_adc.c
+ ${ST_HAL_DRIVER}/Src/${ST_PREFIX}_hal_adc_ex.c
+ ${ST_HAL_DRIVER}/Src/${ST_PREFIX}_hal_tim.c
)
target_include_directories(${BOARD_TARGET} PUBLIC
${CMAKE_CURRENT_FUNCTION_LIST_DIR}
@@ -96,7 +99,7 @@ function(family_configure_example TARGET RTOS)
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(${CMAKE_CURRENT_FUNCTION_LIST_DIR}/family.c PROPERTIES COMPILE_FLAGS "-Wno-missing-prototypes -Wno-self-assign")
endif ()
set_source_files_properties(${STARTUP_FILE_${CMAKE_C_COMPILER_ID}} PROPERTIES
SKIP_LINTING ON
diff --git a/hw/bsp/stm32u5/family.mk b/hw/bsp/stm32u5/family.mk
index 47aed10a9..3dab8c610 100644
--- a/hw/bsp/stm32u5/family.mk
+++ b/hw/bsp/stm32u5/family.mk
@@ -16,6 +16,7 @@ CFLAGS_GCC += \
-Wno-error=undef \
-Wno-error=unused-parameter \
-Wno-error=type-limits \
+ -Wno-self-assign \
ifeq ($(TOOLCHAIN),gcc)
CFLAGS_GCC += -Wno-error=maybe-uninitialized
@@ -35,11 +36,15 @@ SRC_C += \
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_pwr_ex.c \
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_rcc.c \
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_rcc_ex.c \
- $(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_uart.c
+ $(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_uart.c \
+ $(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_adc.c \
+ $(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_adc_ex.c \
+ $(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_tim.c
ifneq ($(filter stm32u545xx stm32u535xx,$(MCU_VARIANT)),)
SRC_C += \
src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c \
+ src/portable/st/stm32_fsdev/hcd_stm32_fsdev.c \
src/portable/st/stm32_fsdev/fsdev_common.c
else
SRC_C += \
diff --git a/hw/bsp/stm32u5/stm32u5xx_hal_conf.h b/hw/bsp/stm32u5/stm32u5xx_hal_conf.h
index 87c3683de..5d95862f6 100644
--- a/hw/bsp/stm32u5/stm32u5xx_hal_conf.h
+++ b/hw/bsp/stm32u5/stm32u5xx_hal_conf.h
@@ -36,7 +36,7 @@
#define HAL_MODULE_ENABLED
-/*#define HAL_ADC_MODULE_ENABLED */
+#define HAL_ADC_MODULE_ENABLED
/*#define HAL_MDF_MODULE_ENABLED */
/*#define HAL_COMP_MODULE_ENABLED */
/*#define HAL_CORDIC_MODULE_ENABLED */
@@ -76,7 +76,7 @@
/*#define HAL_SMBUS_MODULE_ENABLED */
/*#define HAL_SPI_MODULE_ENABLED */
/*#define HAL_SRAM_MODULE_ENABLED */
-/*#define HAL_TIM_MODULE_ENABLED */
+#define HAL_TIM_MODULE_ENABLED
/*#define HAL_TSC_MODULE_ENABLED */
/*#define HAL_RAMCFG_MODULE_ENABLED */
#define HAL_UART_MODULE_ENABLED
diff --git a/hw/bsp/stm32wba/family.c b/hw/bsp/stm32wba/family.c
index 8dc6547ae..d05415755 100644
--- a/hw/bsp/stm32wba/family.c
+++ b/hw/bsp/stm32wba/family.c
@@ -172,14 +172,7 @@ void board_init(void) {
// Configuring the SYSCFG registers OTG_HS PHY
SYSCFG->OTGHSPHYCR |= SYSCFG_OTGHSPHYCR_EN;
-
- // Disable VBUS sense (B device)
- USB_OTG_HS->GCCFG &= ~USB_OTG_GCCFG_VBDEN;
-
- // B-peripheral session valid override enable
- USB_OTG_HS->GCCFG |= USB_OTG_GCCFG_VBVALEXTOEN;
- USB_OTG_HS->GCCFG |= USB_OTG_GCCFG_VBVALOVAL;
- #endif // USB_OTG_FS
+ #endif // USB_OTG_HS
}
void board_led_write(bool state) { HAL_GPIO_WritePin(LED_PORT, LED_PIN, state ? LED_STATE_ON : (1 - LED_STATE_ON)); }
diff --git a/hw/bsp/tm4c/FreeRTOSConfig/FreeRTOSConfig.h b/hw/bsp/tm4c/FreeRTOSConfig/FreeRTOSConfig.h
index 454b085e9..b4423e269 100644
--- a/hw/bsp/tm4c/FreeRTOSConfig/FreeRTOSConfig.h
+++ b/hw/bsp/tm4c/FreeRTOSConfig/FreeRTOSConfig.h
@@ -44,7 +44,13 @@
// skip if included from IAR assembler
#ifndef __IASMARM__
- #include "TM4C123.h"
+ #ifdef TM4C123GH6PM
+ #include "TM4C123.h"
+ #elif TM4C1294NCPDT
+ #include "TM4C129.h"
+ #else
+ #error "Unknown TM4C device"
+ #endif
#endif
/* Cortex M23/M33 port configuration. */
diff --git a/hw/bsp/tm4c/boards/ek_tm4c123gxl/board.h b/hw/bsp/tm4c/boards/ek_tm4c123gxl/board.h
index c0ceb4cd8..fc0ab4c60 100644
--- a/hw/bsp/tm4c/boards/ek_tm4c123gxl/board.h
+++ b/hw/bsp/tm4c/boards/ek_tm4c123gxl/board.h
@@ -36,20 +36,26 @@
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
diff --git a/hw/bsp/tm4c/boards/ek_tm4c123gxl/tm4c123.ld b/hw/bsp/tm4c/boards/ek_tm4c123gxl/tm4c123.ld
index 11e9608cc..3f06d8f03 100644
--- a/hw/bsp/tm4c/boards/ek_tm4c123gxl/tm4c123.ld
+++ b/hw/bsp/tm4c/boards/ek_tm4c123gxl/tm4c123.ld
@@ -17,7 +17,7 @@ SECTIONS
.text :
{
. = ALIGN(4) ;
- *(.vectors)
+ KEEP(*(.vectors))
*(.text)
*(.text.*)
*(.init)
diff --git a/hw/bsp/tm4c/boards/ek_tm4c1294xl/TM4C1294NC.icf b/hw/bsp/tm4c/boards/ek_tm4c1294xl/TM4C1294NC.icf
new file mode 100644
index 000000000..2dba41866
--- /dev/null
+++ b/hw/bsp/tm4c/boards/ek_tm4c1294xl/TM4C1294NC.icf
@@ -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 };
diff --git a/hw/bsp/tm4c/boards/ek_tm4c1294xl/board.cmake b/hw/bsp/tm4c/boards/ek_tm4c1294xl/board.cmake
new file mode 100644
index 000000000..3e03b3f72
--- /dev/null
+++ b/hw/bsp/tm4c/boards/ek_tm4c1294xl/board.cmake
@@ -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()
diff --git a/hw/bsp/tm4c/boards/ek_tm4c1294xl/board.h b/hw/bsp/tm4c/boards/ek_tm4c1294xl/board.h
new file mode 100644
index 000000000..4530e9430
--- /dev/null
+++ b/hw/bsp/tm4c/boards/ek_tm4c1294xl/board.h
@@ -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
diff --git a/hw/bsp/tm4c/boards/ek_tm4c1294xl/board.mk b/hw/bsp/tm4c/boards/ek_tm4c1294xl/board.mk
new file mode 100644
index 000000000..b01977674
--- /dev/null
+++ b/hw/bsp/tm4c/boards/ek_tm4c1294xl/board.mk
@@ -0,0 +1,16 @@
+MCU_SUB_VARIANT = 129
+
+CFLAGS += -DTM4C1294NCPDT
+
+LD_FILE_GCC = $(BOARD_PATH)/tm4c1294nc.ld
+LD_FILE_IAR = $(BOARD_PATH)/TM4C1294NC.icf
+
+# 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
diff --git a/hw/bsp/tm4c/boards/ek_tm4c1294xl/tm4c1294nc.ld b/hw/bsp/tm4c/boards/ek_tm4c1294xl/tm4c1294nc.ld
new file mode 100644
index 000000000..fa4ea4dc5
--- /dev/null
+++ b/hw/bsp/tm4c/boards/ek_tm4c1294xl/tm4c1294nc.ld
@@ -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
+}
diff --git a/hw/bsp/tm4c/family.c b/hw/bsp/tm4c/family.c
index ee1fa2a3c..ae7f22f00 100644
--- a/hw/bsp/tm4c/family.c
+++ b/hw/bsp/tm4c/family.c
@@ -2,7 +2,6 @@
manufacturer: Texas Instruments
*/
-#include "TM4C123.h"
#include "bsp/board_api.h"
#include "board.h"
@@ -27,6 +26,9 @@ 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
@@ -44,12 +46,26 @@ static void board_uart_init(void) {
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);
+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;
+}
+
+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 << 5))) {}
+ while (!((SYSCTL->PRGPIO) & (1 << LED_PORT_CLK))) {}
/* Port Digital Enable */
port->DEN |= PinMsk;
@@ -71,7 +87,9 @@ static uint32_t ReadGPIOPin(GPIOA_Type* port, uint8_t pinMsk) {
}
void board_init(void) {
+#ifdef TM4C123_H
SystemCoreClockUpdate();
+#endif
#if CFG_TUSB_OS == OPT_OS_NONE
// 1ms tick timer
@@ -83,6 +101,7 @@ void board_init(void) {
NVIC_SetPriority(USB0_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY );
#endif
+#ifdef TM4C123_H
/* Reset USB */
SYSCTL->SRCR2 |= (1u << 16);
@@ -99,7 +118,7 @@ void board_init(void) {
/* USB IO Initialization */
SYSCTL->RCGCGPIO |= (1u << 3);
- /* Let the clock stabilize */
+ /* Let the clock stabilize */
while (!(SYSCTL->PRGPIO & (1u << 3))) {}
/* USB IOs to Analog Mode */
@@ -107,16 +126,43 @@ void board_init(void) {
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);
+#else // TM4C129
+ /* Reset USB */
+ SYSCTL->SRUSB = 1;
- /* Configure GPIO for board LED */
- initialize_board_led(LED_PORT, leds, dirmsk);
+ for (volatile uint8_t i = 0; i < 20; i++) {}
+
+ SYSCTL->SRUSB = 0;
- /* Configure GPIO for board switch */
- GPIOF->DIR &= ~(1 << BOARD_BTN);
- GPIOF->PUR |= (1 << BOARD_BTN);
- GPIOF->DEN |= (1 << BOARD_BTN);
+ /* 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();
@@ -125,7 +171,7 @@ void board_init(void) {
}
void board_led_write(bool state) {
- WriteGPIOPin(LED_PORT, (1 << LED_PIN_BLUE), state);
+ WriteGPIOPin(LED_PORT, (1 << BOARD_LED_PIN), state);
}
uint32_t board_button_read(void) {
diff --git a/hw/bsp/tm4c/family.cmake b/hw/bsp/tm4c/family.cmake
index 12f0448a3..41b8a597a 100644
--- a/hw/bsp/tm4c/family.cmake
+++ b/hw/bsp/tm4c/family.cmake
@@ -5,14 +5,14 @@ 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(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 TM4C123 CACHE INTERNAL "")
+set(FAMILY_MCUS TM4C CACHE INTERNAL "")
#------------------------------------
# Startup & Linker script
@@ -20,7 +20,7 @@ set(FAMILY_MCUS TM4C123 CACHE INTERNAL "")
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
#------------------------------------
@@ -29,7 +29,7 @@ function(family_add_board BOARD_TARGET)
${SDK_DIR}/Source/system_${MCU_VARIANT_UPPER}.c
)
target_include_directories(${BOARD_TARGET} PUBLIC
- ${SDK_DIR}/Include/${MCU_VARIANT_UPPER}
+ ${SDK_DIR}/Include
${CMSIS_DIR}/CMSIS/Core/Include
)
@@ -41,7 +41,7 @@ endfunction()
#------------------------------------
function(family_configure_example TARGET RTOS)
family_configure_common(${TARGET} ${RTOS})
- family_add_tinyusb(${TARGET} OPT_MCU_TM4C123)
+ family_add_tinyusb(${TARGET} OPT_MCU_TM4C${MCU_SUB_VARIANT})
target_sources(${TARGET} PUBLIC
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/family.c
@@ -71,13 +71,14 @@ function(family_configure_example TARGET RTOS)
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 ()
- set_source_files_properties(${STARTUP_FILE_${CMAKE_C_COMPILER_ID}} PROPERTIES
- SKIP_LINTING ON
- COMPILE_OPTIONS -w)
# Flashing
family_add_bin_hex(${TARGET})
+ family_flash_jlink(${TARGET})
family_flash_openocd(${TARGET})
family_flash_uniflash(${TARGET})
endfunction()
diff --git a/hw/bsp/tm4c/family.mk b/hw/bsp/tm4c/family.mk
index 76ae785b2..bc966d98e 100644
--- a/hw/bsp/tm4c/family.mk
+++ b/hw/bsp/tm4c/family.mk
@@ -4,11 +4,11 @@ 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
+SDK_DIR = hw/mcu/ti/tm4c
CFLAGS += \
-flto \
- -DCFG_TUSB_MCU=OPT_MCU_TM4C123 \
+ -DCFG_TUSB_MCU=OPT_MCU_TM4C${MCU_SUB_VARIANT} \
-uvectors \
# mcu driver cause following warnings
@@ -18,7 +18,7 @@ LDFLAGS_GCC += --specs=nosys.specs --specs=nano.specs
INC += \
$(TOP)/lib/CMSIS_5/CMSIS/Core/Include \
- $(TOP)/$(SDK_DIR)/Include/${MCU_VARIANT_UPPER} \
+ $(TOP)/$(SDK_DIR)/Include \
$(TOP)/$(BOARD_PATH)
SRC_C += \