summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzhiqiang <[email protected]>2025-09-04 14:38:27 +0800
committerzhiqiang <[email protected]>2025-09-04 14:38:27 +0800
commitf6ca80ab13997d8fdee084d218c22ae15d734e2a (patch)
treeeca66dc58da7ae0b40bf70ed055bb49868232e0f
parent93487deab7449261fd42a2b7ceeffdbec469dc83 (diff)
modified the bsp files of at32 to make them work better
-rw-r--r--docs/reference/boards.rst26
-rw-r--r--hw/bsp/at32f402_405/boards/at_start_f402/board.cmake8
-rw-r--r--hw/bsp/at32f402_405/boards/at_start_f402/board.h74
-rw-r--r--hw/bsp/at32f402_405/boards/at_start_f402/board.mk7
-rw-r--r--hw/bsp/at32f402_405/boards/at_start_f405/board.cmake9
-rw-r--r--hw/bsp/at32f402_405/boards/at_start_f405/board.h106
-rw-r--r--hw/bsp/at32f402_405/boards/at_start_f405/board.mk4
-rw-r--r--hw/bsp/at32f402_405/family.c32
-rw-r--r--hw/bsp/at32f402_405/family.cmake23
-rw-r--r--hw/bsp/at32f402_405/family.mk28
-rw-r--r--hw/bsp/at32f403a_407/boards/at_start_f403a/board.cmake2
-rw-r--r--hw/bsp/at32f403a_407/boards/at_start_f403a/board.mk2
-rw-r--r--hw/bsp/at32f403a_407/boards/at_start_f407/board.cmake8
-rw-r--r--hw/bsp/at32f403a_407/boards/at_start_f407/board.h71
-rw-r--r--hw/bsp/at32f403a_407/boards/at_start_f407/board.mk7
-rw-r--r--hw/bsp/at32f403a_407/family.c4
-rw-r--r--hw/bsp/at32f413/boards/at_start_f413/board.h2
-rw-r--r--hw/bsp/at32f415/boards/at_start_f415/board.h2
-rw-r--r--hw/bsp/at32f423/boards/at_start_f423/board.h2
-rw-r--r--hw/bsp/at32f425/boards/at_start_f425/board.h2
-rw-r--r--hw/bsp/at32f435_437/boards/at_start_f435/board.cmake8
-rw-r--r--hw/bsp/at32f435_437/boards/at_start_f435/board.h74
-rw-r--r--hw/bsp/at32f435_437/boards/at_start_f435/board.mk7
-rw-r--r--hw/bsp/at32f435_437/boards/at_start_f437/board.h117
-rw-r--r--hw/bsp/at32f435_437/family.c40
-rw-r--r--hw/bsp/at32f435_437/family.cmake7
-rw-r--r--hw/bsp/at32f435_437/family.mk5
27 files changed, 384 insertions, 293 deletions
diff --git a/docs/reference/boards.rst b/docs/reference/boards.rst
index f4f2f6d1f..d984b3529 100644
--- a/docs/reference/boards.rst
+++ b/docs/reference/boards.rst
@@ -30,18 +30,20 @@ max78002evkit MAX78002 EVKIT maxim https://www.analog.com/en/resources/e
Artery
-----
-========================= ==================================== ============= ==================================================== ======
-Board Name Family URL Note
-========================= ==================================== ============= ==================================================== ======
-at_start_f405 AT-START-F405 at32f402_405 https://www.arterychip.com/en/product/AT32F405.jsp
-at_start_f403a AT-START-F403a at32f403a_407 https://www.arterychip.com/en/product/AT32F403.jsp
-at32f403a_weact_blackpill WeAct Studio BlackPill AT32F403ACGU7 at32f403a_407 https://github.com/WeActStudio/WeActStudio.BlackPill
-at_start_f413 AT-START-F413 at32f413 https://www.arterychip.com/en/product/AT32F413.jsp
-at_start_f415 AT-START-F415 at32f415 https://www.arterychip.com/en/product/AT32F415.jsp
-at_start_f423 AT-START-F423 at32f423 https://www.arterychip.com/en/product/AT32F423.jsp
-at_start_f425 AT-START-F425 at32f425 https://www.arterychip.com/en/product/AT32F425.jsp
-at_start_f437 AT-START-F437 at32f435_437 https://www.arterychip.com/en/product/AT32F437.jsp
-========================= ==================================== ============= ==================================================== ======
+============== ============== ============= ================================================== ======
+Board Name Family URL Note
+============== ============== ============= ================================================== ======
+at_start_f402 AT-START-F402 at32f402_405 https://www.arterychip.com/en/product/AT32F402.jsp
+at_start_f405 AT-START-F405 at32f402_405 https://www.arterychip.com/en/product/AT32F405.jsp
+at_start_f403a AT-START-F403a at32f403a_407 https://www.arterychip.com/en/product/AT32F403A.jsp
+at_start_f407 AT-START-F407 at32f403a_407 https://www.arterychip.com/en/product/AT32F407.jsp
+at_start_f413 AT-START-F413 at32f413 https://www.arterychip.com/en/product/AT32F413.jsp
+at_start_f415 AT-START-F415 at32f415 https://www.arterychip.com/en/product/AT32F415.jsp
+at_start_f423 AT-START-F423 at32f423 https://www.arterychip.com/en/product/AT32F423.jsp
+at_start_f425 AT-START-F425 at32f425 https://www.arterychip.com/en/product/AT32F425.jsp
+at_start_f435 AT-START-F435 at32f435_435 https://www.arterychip.com/en/product/AT32F435.jsp
+at_start_f437 AT-START-F437 at32f435_437 https://www.arterychip.com/en/product/AT32F437.jsp
+============== ============== ============= ================================================== ======
Bridgetek
---------
diff --git a/hw/bsp/at32f402_405/boards/at_start_f402/board.cmake b/hw/bsp/at32f402_405/boards/at_start_f402/board.cmake
new file mode 100644
index 000000000..4e7755c0f
--- /dev/null
+++ b/hw/bsp/at32f402_405/boards/at_start_f402/board.cmake
@@ -0,0 +1,8 @@
+set(MCU_VARIANT AT32F402RCT7)
+set(MCU_LINKER_NAME AT32F402xC)
+
+set(JLINK_DEVICE ${MCU_VARIANT})
+
+function(update_board TARGET)
+ target_compile_definitions(${TARGET} PUBLIC ${MCU_VARIANT})
+endfunction()
diff --git a/hw/bsp/at32f402_405/boards/at_start_f402/board.h b/hw/bsp/at32f402_405/boards/at_start_f402/board.h
new file mode 100644
index 000000000..b11b7a80f
--- /dev/null
+++ b/hw/bsp/at32f402_405/boards/at_start_f402/board.h
@@ -0,0 +1,74 @@
+/*
+ * 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-F405
+ url: https://www.arterychip.com/en/product/AT32F405.jsp
+*/
+
+#ifndef BOARD_H_
+#define BOARD_H_
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+#define USB_VBUS_IGNORE
+//#define USB_SOF_OUTPUT_ENABLE
+
+// LED
+#define LED_PORT GPIOF
+#define LED_PIN GPIO_PINS_4
+#define LED_STATE_ON 0 // Active Low
+#define LED_GPIO_CLK_EN() crm_periph_clock_enable(CRM_GPIOF_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)
+
+//USART
+#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
+
+//Vbus
+static inline void board_vbus_sense_init(void)
+{
+ *(int*)(0x50000038) |= (1<<21);
+ *(int*)(0x40040038) |= (1<<21);
+}
+
+#ifdef __cplusplus
+ }
+#endif
+
+#endif /* BOARD_H_ */
diff --git a/hw/bsp/at32f402_405/boards/at_start_f402/board.mk b/hw/bsp/at32f402_405/boards/at_start_f402/board.mk
new file mode 100644
index 000000000..f1082247b
--- /dev/null
+++ b/hw/bsp/at32f402_405/boards/at_start_f402/board.mk
@@ -0,0 +1,7 @@
+MCU_VARIANT = AT32F402RCT7
+MCU_LINKER_NAME = AT32F402xC
+
+JLINK_DEVICE = ${MCU_VARIANT}
+
+CFLAGS += \
+ -D${MCU_VARIANT}
diff --git a/hw/bsp/at32f402_405/boards/at_start_f405/board.cmake b/hw/bsp/at32f402_405/boards/at_start_f405/board.cmake
index 0d09680a1..39c5cd905 100644
--- a/hw/bsp/at32f402_405/boards/at_start_f405/board.cmake
+++ b/hw/bsp/at32f402_405/boards/at_start_f405/board.cmake
@@ -3,6 +3,15 @@ set(MCU_LINKER_NAME AT32F405xC)
set(JLINK_DEVICE ${MCU_VARIANT})
+set(RHPORT_SPEED OPT_MODE_FULL_SPEED OPT_MODE_HIGH_SPEED)
+
+if (NOT DEFINED RHPORT_DEVICE)
+ set(RHPORT_DEVICE 1)
+endif()
+if (NOT DEFINED RHPORT_HOST)
+ set(RHPORT_HOST 0)
+endif()
+
function(update_board TARGET)
target_compile_definitions(${TARGET} PUBLIC ${MCU_VARIANT})
endfunction()
diff --git a/hw/bsp/at32f402_405/boards/at_start_f405/board.h b/hw/bsp/at32f402_405/boards/at_start_f405/board.h
index 2d6cc3e57..b11b7a80f 100644
--- a/hw/bsp/at32f402_405/boards/at_start_f405/board.h
+++ b/hw/bsp/at32f402_405/boards/at_start_f405/board.h
@@ -48,7 +48,7 @@
// Button
#define BUTTON_PORT GPIOA
#define BUTTON_PIN GPIO_PINS_0
-#define BUTTON_STATE_ACTIVE 0
+#define BUTTON_STATE_ACTIVE 1
#define BUTTON_GPIO_CLK_EN() crm_periph_clock_enable(CRM_GPIOA_PERIPH_CLOCK, TRUE)
//USART
@@ -60,111 +60,11 @@
#define PRINT_UART_TX_PIN_SOURCE GPIO_PINS_SOURCE9
#define PRINT_UART_TX_PIN_MUX_NUM GPIO_MUX_7
-//USB
-#ifdef BOARD_TUD_RHPORT
- #if BOARD_TUD_RHPORT == 0
- #define USB_ID USB_OTG1_ID
- #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_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
- #define USB_SPEED_CORE_ID USB_FULL_SPEED_CORE_ID
- #elif BOARD_TUD_RHPORT == 1
- #define USB_ID USB_OTG2_ID
- #define OTG_CLOCK CRM_OTGHS_PERIPH_CLOCK
- #define OTG_IRQ OTGHS_IRQn
- #define OTG_IRQ_HANDLER OTGHS_IRQHandler
- #define OTG_WKUP_IRQ OTGHS_WKUP_IRQn
- #define OTG_WKUP_HANDLER OTGHS_WKUP_IRQHandler
- #define OTG_WKUP_EXINT_LINE EXINT_LINE_20
- #define OTG_PIN_GPIO GPIOB
- #define OTG_PIN_GPIO_CLOCK CRM_GPIOB_PERIPH_CLOCK
- #define OTG_PIN_VBUS GPIO_PINS_13
- #define OTG_PIN_VBUS_SOURCE GPIO_PINS_SOURCE13
- #define OTG_PIN_ID GPIO_PINS_12
- #define OTG_PIN_ID_SOURCE GPIO_PINS_SOURCE12
- #define OTG_PIN_SOF_GPIO GPIOA
- #define OTG_PIN_SOF_GPIO_CLOCK CRM_GPIOA_PERIPH_CLOCK
- #define OTG_PIN_SOF GPIO_PINS_4
- #define OTG_PIN_SOF_SOURCE GPIO_PINS_SOURCE4
- #define OTG_PIN_MUX GPIO_MUX_10
- #define USB_SPEED_CORE_ID USB_HIGH_SPEED_CORE_ID
- #endif
-#endif
-#ifdef BOARD_TUH_RHPORT
- #if BOARD_TUH_RHPORT == 0
- #define USB_ID USB_OTG1_ID
- #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_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
- #define USB_SPEED_CORE_ID USB_FULL_SPEED_CORE_ID
- #elif BOARD_TUH_RHPORT == 1
- #define USB_ID USB_OTG2_ID
- #define OTG_CLOCK CRM_OTGHS_PERIPH_CLOCK
- #define OTG_IRQ OTGHS_IRQn
- #define OTG_IRQ_HANDLER OTGHS_IRQHandler
- #define OTG_WKUP_IRQ OTGHS_WKUP_IRQn
- #define OTG_WKUP_HANDLER OTGHS_WKUP_IRQHandler
- #define OTG_WKUP_EXINT_LINE EXINT_LINE_20
- #define OTG_PIN_GPIO GPIOB
- #define OTG_PIN_GPIO_CLOCK CRM_GPIOB_PERIPH_CLOCK
- #define OTG_PIN_VBUS GPIO_PINS_13
- #define OTG_PIN_VBUS_SOURCE GPIO_PINS_SOURCE13
- #define OTG_PIN_ID GPIO_PINS_12
- #define OTG_PIN_ID_SOURCE GPIO_PINS_SOURCE12
- #define OTG_PIN_SOF_GPIO GPIOA
- #define OTG_PIN_SOF_GPIO_CLOCK CRM_GPIOA_PERIPH_CLOCK
- #define OTG_PIN_SOF GPIO_PINS_4
- #define OTG_PIN_SOF_SOURCE GPIO_PINS_SOURCE4
- #define OTG_PIN_MUX GPIO_MUX_10
- #define USB_SPEED_CORE_ID USB_HIGH_SPEED_CORE_ID
- #endif
-#endif
-
//Vbus
static inline void board_vbus_sense_init(void)
{
- #ifdef BOARD_TUD_RHPORT
- #if BOARD_TUD_RHPORT == 0
- *(int*)(0x50000038) |= (1<<21);
- #elif BOARD_TUD_RHPORT == 1
- *(int*)(0x40040038) |= (1<<21);
- #endif
- #endif
- #ifdef BOARD_TUH_RHPORT
- #if BOARD_TUH_RHPORT == 0
- *(int*)(0x50000038) |= (1<<21);
- #elif BOARD_TUH_RHPORT == 1
- *(int*)(0x40040038) |= (1<<21);
- #endif
- #endif
+ *(int*)(0x50000038) |= (1<<21);
+ *(int*)(0x40040038) |= (1<<21);
}
#ifdef __cplusplus
diff --git a/hw/bsp/at32f402_405/boards/at_start_f405/board.mk b/hw/bsp/at32f402_405/boards/at_start_f405/board.mk
index 25a719ccf..b4d55ca8f 100644
--- a/hw/bsp/at32f402_405/boards/at_start_f405/board.mk
+++ b/hw/bsp/at32f402_405/boards/at_start_f405/board.mk
@@ -3,5 +3,9 @@ MCU_LINKER_NAME = AT32F405xC
JLINK_DEVICE = ${MCU_VARIANT}
+RHPORT_SPEED = OPT_MODE_FULL_SPEED OPT_MODE_HIGH_SPEED
+RHPORT_DEVICE ?= 1
+RHPORT_HOST ?= 0
+
CFLAGS += \
-D${MCU_VARIANT}
diff --git a/hw/bsp/at32f402_405/family.c b/hw/bsp/at32f402_405/family.c
index 7d94f2564..6b69c0157 100644
--- a/hw/bsp/at32f402_405/family.c
+++ b/hw/bsp/at32f402_405/family.c
@@ -66,10 +66,11 @@ void board_init(void)
system_clock_config();
/* config usb io*/
- usb_gpio_config();
+ //usb_gpio_config();
/* enable usb clock */
- crm_periph_clock_enable(OTG_CLOCK, TRUE);
+ crm_periph_clock_enable(CRM_OTGFS1_PERIPH_CLOCK, TRUE);
+ crm_periph_clock_enable(CRM_OTGHS_PERIPH_CLOCK, TRUE);
/* select usb 48m clcok source */
usb_clock48m_select(USB_CLK_HEXT);
@@ -82,9 +83,11 @@ void board_init(void)
#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);
+ NVIC_SetPriority(OTGHS_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY);
+ NVIC_SetPriority(OTGFS1_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY);
#else
- NVIC_SetPriority(OTG_IRQ, 0);
+ NVIC_SetPriority(OTGHS_IRQn, 0);
+ NVIC_SetPriority(OTGFS1_IRQn, 0);
#endif
/* config led and key */
@@ -160,26 +163,7 @@ void usb_clock48m_select(usb_clk48_s clk_s)
void usb_gpio_config(void)
{
- 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_pull = GPIO_PULL_NONE;
- #ifdef USB_SOF_OUTPUT_ENABLE
- crm_periph_clock_enable(OTG_PIN_SOF_GPIO_CLOCK, TRUE);
- gpio_init_struct.gpio_pins = OTG_PIN_SOF;
- gpio_init(OTG_PIN_SOF_GPIO, &gpio_init_struct);
- gpio_pin_mux_config(OTG_PIN_SOF_GPIO, OTG_PIN_SOF_SOURCE, OTG_PIN_MUX);
- #endif
- /* otgfs use vbus pin */
- #ifndef USB_VBUS_IGNORE
- 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
+ /*if needed*/
}
/**
diff --git a/hw/bsp/at32f402_405/family.cmake b/hw/bsp/at32f402_405/family.cmake
index 010e36b88..b10760cef 100644
--- a/hw/bsp/at32f402_405/family.cmake
+++ b/hw/bsp/at32f402_405/family.cmake
@@ -14,6 +14,23 @@ set(CMAKE_TOOLCHAIN_FILE ${TOP}/examples/build_system/cmake/toolchain/arm_${TOOL
set(FAMILY_MCUS ${AT32_FAMILY_UPPER} CACHE INTERNAL "")
+if (NOT DEFINED RHPORT_DEVICE)
+ set(RHPORT_DEVICE 0)
+endif ()
+if (NOT DEFINED RHPORT_HOST)
+ set(RHPORT_HOST 0)
+endif ()
+
+if (NOT DEFINED RHPORT_SPEED)
+ set(RHPORT_SPEED OPT_MODE_FULL_SPEED OPT_MODE_FULL_SPEED)
+endif ()
+if (NOT DEFINED RHPORT_DEVICE_SPEED)
+ list(GET RHPORT_SPEED ${RHPORT_DEVICE} RHPORT_DEVICE_SPEED)
+endif ()
+if (NOT DEFINED RHPORT_HOST_SPEED)
+ list(GET RHPORT_SPEED ${RHPORT_HOST} RHPORT_HOST_SPEED)
+endif ()
+
#------------------------------------
# BOARD_TARGET
#------------------------------------
@@ -50,8 +67,10 @@ function(add_board_target BOARD_TARGET)
${AT32_SDK_LIB}/drivers/inc
)
target_compile_definitions(${BOARD_TARGET} PUBLIC
- BOARD_TUD_RHPORT=0
- BOARD_TUD_MAX_SPEED=OPT_MODE_HIGH_SPEED
+ BOARD_TUD_RHPORT=${RHPORT_DEVICE}
+ BOARD_TUD_MAX_SPEED=${RHPORT_DEVICE_SPEED}
+ BOARD_TUH_RHPORT=${RHPORT_HOST}
+ BOARD_TUH_MAX_SPEED=${RHPORT_HOST_SPEED}
)
update_board(${BOARD_TARGET})
diff --git a/hw/bsp/at32f402_405/family.mk b/hw/bsp/at32f402_405/family.mk
index 60a0f93e9..09b2f1139 100644
--- a/hw/bsp/at32f402_405/family.mk
+++ b/hw/bsp/at32f402_405/family.mk
@@ -8,10 +8,32 @@ CPU_CORE ?= cortex-m4
CFLAGS_GCC += \
-flto
+RHPORT_SPEED ?= OPT_MODE_FULL_SPEED OPT_MODE_FULL_SPEED
+RHPORT_DEVICE ?= 0
+RHPORT_HOST ?= 0
+
+ifndef RHPORT_DEVICE_SPEED
+ifeq ($(RHPORT_DEVICE), 0)
+ RHPORT_DEVICE_SPEED = $(firstword $(RHPORT_SPEED))
+else
+ RHPORT_DEVICE_SPEED = $(lastword $(RHPORT_SPEED))
+endif
+endif
+
+ifndef RHPORT_HOST_SPEED
+ifeq ($(RHPORT_HOST), 0)
+ RHPORT_HOST_SPEED = $(firstword $(RHPORT_SPEED))
+else
+ RHPORT_HOST_SPEED = $(lastword $(RHPORT_SPEED))
+endif
+endif
+
CFLAGS += \
- -DCFG_TUSB_MCU=OPT_MCU_AT32F402_405 \
- -DBOARD_TUD_RHPORT=0 \
- -DBOARD_TUD_MAX_SPEED=OPT_MODE_HIGH_SPEED
+ -DCFG_TUSB_MCU=OPT_MCU_AT32F402_405 \
+ -DBOARD_TUD_RHPORT=${RHPORT_DEVICE} \
+ -DBOARD_TUD_MAX_SPEED=${RHPORT_DEVICE_SPEED} \
+ -DBOARD_TUH_RHPORT=${RHPORT_HOST} \
+ -DBOARD_TUH_MAX_SPEED=${RHPORT_HOST_SPEED} \
LDFLAGS_GCC += \
-flto --specs=nosys.specs -nostdlib -nostartfiles
diff --git a/hw/bsp/at32f403a_407/boards/at_start_f403a/board.cmake b/hw/bsp/at32f403a_407/boards/at_start_f403a/board.cmake
index 25c9558f9..ce26fd244 100644
--- a/hw/bsp/at32f403a_407/boards/at_start_f403a/board.cmake
+++ b/hw/bsp/at32f403a_407/boards/at_start_f403a/board.cmake
@@ -1,4 +1,4 @@
-set(MCU_VARIANT AT32F403ACGU7)
+set(MCU_VARIANT AT32F403AVGT7)
set(MCU_LINKER_NAME AT32F403AxG)
set(JLINK_DEVICE ${MCU_VARIANT})
diff --git a/hw/bsp/at32f403a_407/boards/at_start_f403a/board.mk b/hw/bsp/at32f403a_407/boards/at_start_f403a/board.mk
index 9bb6843aa..d9f360360 100644
--- a/hw/bsp/at32f403a_407/boards/at_start_f403a/board.mk
+++ b/hw/bsp/at32f403a_407/boards/at_start_f403a/board.mk
@@ -1,4 +1,4 @@
-MCU_VARIANT = AT32F403ACGU7
+MCU_VARIANT = AT32F403AVGT7
MCU_LINKER_NAME = AT32F403AxG
JLINK_DEVICE = ${MCU_VARIANT}
diff --git a/hw/bsp/at32f403a_407/boards/at_start_f407/board.cmake b/hw/bsp/at32f403a_407/boards/at_start_f407/board.cmake
new file mode 100644
index 000000000..f76c46f21
--- /dev/null
+++ b/hw/bsp/at32f403a_407/boards/at_start_f407/board.cmake
@@ -0,0 +1,8 @@
+set(MCU_VARIANT AT32F407VGT7)
+set(MCU_LINKER_NAME AT32F407xG)
+
+set(JLINK_DEVICE ${MCU_VARIANT})
+
+function(update_board TARGET)
+ target_compile_definitions(${TARGET} PUBLIC ${MCU_VARIANT})
+endfunction()
diff --git a/hw/bsp/at32f403a_407/boards/at_start_f407/board.h b/hw/bsp/at32f403a_407/boards/at_start_f407/board.h
new file mode 100644
index 000000000..753fece10
--- /dev/null
+++ b/hw/bsp/at32f403a_407/boards/at_start_f407/board.h
@@ -0,0 +1,71 @@
+/*
+ * 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-F403a
+ url: https://www.arterychip.com/en/product/AT32F403.jsp
+*/
+
+#ifndef BOARD_H_
+#define BOARD_H_
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+// 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)
+
+// #define LED_PORT GPIOA
+// #define LED_PIN GPIO_PINS_1
+// #define LED_STATE_ON 0 // Active Low
+// #define LED_GPIO_CLK_EN() crm_periph_clock_enable(CRM_GPIOA_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
+
+static inline void board_vbus_sense_init(void)
+{
+}
+
+#ifdef __cplusplus
+ }
+#endif
+
+#endif /* BOARD_H_ */
diff --git a/hw/bsp/at32f403a_407/boards/at_start_f407/board.mk b/hw/bsp/at32f403a_407/boards/at_start_f407/board.mk
new file mode 100644
index 000000000..714cbaec2
--- /dev/null
+++ b/hw/bsp/at32f403a_407/boards/at_start_f407/board.mk
@@ -0,0 +1,7 @@
+MCU_VARIANT = AT32F407VGT7
+MCU_LINKER_NAME = AT32F407xG
+
+JLINK_DEVICE = ${MCU_VARIANT}
+
+CFLAGS += \
+ -D${MCU_VARIANT}
diff --git a/hw/bsp/at32f403a_407/family.c b/hw/bsp/at32f403a_407/family.c
index afd3a24d1..8c8329323 100644
--- a/hw/bsp/at32f403a_407/family.c
+++ b/hw/bsp/at32f403a_407/family.c
@@ -29,8 +29,8 @@
*/
#include "at32f403a_407_clock.h"
-#include "board.h"
#include "bsp/board_api.h"
+#include "board.h"
void usb_clock48m_select(usb_clk48_s clk_s);
void uart_print_init(uint32_t baudrate);
@@ -102,7 +102,7 @@ void board_init(void) {
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 = BUTTON_PULL;
+ gpio_button_init_struct.gpio_pull = GPIO_PULL_DOWN;
gpio_init(BUTTON_PORT, &gpio_button_init_struct);
uart_print_init(115200);
diff --git a/hw/bsp/at32f413/boards/at_start_f413/board.h b/hw/bsp/at32f413/boards/at_start_f413/board.h
index 4b386a2f4..290400658 100644
--- a/hw/bsp/at32f413/boards/at_start_f413/board.h
+++ b/hw/bsp/at32f413/boards/at_start_f413/board.h
@@ -45,7 +45,7 @@
// Button
#define BUTTON_PORT GPIOA
#define BUTTON_PIN GPIO_PINS_0
-#define BUTTON_STATE_ACTIVE 0
+#define BUTTON_STATE_ACTIVE 1
#define BUTTON_GPIO_CLK_EN() crm_periph_clock_enable(CRM_GPIOA_PERIPH_CLOCK, TRUE)
// UART
diff --git a/hw/bsp/at32f415/boards/at_start_f415/board.h b/hw/bsp/at32f415/boards/at_start_f415/board.h
index 0464d383e..b3c2c1aea 100644
--- a/hw/bsp/at32f415/boards/at_start_f415/board.h
+++ b/hw/bsp/at32f415/boards/at_start_f415/board.h
@@ -47,7 +47,7 @@
// Button
#define BUTTON_PORT GPIOA
#define BUTTON_PIN GPIO_PINS_0
-#define BUTTON_STATE_ACTIVE 0
+#define BUTTON_STATE_ACTIVE 1
#define BUTTON_GPIO_CLK_EN() crm_periph_clock_enable(CRM_GPIOA_PERIPH_CLOCK, TRUE)
// Usart
diff --git a/hw/bsp/at32f423/boards/at_start_f423/board.h b/hw/bsp/at32f423/boards/at_start_f423/board.h
index ef85b4977..24def1ee7 100644
--- a/hw/bsp/at32f423/boards/at_start_f423/board.h
+++ b/hw/bsp/at32f423/boards/at_start_f423/board.h
@@ -47,7 +47,7 @@
// Button
#define BUTTON_PORT GPIOA
#define BUTTON_PIN GPIO_PINS_0
-#define BUTTON_STATE_ACTIVE 0
+#define BUTTON_STATE_ACTIVE 1
#define BUTTON_GPIO_CLK_EN() crm_periph_clock_enable(CRM_GPIOA_PERIPH_CLOCK, TRUE)
// UART
diff --git a/hw/bsp/at32f425/boards/at_start_f425/board.h b/hw/bsp/at32f425/boards/at_start_f425/board.h
index 145eab3b9..2a4d98237 100644
--- a/hw/bsp/at32f425/boards/at_start_f425/board.h
+++ b/hw/bsp/at32f425/boards/at_start_f425/board.h
@@ -47,7 +47,7 @@
// Button
#define BUTTON_PORT GPIOA
#define BUTTON_PIN GPIO_PINS_0
-#define BUTTON_STATE_ACTIVE 0
+#define BUTTON_STATE_ACTIVE 1
#define BUTTON_GPIO_CLK_EN() crm_periph_clock_enable(CRM_GPIOA_PERIPH_CLOCK, TRUE)
// Usart
diff --git a/hw/bsp/at32f435_437/boards/at_start_f435/board.cmake b/hw/bsp/at32f435_437/boards/at_start_f435/board.cmake
new file mode 100644
index 000000000..6d9024f4f
--- /dev/null
+++ b/hw/bsp/at32f435_437/boards/at_start_f435/board.cmake
@@ -0,0 +1,8 @@
+set(MCU_VARIANT AT32F435ZMT7)
+set(MCU_LINKER_NAME AT32F435xM)
+
+set(JLINK_DEVICE ${MCU_VARIANT})
+
+function(update_board TARGET)
+ target_compile_definitions(${TARGET} PUBLIC ${MCU_VARIANT})
+endfunction()
diff --git a/hw/bsp/at32f435_437/boards/at_start_f435/board.h b/hw/bsp/at32f435_437/boards/at_start_f435/board.h
new file mode 100644
index 000000000..3522e759a
--- /dev/null
+++ b/hw/bsp/at32f435_437/boards/at_start_f435/board.h
@@ -0,0 +1,74 @@
+/*
+ * 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-F437
+ url: https://www.arterychip.com/en/product/AT32F437.jsp
+*/
+
+#ifndef BOARD_H_
+#define BOARD_H_
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+//#define USB_VBUS_IGNORE
+//#define USB_SOF_OUTPUT_ENABLE
+
+// 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)
+
+// USART
+#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
+
+// VBUS
+static inline void board_vbus_sense_init(void)
+{
+ *(int*)(0x50000038) |= (1<<21);
+ *(int*)(0x40040038) |= (1<<21);
+}
+
+#ifdef __cplusplus
+ }
+#endif
+
+#endif /* BOARD_H_ */
diff --git a/hw/bsp/at32f435_437/boards/at_start_f435/board.mk b/hw/bsp/at32f435_437/boards/at_start_f435/board.mk
new file mode 100644
index 000000000..5fe56ce77
--- /dev/null
+++ b/hw/bsp/at32f435_437/boards/at_start_f435/board.mk
@@ -0,0 +1,7 @@
+MCU_VARIANT = AT32F435ZMT7
+MCU_LINKER_NAME = AT32F435xM
+
+JLINK_DEVICE = ${MCU_VARIANT}
+
+CFLAGS += \
+ -D${MCU_VARIANT}
diff --git a/hw/bsp/at32f435_437/boards/at_start_f437/board.h b/hw/bsp/at32f435_437/boards/at_start_f437/board.h
index b6de119bc..3522e759a 100644
--- a/hw/bsp/at32f435_437/boards/at_start_f437/board.h
+++ b/hw/bsp/at32f435_437/boards/at_start_f437/board.h
@@ -60,124 +60,11 @@
#define PRINT_UART_TX_PIN_SOURCE GPIO_PINS_SOURCE9
#define PRINT_UART_TX_PIN_MUX_NUM GPIO_MUX_7
-// USB
-#ifdef BOARD_TUD_RHPORT
- #if BOARD_TUD_RHPORT == 0
- #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_SOURCE12
- #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
- #elif BOARD_TUD_RHPORT == 1
- #define USB_ID 1
- #define OTG_CLOCK CRM_OTGFS2_PERIPH_CLOCK
- #define OTG_IRQ OTGFS2_IRQn
- #define OTG_IRQ_HANDLER OTGFS2_IRQHandler
- #define OTG_WKUP_IRQ OTGFS2_WKUP_IRQn
- #define OTG_WKUP_HANDLER OTGFS2_WKUP_IRQHandler
- #define OTG_WKUP_EXINT_LINE EXINT_LINE_20
- #define OTG_PIN_GPIO GPIOB
- #define OTG_PIN_GPIO_CLOCK CRM_GPIOB_PERIPH_CLOCK
- #define OTG_PIN_DP GPIO_PINS_15
- #define OTG_PIN_DP_SOURCE GPIO_PINS_SOURCE15
- #define OTG_PIN_DM GPIO_PINS_14
- #define OTG_PIN_DM_SOURCE GPIO_PINS_SOURCE14
- #define OTG_PIN_VBUS GPIO_PINS_13
- #define OTG_PIN_VBUS_SOURCE GPIO_PINS_SOURCE13
- #define OTG_PIN_ID GPIO_PINS_12
- #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_4
- #define OTG_PIN_SOF_SOURCE GPIO_PINS_SOURCE4
- #define OTG_PIN_MUX GPIO_MUX_12
- #endif
-#endif
-
-#ifdef BOARD_TUH_RHPORT
- #if BOARD_TUH_RHPORT == 0
- #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_SOURCE12
- #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
- #elif BOARD_TUH_RHPORT == 1
- #define USB_ID 1
- #define OTG_CLOCK CRM_OTGFS2_PERIPH_CLOCK
- #define OTG_IRQ OTGFS2_IRQn
- #define OTG_IRQ_HANDLER OTGFS2_IRQHandler
- #define OTG_WKUP_IRQ OTGFS2_WKUP_IRQn
- #define OTG_WKUP_HANDLER OTGFS2_WKUP_IRQHandler
- #define OTG_WKUP_EXINT_LINE EXINT_LINE_20
- #define OTG_PIN_GPIO GPIOB
- #define OTG_PIN_GPIO_CLOCK CRM_GPIOB_PERIPH_CLOCK
- #define OTG_PIN_DP GPIO_PINS_15
- #define OTG_PIN_DP_SOURCE GPIO_PINS_SOURCE15
- #define OTG_PIN_DM GPIO_PINS_14
- #define OTG_PIN_DM_SOURCE GPIO_PINS_SOURCE14
- #define OTG_PIN_VBUS GPIO_PINS_13
- #define OTG_PIN_VBUS_SOURCE GPIO_PINS_SOURCE13
- #define OTG_PIN_ID GPIO_PINS_12
- #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_4
- #define OTG_PIN_SOF_SOURCE GPIO_PINS_SOURCE4
- #define OTG_PIN_MUX GPIO_MUX_12
- #endif
-#endif
-
// VBUS
static inline void board_vbus_sense_init(void)
{
- #ifdef BOARD_TUD_RHPORT
- #if BOARD_TUD_RHPORT == 0
- *(int*)(0x50000038) |= (1<<21);
- #elif BOARD_TUD_RHPORT == 1
- *(int*)(0x40040038) |= (1<<21);
- #endif
- #endif
- #ifdef BOARD_TUH_RHPORT
- #if BOARD_TUH_RHPORT == 0
- *(int*)(0x50000038) |= (1<<21);
- #elif BOARD_TUH_RHPORT == 1
- *(int*)(0x40040038) |= (1<<21);
- #endif
- #endif
+ *(int*)(0x50000038) |= (1<<21);
+ *(int*)(0x40040038) |= (1<<21);
}
#ifdef __cplusplus
diff --git a/hw/bsp/at32f435_437/family.c b/hw/bsp/at32f435_437/family.c
index 702fdd2a8..a65116729 100644
--- a/hw/bsp/at32f435_437/family.c
+++ b/hw/bsp/at32f435_437/family.c
@@ -64,21 +64,23 @@ void board_init(void) {
usb_gpio_config();
/* enable usb clock */
- crm_periph_clock_enable(OTG_CLOCK, TRUE);
+ crm_periph_clock_enable(CRM_OTGFS1_PERIPH_CLOCK, TRUE);
+ crm_periph_clock_enable(CRM_OTGFS2_PERIPH_CLOCK, TRUE);
/* select usb 48m clcok source */
usb_clock48m_select(USB_CLK_HEXT);
- /* enable otgfs irq */
- //nvic_irq_enable(OTG_IRQ, 0, 0);
-
/* vbus ignore */
board_vbus_sense_init();
SysTick_Config(SystemCoreClock / 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);
+ NVIC_SetPriority(OTGFS1_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY);
+ NVIC_SetPriority(OTGFS2_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY);
+#else
+ NVIC_SetPriority(OTGFS1_IRQn, 0);
+ NVIC_SetPriority(OTGFS2_IRQn, 0);
#endif
/* config led and key */
@@ -271,30 +273,22 @@ int inHandlerMode(void) {
void usb_gpio_config(void) {
gpio_init_type gpio_init_struct;
- crm_periph_clock_enable(OTG_PIN_GPIO_CLOCK, TRUE);
+ crm_periph_clock_enable(CRM_GPIOA_PERIPH_CLOCK, TRUE);
+ crm_periph_clock_enable(CRM_GPIOB_PERIPH_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_pull = GPIO_PULL_NONE;
/* dp and dm */
- gpio_init_struct.gpio_pins = OTG_PIN_DP | OTG_PIN_DM;
- gpio_init(OTG_PIN_GPIO, &gpio_init_struct);
- gpio_pin_mux_config(OTG_PIN_GPIO, OTG_PIN_DP_SOURCE, OTG_PIN_MUX);
- gpio_pin_mux_config(OTG_PIN_GPIO, OTG_PIN_DM_SOURCE, OTG_PIN_MUX);
-#ifdef USB_SOF_OUTPUT_ENABLE
- crm_periph_clock_enable(OTG_PIN_SOF_GPIO_CLOCK, TRUE);
- gpio_init_struct.gpio_pins = OTG_PIN_SOF;
- gpio_init(OTG_PIN_SOF_GPIO, &gpio_init_struct);
- gpio_pin_mux_config(OTG_PIN_SOF_GPIO, OTG_PIN_SOF_SOURCE, OTG_PIN_MUX);
-#endif
- /* otgfs use vbus pin */
-#ifndef USB_VBUS_IGNORE
- 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
+ gpio_init_struct.gpio_pins = GPIO_PINS_11 | GPIO_PINS_12;
+ gpio_init(GPIOA, &gpio_init_struct);
+ gpio_init_struct.gpio_pins = GPIO_PINS_14 | GPIO_PINS_15;
+ gpio_init(GPIOB, &gpio_init_struct);
+ gpio_pin_mux_config(GPIOA, GPIO_PINS_SOURCE11, GPIO_MUX_10);
+ gpio_pin_mux_config(GPIOA, GPIO_PINS_SOURCE12, GPIO_MUX_10);
+ gpio_pin_mux_config(GPIOB, GPIO_PINS_SOURCE14, GPIO_MUX_12);
+ gpio_pin_mux_config(GPIOB, GPIO_PINS_SOURCE15, GPIO_MUX_12);
}
void board_led_write(bool state) {
diff --git a/hw/bsp/at32f435_437/family.cmake b/hw/bsp/at32f435_437/family.cmake
index c85b58ae4..7bb38eb2f 100644
--- a/hw/bsp/at32f435_437/family.cmake
+++ b/hw/bsp/at32f435_437/family.cmake
@@ -51,9 +51,12 @@ function(add_board_target BOARD_TARGET)
${AT32_SDK_LIB}/drivers/inc
)
target_compile_definitions(${BOARD_TARGET} PUBLIC
- BOARD_TUD_RHPORT=0
+ BOARD_TUD_RHPORT=1
+ BOARD_TUH_RHPORT=0
+ BOARD_TUD_MAX_SPEED=OPT_MODE_FULL_SPEED
+ BOARD_TUH_MAX_SPEED=OPT_MODE_FULL_SPEED
)
-
+
update_board(${BOARD_TARGET})
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
diff --git a/hw/bsp/at32f435_437/family.mk b/hw/bsp/at32f435_437/family.mk
index b33be1180..ba22f5420 100644
--- a/hw/bsp/at32f435_437/family.mk
+++ b/hw/bsp/at32f435_437/family.mk
@@ -10,7 +10,10 @@ CFLAGS_GCC += \
CFLAGS += \
-DCFG_TUSB_MCU=OPT_MCU_AT32F435_437 \
- -DBOARD_TUD_RHPORT=0
+ -DBOARD_TUD_RHPORT=1 \
+ -DBOARD_TUH_RHPORT=0 \
+ -DBOARD_TUD_MAX_SPEED=OPT_MODE_FULL_SPEED \
+ -DBOARD_TUH_MAX_SPEED=OPT_MODE_FULL_SPEED \
LDFLAGS_GCC += \
-flto --specs=nosys.specs -nostdlib -nostartfiles