Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ Supported CPUs
| +-----------------------------+--------+------+-----------+------------------------+--------------------+
| | S31 | ✔ | ✔ | ✔ | dwc2 | |
+--------------+-----------------------------+--------+------+-----------+------------------------+--------------------+
| Geehy APM32 | F072 | ✔ | | ✖ | fsdev | 1KB USB RAM |
+--------------+-----------------------------+--------+------+-----------+------------------------+--------------------+
| GigaDevice | GD32VF103 | ✔ | | ✖ | dwc2 | |
+--------------+-----------------------------+--------+------+-----------+------------------------+--------------------+
| HPMicro | HPM6750 | ✔ | ✔ | ✔ | ci_hs, ehci | |
Expand Down
9 changes: 9 additions & 0 deletions docs/reference/boards.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ espressif_s3_devkitm Espresif S3 DevKitM espressif https://do
espressif_saola_1 Espresif S2 Saola 1 espressif https://docs.espressif.com/projects/esp-dev-kits/en/latest/esp32s2/esp32-s2-saola-1/index.html
========================= ============================== ========= ======================================================================================================== ======

Geehy
-----

==================== ==================== ========= ============================================== ======
Board Name Family URL Note
==================== ==================== ========= ============================================== ======
apm32f072_dev_board APM32F072 Dev Board apm32f0xx
==================== ==================== ========= ============================================== ======

GigaDevice
----------

Expand Down
8 changes: 8 additions & 0 deletions hw/bsp/apm32f0xx/boards/apm32f072_dev_board/board.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
set(MCU_VARIANT APM32F072xB)
set(MCU_LINKER_NAME APM32F07xxB)

set(JLINK_DEVICE APM32F072RB)

function(update_board TARGET)
target_compile_definitions(${TARGET} PUBLIC ${MCU_VARIANT})
endfunction()
49 changes: 49 additions & 0 deletions hw/bsp/apm32f0xx/boards/apm32f072_dev_board/board.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2024, 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: APM32F072 Dev Board
url: https://www.geehy.com
*/

#ifndef BOARD_H_
#define BOARD_H_

#ifdef __cplusplus
extern "C" {
#endif

// LED
#define LED_PORT GPIOC
#define LED_PIN GPIO_PIN_13
#define LED_STATE_ON 0
#define LED_GPIO_CLK_EN() RCM_EnableAHBPeriphClock(RCM_AHB_PERIPH_GPIOC)

#ifdef __cplusplus
}
#endif

#endif /* BOARD_H_ */
7 changes: 7 additions & 0 deletions hw/bsp/apm32f0xx/boards/apm32f072_dev_board/board.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
MCU_VARIANT = APM32F072xB
MCU_LINKER_NAME = APM32F07xxB

JLINK_DEVICE = APM32F072RB

CFLAGS += \
-D${MCU_VARIANT}
145 changes: 145 additions & 0 deletions hw/bsp/apm32f0xx/family.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/*
* 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: Geehy
*/

#include "apm32f0xx.h"
#include "apm32f0xx_rcm.h"
#include "apm32f0xx_gpio.h"
#include "apm32f0xx_misc.h"
#include "apm32f0xx_crs.h"
#include "bsp/board_api.h"
#include "board.h"

//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
void USBD_IRQHandler(void) {
tud_int_handler(0);
}

//--------------------------------------------------------------------+
// Board Init
//--------------------------------------------------------------------+
void board_init(void) {
// Enable HSI48 for USB clock
RCM_EnableHSI48();
while (RCM_ReadStatusFlag(RCM_FLAG_HSI48RDY) == RESET) {}

// Select HSI48 as USB clock source
RCM_ConfigUSBCLK(RCM_USBCLK_HSI48);

// Enable CRS for automatic HSI48 calibration from USB SOF
RCM_EnableAPB1PeriphClock(RCM_APB1_PERIPH_CRS);
CRS_ConfigSynchronizationSource(CRS_SYNC_SOURCE_USB);
CRS_EnableAutomaticCalibration();
CRS_EnableFrequencyErrorCounter();

// Enable USB peripheral clock
RCM_EnableAPB1PeriphClock(RCM_APB1_PERIPH_USB);

// SysTick 1ms tick
SysTick_Config(SystemCoreClock / 1000);

// LED
LED_GPIO_CLK_EN();
GPIO_Config_T gpio_config;
GPIO_ConfigStructInit(&gpio_config);
gpio_config.pin = LED_PIN;
gpio_config.mode = GPIO_MODE_OUT;
gpio_config.outtype = GPIO_OUT_TYPE_PP;
gpio_config.speed = GPIO_SPEED_50MHz;
GPIO_Config(LED_PORT, &gpio_config);

board_led_write(false);
}

//--------------------------------------------------------------------+
// Board porting API
//--------------------------------------------------------------------+
void board_led_write(bool state) {
if (state ^ (!LED_STATE_ON)) {
GPIO_SetBit(LED_PORT, LED_PIN);
} else {
GPIO_ClearBit(LED_PORT, LED_PIN);
}
}

uint32_t board_button_read(void) {
return 0;
}

size_t board_get_unique_id(uint8_t id[], size_t max_len) {
(void) max_len;
volatile uint32_t *apm32_uuid = ((volatile uint32_t *) 0x1FFFF7AC);
uint32_t *id32 = (uint32_t *) (uintptr_t) id;
uint8_t const len = 12;

id32[0] = apm32_uuid[0];
id32[1] = apm32_uuid[1];
id32[2] = apm32_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) {
(void) buf;
(void) len;
return 0;
}

#if CFG_TUSB_OS == OPT_OS_NONE
volatile uint32_t system_ticks = 0;

void SysTick_Handler(void) {
system_ticks++;
}

uint32_t tusb_time_millis_api(void) {
return system_ticks;
}

void SVC_Handler(void) {
}

void PendSV_Handler(void) {
}
#endif

void HardFault_Handler(void) {
__asm("BKPT #0\n");
}

void _init(void) {
}
84 changes: 84 additions & 0 deletions hw/bsp/apm32f0xx/family.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
include_guard()

set(APM32_FAMILY apm32f0xx)
set(APM32_SDK ${TOP}/hw/mcu/geehy/APM32F0xx_SDK_V1.8.6/Libraries)

# include board specific
include(${CMAKE_CURRENT_LIST_DIR}/boards/${BOARD}/board.cmake)

# toolchain set up
set(CMAKE_SYSTEM_CPU cortex-m0plus CACHE INTERNAL "System Processor")
set(CMAKE_TOOLCHAIN_FILE ${TOP}/examples/build_system/cmake/toolchain/arm_${TOOLCHAIN}.cmake)

set(FAMILY_MCUS APM32F0XX CACHE INTERNAL "")

#------------------------------------
# Startup & Linker script
#------------------------------------
set(STARTUP_FILE_GNU ${APM32_SDK}/Device/Geehy/APM32F0xx/Source/gcc/startup_apm32f072.S)
set(STARTUP_FILE_Clang ${STARTUP_FILE_GNU})
if (NOT DEFINED LD_FILE_GNU)
set(LD_FILE_GNU ${APM32_SDK}/Device/Geehy/APM32F0xx/Source/gcc/gcc_${MCU_LINKER_NAME}.ld)
endif ()
set(LD_FILE_Clang ${LD_FILE_GNU})

#------------------------------------
# BOARD_TARGET
#------------------------------------
function(family_add_board BOARD_TARGET)
add_library(${BOARD_TARGET} STATIC
${APM32_SDK}/Device/Geehy/APM32F0xx/Source/system_apm32f0xx.c
${APM32_SDK}/APM32F0xx_StdPeriphDriver/src/apm32f0xx_gpio.c
${APM32_SDK}/APM32F0xx_StdPeriphDriver/src/apm32f0xx_misc.c
${APM32_SDK}/APM32F0xx_StdPeriphDriver/src/apm32f0xx_rcm.c
${APM32_SDK}/APM32F0xx_StdPeriphDriver/src/apm32f0xx_crs.c
)
target_include_directories(${BOARD_TARGET} PUBLIC
${CMAKE_CURRENT_FUNCTION_LIST_DIR}
${APM32_SDK}/CMSIS/Include
${APM32_SDK}/Device/Geehy/APM32F0xx/Include
${APM32_SDK}/APM32F0xx_StdPeriphDriver/inc
)

update_board(${BOARD_TARGET})
endfunction()

#------------------------------------
# Functions
#------------------------------------
function(family_configure_example TARGET RTOS)
family_configure_common(${TARGET} ${RTOS})
family_add_tinyusb(${TARGET} OPT_MCU_APM32F0XX)

target_sources(${TARGET} PUBLIC
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/family.c
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../board.c
${TOP}/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c
${TOP}/src/portable/st/stm32_fsdev/fsdev_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}"
)
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()
39 changes: 39 additions & 0 deletions hw/bsp/apm32f0xx/family.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
APM32_FAMILY = apm32f0xx
APM32_SDK = hw/mcu/geehy/APM32F0xx_SDK_V1.8.6/Libraries

include $(TOP)/$(BOARD_PATH)/board.mk

CPU_CORE ?= cortex-m0plus

CFLAGS += \
-flto

CFLAGS += \
-DCFG_TUSB_MCU=OPT_MCU_APM32F0XX

LDFLAGS += \
-flto --specs=nosys.specs -nostdlib -nostartfiles

SRC_C += \
src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c \
src/portable/st/stm32_fsdev/fsdev_common.c \
$(APM32_SDK)/APM32F0xx_StdPeriphDriver/src/apm32f0xx_gpio.c \
$(APM32_SDK)/APM32F0xx_StdPeriphDriver/src/apm32f0xx_misc.c \
$(APM32_SDK)/APM32F0xx_StdPeriphDriver/src/apm32f0xx_rcm.c \
$(APM32_SDK)/APM32F0xx_StdPeriphDriver/src/apm32f0xx_crs.c \
$(APM32_SDK)/Device/Geehy/APM32F0xx/Source/system_apm32f0xx.c

INC += \
$(TOP)/$(BOARD_PATH) \
$(TOP)/$(APM32_SDK)/APM32F0xx_StdPeriphDriver/inc \
$(TOP)/$(APM32_SDK)/CMSIS/Include \
$(TOP)/$(APM32_SDK)/Device/Geehy/APM32F0xx/Include

SRC_S += $(APM32_SDK)/Device/Geehy/APM32F0xx/Source/gcc/startup_apm32f072.S

LD_FILE ?= $(APM32_SDK)/Device/Geehy/APM32F0xx/Source/gcc/gcc_${MCU_LINKER_NAME}.ld

# For freeRTOS port source
FREERTOS_PORTABLE_SRC = $(FREERTOS_PORTABLE_PATH)/ARM_CM0

flash: flash-jlink
8 changes: 8 additions & 0 deletions src/common/tusb_mcu.h
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,14 @@

#define TU_ATTR_FAST_FUNC __attribute__((section(".fast")))

//--------------------------------------------------------------------+
// Geehy
//--------------------------------------------------------------------+
#elif TU_CHECK_MCU(OPT_MCU_APM32F0XX)
#define TUP_USBIP_FSDEV
#define TUP_USBIP_FSDEV_APM32
#define CFG_TUSB_FSDEV_PMA_SIZE 1024u

#endif

// External USB controller
Expand Down
Loading
Loading