Skip to content

Commit

Permalink
Merge pull request #2278 from Krasutski/feature/ch32f20x
Browse files Browse the repository at this point in the history
Add CH32F20x support
  • Loading branch information
hathach authored Nov 24, 2023
2 parents d6b8b35 + b6059fa commit f03f60e
Show file tree
Hide file tree
Showing 26 changed files with 2,262 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ hw/mcu/st/stm32u5xx_hal_driver
hw/mcu/st/stm32wbxx_hal_driver
hw/mcu/ti
hw/mcu/wch/ch32v307
hw/mcu/wch/ch32f20x
lib/CMSIS_5
lib/FreeRTOS-Kernel
lib/lwip
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ Following CPUs are supported, check out `Supported Devices`_ for comprehensive l
+--------------+------------------------------------------------------------+
| ValentyUSB | eptri |
+--------------+------------------------------------------------------------+
| WCH | CH32V307 |
| WCH | CH32F20x, CH32V307, |
+--------------+------------------------------------------------------------+

Docs
Expand Down
1 change: 1 addition & 0 deletions docs/reference/dependencies.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ hw/mcu/st/stm32u5xx_hal_driver https://github.com/STMicroelectronics/
hw/mcu/st/stm32wbxx_hal_driver https://github.com/STMicroelectronics/stm32wbxx_hal_driver.git 2c5f06638be516c1b772f768456ba637f077bac8
hw/mcu/ti https://github.com/hathach/ti_driver.git 143ed6cc20a7615d042b03b21e070197d473e6e5
hw/mcu/wch/ch32v307 https://github.com/openwch/ch32v307.git 17761f5cf9dbbf2dcf665b7c04934188add20082
hw/mcu/wch/ch32f20x https://github.com/openwch/ch32f20x.git 77c4095087e5ed2c548ec9058e655d0b8757663b
lib/CMSIS_5 https://github.com/ARM-software/CMSIS_5.git 20285262657d1b482d132d20d755c8c330d55c1f
lib/FreeRTOS-Kernel https://github.com/FreeRTOS/FreeRTOS-Kernel.git def7d2df2b0506d3d249334974f51e427c17a41c
lib/lwip https://github.com/lwip-tcpip/lwip.git 159e31b689577dbf69cf0683bbaffbd71fa5ee10
Expand Down
5 changes: 4 additions & 1 deletion docs/reference/supported.rst
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ Supported MCUs
| ValentyUSB | eptri |||| eptri | |
+--------------+-----------------------+--------+------+-----------+-------------------+--------------+
| WCH | CH32V307 || || ch32v307 | |
| +-----------------------+--------+------+-----------+-------------------+--------------+
| | CH32F20x || || ch32f205 | |
+--------------+-----------------------+--------+------+-----------+-------------------+--------------+


Expand Down Expand Up @@ -435,4 +437,5 @@ Tomu
WCH
---

- `CH32V307V-R1-1v0 <https://lcsc.com/product-detail/Development-Boards-Kits_WCH-Jiangsu-Qin-Heng-CH32V307V-EVT-R1_C2943980.html>`
- `CH32V307V-R1-1v0 <https://lcsc.com/product-detail/Development-Boards-Kits_WCH-Jiangsu-Qin-Heng-CH32V307V-EVT-R1_C2943980.html>`__
- `CH32F205R-R0-1v0 <https://github.com/openwch/ch32f20x/blob/main/EVT/PUB/CH32F20x%20Evaluation%20Board%20Reference-EN.pdf>`__
3 changes: 3 additions & 0 deletions hw/bsp/board_mcu.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@
#elif CFG_TUSB_MCU == OPT_MCU_TM4C123
#include "TM4C123.h"

#elif CFG_TUSB_MCU == OPT_MCU_CH32F20X
#include "ch32f20x.h"

#elif TU_CHECK_MCU(OPT_MCU_BCM2711, OPT_MCU_BCM2835, OPT_MCU_BCM2837)
// no header needed

Expand Down
59 changes: 59 additions & 0 deletions hw/bsp/ch32f20x/boards/ch32f205r-r0/board.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2023, Denis Krasutski
*
* 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.
*/

#ifndef BOARD_H_
#define BOARD_H_

#ifdef __cplusplus
extern "C" {
#endif

// LED: need to wire pin LED1 to PC0 in the P1 header
#define LED_PORT GPIOC
#define LED_PIN GPIO_Pin_1
#define LED_STATE_ON 0
#define LED_CLOCK_EN() RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE)

// Button: need to wire pin KEY to PC1 in the P1 header
#define BUTTON_PORT GPIOC
#define BUTTON_PIN GPIO_Pin_0
#define BUTTON_STATE_ACTIVE 0
#define BUTTON_CLOCK_EN() RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE)

// UART
#define UART_DEV USART2
#define UART_DEV_IRQn USART2_IRQn
#define UART_DEV_IRQHandler USART2_IRQHandler
#define UART_DEV_GPIO_PORT GPIOA
#define UART_DEV_TX_PIN GPIO_Pin_2
#define UART_DEV_CLK_EN() do { \
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); \
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE); \
} while(0)

#ifdef __cplusplus
}
#endif

#endif
7 changes: 7 additions & 0 deletions hw/bsp/ch32f20x/boards/ch32f205r-r0/board.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
LD_FILE = $(FAMILY_PATH)/ch32f205.ld

SRC_S += \
$(FAMILY_PATH)/startup_gcc_ch32f20x_d8c.s

CFLAGS += \
-DCH32F20x_D8C
111 changes: 111 additions & 0 deletions hw/bsp/ch32f20x/ch32f205.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
ENTRY(Reset_Handler)

_Min_Heap_Size = 0x200;
_Min_Stack_Size = 0x400;

MEMORY
{
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 128K
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 32K
}
SECTIONS
{
.isr_vector :
{
. = ALIGN(4);
KEEP(*(.isr_vector))
. = ALIGN(4);
} >FLASH

.text :
{
. = ALIGN(4);
_stext = .;
*(.text)
*(.text*)
*(.glue_7)
*(.glue_7t)
*(.eh_frame)
KEEP (*(.init))
KEEP (*(.fini))
. = ALIGN(4);
_etext = .;
} >FLASH
.rodata :
{
. = ALIGN(4);
*(.rodata)
*(.rodata*)
. = ALIGN(4);
} >FLASH
.ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH
.ARM : {
__exidx_start = .;
*(.ARM.exidx*)
__exidx_end = .;
} >FLASH
.preinit_array :
{
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array*))
PROVIDE_HIDDEN (__preinit_array_end = .);
} >FLASH
.init_array :
{
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array*))
PROVIDE_HIDDEN (__init_array_end = .);
} >FLASH
.fini_array :
{
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(SORT(.fini_array.*)))
KEEP (*(.fini_array*))
PROVIDE_HIDDEN (__fini_array_end = .);
} >FLASH
_sidata = LOADADDR(.data);
.data :
{
. = ALIGN(4);
_sdata = .;
*(.data)
*(.data*)
. = ALIGN(4);
_edata = .;
} >RAM AT> FLASH
. = ALIGN(4);
.bss :
{
_sbss = .;
__bss_start__ = _sbss;
*(.bss)
*(.bss*)
*(COMMON)
. = ALIGN(4);
_ebss = .;
__bss_end__ = _ebss;
} >RAM
._user_heap_stack :
{
. = ALIGN(4);
PROVIDE ( end = . );
PROVIDE ( _end = . );
__HeapStart = .;
. = . + _Min_Heap_Size;
__HeapEnd = .;
__StackLimit = .;
. = . + _Min_Stack_Size;
__StackTop = .;
. = ALIGN(4);
} >RAM
_estack = __StackTop;
_sstack = __StackLimit;
/DISCARD/ :
{
libc.a ( * )
libm.a ( * )
libgcc.a ( * )
}
.ARM.attributes 0 : { *(.ARM.attributes) }
}
39 changes: 39 additions & 0 deletions hw/bsp/ch32f20x/ch32f20x_conf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : ch32f20x_conf.h
* Author : WCH
* Version : V1.0.0
* Date : 2021/08/08
* Description : Library configuration file.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef __CH32F20x_CONF_H
#define __CH32F20x_CONF_H

#include "ch32f20x_adc.h"
#include "ch32f20x_bkp.h"
#include "ch32f20x_can.h"
#include "ch32f20x_crc.h"
#include "ch32f20x_dac.h"
#include "ch32f20x_dbgmcu.h"
#include "ch32f20x_dma.h"
#include "ch32f20x_exti.h"
#include "ch32f20x_flash.h"
#include "ch32f20x_fsmc.h"
#include "ch32f20x_gpio.h"
#include "ch32f20x_i2c.h"
#include "ch32f20x_iwdg.h"
#include "ch32f20x_pwr.h"
#include "ch32f20x_rcc.h"
#include "ch32f20x_rtc.h"
#include "ch32f20x_sdio.h"
#include "ch32f20x_spi.h"
#include "ch32f20x_tim.h"
#include "ch32f20x_usart.h"
#include "ch32f20x_wwdg.h"
#include "ch32f20x_it.h"
#include "ch32f20x_misc.h"

#endif /* __CH32F20x_CONF_H */
35 changes: 35 additions & 0 deletions hw/bsp/ch32f20x/ch32f20x_it.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "ch32f20x_it.h"

#include "ch32f20x.h"

/* -------------------------------------------------------------------------- */

void NMI_Handler(void) {

}

/* -------------------------------------------------------------------------- */

void MemManage_Handler(void) {

}

/* -------------------------------------------------------------------------- */

void BusFault_Handler(void) {

}

/* -------------------------------------------------------------------------- */

void UsageFault_Handler(void) {

}

/* -------------------------------------------------------------------------- */

void DebugMon_Handler(void) {

}

/* -------------------------------------------------------------------------- */
25 changes: 25 additions & 0 deletions hw/bsp/ch32f20x/ch32f20x_it.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : ch32f20x_it.h
* Author : WCH
* Version : V1.0.0
* Date : 2021/08/08
* Description : This file contains the headers of the interrupt handlers.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef __CH32F20xIT_H
#define __CH32F20xIT_H

#include "ch32f20x.h"

void NMI_Handler(void);
void HardFault_Handler(void);
void MemManage_Handler(void);
void BusFault_Handler(void);
void UsageFault_Handler(void);
void DebugMon_Handler(void);


#endif /* __CH32F20xIT_H */
11 changes: 11 additions & 0 deletions hw/bsp/ch32f20x/core_cm3.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* There is core_cm3.h wrapper just to avoid warnings from CMSIS headers */
/* if you want use original file add to make file:
INC += \
$(TOP)/$(CH32F20X_SDK_SRC)/CMSIS
*/
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstrict-prototypes"

#include <../../CMSIS/core_cm3.h>

#pragma GCC diagnostic pop
Loading

0 comments on commit f03f60e

Please sign in to comment.