Skip to content

Commit

Permalink
update cherryusb and ports
Browse files Browse the repository at this point in the history
update wch series
update st series
update arterytek series

Update README.md
  • Loading branch information
zhaqian12 committed Apr 2, 2024
1 parent c68e82f commit beb80be
Show file tree
Hide file tree
Showing 130 changed files with 2,702 additions and 2,384 deletions.
8 changes: 4 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[submodule "lib/CherryUSB"]
path = lib/CherryUSB
url = https://github.com/zhaqian12/CherryUSB
[submodule "lib/uf2"]
path = lib/uf2
url = https://github.com/microsoft/uf2.git
Expand Down Expand Up @@ -60,4 +57,7 @@
url = https://github.com/ArteryTek/AT32F402_405_Firmware_Library.git
[submodule "sdk/ArteryTek/at32wb415_library"]
path = sdk/ArteryTek/at32wb415_library
url = https://github.com/ArteryTek/AT32WB415_Firmware_Library.git
url = https://github.com/ArteryTek/AT32WB415_Firmware_Library.git
[submodule "lib/CherryUSB"]
path = lib/CherryUSB
url = https://github.com/cherry-embedded/CherryUSB.git
52 changes: 27 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,31 @@ It only supports DFU with MSC.
```

# Support Devices
| Manufacturer | MCU | Note |
| :----------- | :-------- | :--------------------------------------------------------------------------------------------- |
| ArteryTek | AT32F402 | |
| ArteryTek | AT32F403A | |
| ArteryTek | AT32F405 | If you use hs embedded phy, change the init value of the GCCFG register in the CherryUSB port. |
| ArteryTek | AT32F407 | |
| ArteryTek | AT32F413 | |
| ArteryTek | AT32F415 | |
| ArteryTek | AT32F423 | |
| ArteryTek | AT32F425 | |
| ArteryTek | AT32F435 | |
| ArteryTek | AT32F437 | |
| ArteryTek | AT32WB415 | |
| ST | STM32F072 | Need to redirect vectors in app or bootloader. |
| ST | STM32F103 | |
| ST | STM32F401 | |
| ST | STM32F407 | |
| ST | STM32F411 | |
| ST | STM32G431 | |
| ST | STM32L433 | |
| WCH | CH32V307 | |
| WCH | CH582M | |
| HDSC | HC32F460 | Some problems with usb.And need to config icg if you want to use it in app. |
| Manufacturer | MCU | Note |
| :----------- | :-------- | :-------------------------------------------------------------------------- |
| ArteryTek | AT32F402 | |
| ArteryTek | AT32F403A | |
| ArteryTek | AT32F405 | |
| ArteryTek | AT32F407 | |
| ArteryTek | AT32F413 | |
| ArteryTek | AT32F415 | |
| ArteryTek | AT32F423 | |
| ArteryTek | AT32F425 | |
| ArteryTek | AT32F435 | |
| ArteryTek | AT32F437 | |
| ArteryTek | AT32WB415 | |
| ST | STM32F072 | Need to redirect vectors in app or bootloader. |
| ST | STM32F103 | |
| ST | STM32F401 | |
| ST | STM32F407 | |
| ST | STM32F411 | |
| ST | STM32G431 | |
| ST | STM32L433 | |
| WCH | CH32V307 | |
| WCH | CH582M | |
| HDSC | HC32F460 | Some problems with usb.And need to config icg if you want to use it in app. |

## Todo List
- [x] AT32WB415
- [ ] AT32F435/7(Multiport)
- [ ] HPM5300
- [ ] CH32V307 -> CH32V20X_30X
Expand All @@ -65,4 +64,7 @@ $ make BOARD=at32f413cbt7 all
```
$ cd ports/ArteryTek/at32f413
$ make BOARD=at32f413cbt7 clean
```
```

# Changelog
- 2024.4 Update to the latest CherryUSB v1.2.0.
2 changes: 1 addition & 1 deletion lib/CherryUSB
Submodule CherryUSB updated 231 files
2 changes: 1 addition & 1 deletion lib/uf2
Submodule uf2 updated 1 files
+10 −0 utils/uf2families.json
3 changes: 0 additions & 3 deletions ports/ArteryTek/at32f402_405/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,3 @@ PORTS ?= ArteryTek
include ../../make.mk
include port.mk
include ../../rules.mk

self-update:
@echo "not implemented yet"
9 changes: 1 addition & 8 deletions ports/ArteryTek/at32f402_405/board_flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static bool flash_erase(uint32_t addr) {
if (sector_addr + size > addr) {
sector = i;
erased = erased_sectors[i];
erased_sectors[i] = 1; // don't erase anymore - we will continue writing here!
erased_sectors[i] = 1;
break;
}
sector_addr += size;
Expand Down Expand Up @@ -104,10 +104,3 @@ __attribute__((weak)) void board_flash_write(uint32_t addr, void const *data, ui
}

__attribute__((weak)) void board_flash_erase_app(void) {}

#ifdef CHERRYUF2_SELF_UPDATE
__attribute__((weak)) void board_self_update(const uint8_t *bootloader_bin, uint32_t bootloader_len) {
(void)bootloader_bin;
(void)bootloader_len;
}
#endif
76 changes: 76 additions & 0 deletions ports/ArteryTek/at32f402_405/board_usb.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2024 Zhaqian
*
* 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.
*/

#include "board_api.h"

//--------------------------------------------------------------------+
// CherryUSB LLD
//--------------------------------------------------------------------+
extern const uint8_t msc_descriptor[];

static struct usbd_interface intf0;

void board_msc_init(void) {
usbd_desc_register(0, msc_descriptor);
usbd_add_interface(0, usbd_msc_init_intf(0, &intf0, MSC_OUT_EP, MSC_IN_EP));

#ifdef CONFIG_USB_HS
usbd_initialize(0, OTGHS_BASE, usbd_event_handler);
#else
usbd_initialize(0, OTGFS1_BASE, usbd_event_handler);
#endif
}

__attribute__((weak)) void usb_dc_low_level_init(void) {
#ifdef CONFIG_USB_HS
crm_periph_clock_enable(CRM_OTGHS_PERIPH_CLOCK, TRUE);
nvic_irq_enable(OTGHS_IRQn, 0, 0);
#else
crm_pllu_output_set(TRUE);
while (crm_flag_get(CRM_PLLU_STABLE_FLAG) != SET) {
}
crm_usb_clock_source_select(CRM_USB_CLOCK_SOURCE_PLLU);
crm_periph_clock_enable(CRM_OTGFS1_PERIPH_CLOCK, TRUE);
nvic_irq_enable(OTGFS1_IRQn, 0, 0);
#endif
}

//--------------------------------------------------------------------+
// IRQ Handler
//--------------------------------------------------------------------+
#ifdef CONFIG_USB_HS
void OTGHS_IRQHandler(void) {
extern void USBD_IRQHandler(uint8_t busid);
USBD_IRQHandler(0);
}
#else
void OTGFS1_IRQHandler(void) {
extern void USBD_IRQHandler(uint8_t busid);
USBD_IRQHandler(0);
}
#endif




55 changes: 8 additions & 47 deletions ports/ArteryTek/at32f402_405/boards.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,17 @@

#include "board_api.h"

//--------------------------------------------------------------------+
// CherryUSB LLD
//--------------------------------------------------------------------+
__attribute__((weak)) void usb_dc_low_level_init(void) {
#ifdef CONFIG_USB_HS
crm_periph_clock_enable(CRM_OTGHS_PERIPH_CLOCK, TRUE);
nvic_irq_enable(OTGHS_IRQn, 0, 0);
#else
crm_pllu_output_set(TRUE);
while (crm_flag_get(CRM_PLLU_STABLE_FLAG) != SET) {
}
crm_usb_clock_source_select(CRM_USB_CLOCK_SOURCE_PLLU);
crm_periph_clock_enable(CRM_OTGFS1_PERIPH_CLOCK, TRUE);
nvic_irq_enable(OTGFS1_IRQn, 0, 0);
#endif
}

//--------------------------------------------------------------------+
// Boards api
//--------------------------------------------------------------------+
__attribute__((weak)) void board_init(void) {
nvic_priority_group_config(NVIC_PRIORITY_GROUP_4);

clock_init();
system_core_clock_update();

board_timer_stop();
}

__attribute__((weak)) void board_dfu_init(void) {
crm_periph_clock_enable(CRM_GPIOA_PERIPH_CLOCK, TRUE);
crm_periph_clock_enable(CRM_GPIOB_PERIPH_CLOCK, TRUE);
crm_periph_clock_enable(CRM_GPIOC_PERIPH_CLOCK, TRUE);
Expand All @@ -77,9 +60,6 @@ __attribute__((weak)) void board_dfu_complete(void) {
NVIC_SystemReset();
}

__attribute__((weak)) void board_usb_process(void) {
}

__attribute__((weak)) bool board_app_valid(void) {
volatile uint32_t const *app_vector = (volatile uint32_t const *)BOARD_FLASH_APP_START;

Expand All @@ -92,37 +72,24 @@ __attribute__((weak)) bool board_app_valid(void) {
}

__attribute__((weak)) void board_app_jump(void) {
#ifdef LED_PIN
gpio_reset(LED_PORT);
#endif
crm_periph_clock_enable(CRM_GPIOA_PERIPH_CLOCK, FALSE);
crm_periph_clock_enable(CRM_GPIOB_PERIPH_CLOCK, FALSE);
crm_periph_clock_enable(CRM_GPIOC_PERIPH_CLOCK, FALSE);
crm_periph_clock_enable(CRM_GPIOD_PERIPH_CLOCK, FALSE);
crm_periph_clock_enable(CRM_GPIOF_PERIPH_CLOCK, FALSE);
#ifdef CONFIG_USB_HS
crm_periph_clock_enable(CRM_OTGHS_PERIPH_CLOCK, FALSE);
#else
crm_periph_clock_enable(CRM_OTGFS1_PERIPH_CLOCK, FALSE);
#endif
crm_reset();

SysTick->CTRL = 0;
SysTick->LOAD = 0;
SysTick->VAL = 0;

// Disable all Interrupts
NVIC->ICER[0] = 0xFFFFFFFF;
NVIC->ICER[1] = 0xFFFFFFFF;
NVIC->ICER[2] = 0xFFFFFFFF;
NVIC->ICER[3] = 0xFFFFFFFF;
for (int i = 0; i < BOARD_ARRAY_SIZE(NVIC->ICER); i++) {
NVIC->ICER[i] = 0xFFFFFFFF;
NVIC->ICPR[i] = 0xFFFFFFFF;
}

volatile uint32_t const *app_vector = (volatile uint32_t const *)BOARD_FLASH_APP_START;

/* switch exception handlers to the application */
SCB->VTOR = (uint32_t)BOARD_FLASH_APP_START;

// Set stack pointer
__set_CONTROL(0);
__set_MSP(app_vector[0]);
asm("bx %0" ::"r"(app_vector[1]));
}
Expand All @@ -141,7 +108,7 @@ void board_led_write(uint32_t state) {
// Timer
//--------------------------------------------------------------------+
void board_timer_start(uint32_t ms) {
SysTick_Config((SystemCoreClock / 1000) * ms);
SysTick_Config((system_core_clock / 1000) * ms);
}

void board_timer_stop(void) {
Expand All @@ -152,10 +119,4 @@ void SysTick_Handler(void) {
board_timer_handler();
}

int board_uart_write(void const *buf, int len) {
(void)buf;
(void)len;
return 0;
}

void _init(void) {}
15 changes: 0 additions & 15 deletions ports/ArteryTek/at32f402_405/boards/at32f405ccu7/board.mk

This file was deleted.

9 changes: 9 additions & 0 deletions ports/ArteryTek/at32f402_405/boards/at32f405ccu7_fs/board.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CFLAGS += \
-DAT32F405CCU7 \
-DHEXT_VALUE=12000000U \
-DSystemCoreClock=system_core_clock

SRC_S += \
$(AT_CMSIS)/cm4/device_support/startup/gcc/startup_at32f402_405.s

USB_XFER_SPEED = FS
Loading

0 comments on commit beb80be

Please sign in to comment.