-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2674 from hathach/add-ch32v103
Add ch32v103 (not working yet)
- Loading branch information
Showing
38 changed files
with
1,383 additions
and
969 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
mcu:CH32V103 | ||
mcu:CH32V20X | ||
mcu:CH32V307 | ||
mcu:CXD56 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
mcu:CH32V103 | ||
mcu:CH32V20X | ||
mcu:CH32V307 | ||
mcu:CXD56 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
mcu:CH32V103 | ||
mcu:CH32V20X | ||
mcu:CH32V307 | ||
mcu:CXD56 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
mcu:CH32V103 | ||
mcu:CH32V20X | ||
mcu:CH32V307 | ||
mcu:CXD56 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
mcu:CH32V103 | ||
mcu:CH32V20X | ||
mcu:LPC11UXX | ||
mcu:LPC13XX | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
mcu:CH32V103 | ||
mcu:CH32V20X | ||
mcu:MSP430x5xx | ||
mcu:NUC121 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ mcu:MSP430x5xx | |
mcu:NUC121 | ||
mcu:SAMD11 | ||
mcu:GD32VF103 | ||
mcu:CH32V103 | ||
mcu:CH32V20X | ||
mcu:CH32V307 | ||
mcu:STM32L0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
set(LD_FLASH_SIZE 64K) | ||
set(LD_RAM_SIZE 20K) | ||
|
||
function(update_board TARGET) | ||
target_compile_definitions(${TARGET} PUBLIC | ||
CFG_EXAMPLE_MSC_DUAL_READONLY | ||
) | ||
endfunction() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#ifndef BOARD_H_ | ||
#define BOARD_H_ | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#define LED_PORT GPIOA | ||
#define LED_PIN GPIO_Pin_10 | ||
#define LED_STATE_ON 0 | ||
|
||
#define BUTTON_PORT GPIOA | ||
#define BUTTON_PIN GPIO_Pin_1 | ||
#define BUTTON_STATE_ACTIVE 0 | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
CFLAGS += -DCFG_EXAMPLE_MSC_DUAL_READONLY | ||
|
||
LDFLAGS += \ | ||
-Wl,--defsym=__flash_size=64K \ | ||
-Wl,--defsym=__ram_size=20K \ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/********************************** (C) COPYRIGHT ******************************* | ||
* File Name : ch32v10x_conf.h | ||
* Author : WCH | ||
* Version : V1.0.0 | ||
* Date : 2020/04/30 | ||
* 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 __CH32V10x_CONF_H | ||
#define __CH32V10x_CONF_H | ||
|
||
#include "ch32v10x_adc.h" | ||
#include "ch32v10x_bkp.h" | ||
#include "ch32v10x_crc.h" | ||
#include "ch32v10x_dbgmcu.h" | ||
#include "ch32v10x_dma.h" | ||
#include "ch32v10x_exti.h" | ||
#include "ch32v10x_flash.h" | ||
#include "ch32v10x_gpio.h" | ||
#include "ch32v10x_i2c.h" | ||
#include "ch32v10x_iwdg.h" | ||
#include "ch32v10x_pwr.h" | ||
#include "ch32v10x_rcc.h" | ||
#include "ch32v10x_rtc.h" | ||
#include "ch32v10x_spi.h" | ||
#include "ch32v10x_tim.h" | ||
#include "ch32v10x_usart.h" | ||
#include "ch32v10x_wwdg.h" | ||
#include "ch32v10x_usb.h" | ||
#include "ch32v10x_usb_host.h" | ||
#include "ch32v10x_it.h" | ||
#include "ch32v10x_misc.h" | ||
|
||
#endif /* __CH32V10x_CONF_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/********************************** (C) COPYRIGHT ******************************* | ||
* File Name : ch32v10x_it.h | ||
* Author : WCH | ||
* Version : V1.0.0 | ||
* Date : 2022/08/20 | ||
* 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 __CH32V10x_IT_H | ||
#define __CH32V10x_IT_H | ||
|
||
#endif /* __CH32V10x_IT_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
#include <stdio.h> | ||
|
||
// https://github.com/openwch/ch32v307/pull/90 | ||
// https://github.com/openwch/ch32v20x/pull/12 | ||
#ifdef __GNUC__ | ||
#pragma GCC diagnostic push | ||
#pragma GCC diagnostic ignored "-Wstrict-prototypes" | ||
#endif | ||
|
||
#include "ch32v10x.h" | ||
|
||
#ifdef __GNUC__ | ||
#pragma GCC diagnostic pop | ||
#endif | ||
|
||
#include "bsp/board_api.h" | ||
#include "board.h" | ||
|
||
__attribute__((interrupt)) __attribute__((used)) | ||
void USBHD_IRQHandler(void) { | ||
#if CFG_TUD_WCH_USBIP_USBFS | ||
tud_int_handler(0); | ||
#endif | ||
} | ||
|
||
__attribute__((interrupt)) __attribute__((used)) | ||
void USBWakeUp_IRQHandler(void) { | ||
#if CFG_TUD_WCH_USBIP_USBFS | ||
tud_int_handler(0); | ||
#endif | ||
} | ||
|
||
#if CFG_TUSB_OS == OPT_OS_NONE | ||
volatile uint32_t system_ticks = 0; | ||
|
||
__attribute__((interrupt)) __attribute__((used)) | ||
void SysTick_Handler(void) { | ||
SysTick->CNTL0 = SysTick->CNTL1 = SysTick->CNTL2 = SysTick->CNTL3 = 0; | ||
SysTick->CNTH0 = SysTick->CNTH1 = SysTick->CNTH2 = SysTick->CNTH3 = 0; | ||
system_ticks++; | ||
} | ||
|
||
uint32_t SysTick_Config(uint32_t ticks) { | ||
NVIC_EnableIRQ(SysTicK_IRQn); | ||
SysTick->CTLR = 0; | ||
SysTick->CNTL0 = SysTick->CNTL1 = SysTick->CNTL2 = SysTick->CNTL3 = 0; | ||
SysTick->CNTH0 = SysTick->CNTH1 = SysTick->CNTH2 = SysTick->CNTH3 = 0; | ||
|
||
SysTick->CMPLR0 = (u8)(ticks & 0xFF); | ||
SysTick->CMPLR1 = (u8)(ticks >> 8); | ||
SysTick->CMPLR2 = (u8)(ticks >> 16); | ||
SysTick->CMPLR3 = (u8)(ticks >> 24); | ||
|
||
SysTick->CMPHR0 = SysTick->CMPHR1 = SysTick->CMPHR2 = SysTick->CMPHR3 = 0; | ||
SysTick->CTLR = 1; | ||
return 0; | ||
} | ||
|
||
uint32_t board_millis(void) { | ||
return system_ticks; | ||
} | ||
#endif | ||
|
||
void board_init(void) { | ||
__disable_irq(); | ||
|
||
#if CFG_TUSB_OS == OPT_OS_NONE | ||
SysTick_Config(SystemCoreClock / 1000); | ||
#endif | ||
|
||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); | ||
|
||
EXTEN->EXTEN_CTR |= EXTEN_USBFS_IO_EN; | ||
uint8_t usb_div; | ||
switch (SystemCoreClock) { | ||
case 48000000: usb_div = RCC_USBCLKSource_PLLCLK_Div1; break; | ||
case 72000000: usb_div = RCC_USBCLKSource_PLLCLK_1Div5; break; | ||
default: TU_ASSERT(0,); break; | ||
} | ||
RCC_USBCLKConfig(usb_div); | ||
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_USBFS, ENABLE); | ||
|
||
#ifdef LED_PIN | ||
GPIO_InitTypeDef led_init = { | ||
.GPIO_Pin = LED_PIN, | ||
.GPIO_Mode = GPIO_Mode_Out_OD, | ||
.GPIO_Speed = GPIO_Speed_50MHz, | ||
}; | ||
GPIO_Init(LED_PORT, &led_init); | ||
#endif | ||
|
||
#ifdef BUTTON_PIN | ||
GPIO_InitTypeDef button_init = { | ||
.GPIO_Pin = BUTTON_PIN, | ||
.GPIO_Mode = GPIO_Mode_IPU, | ||
.GPIO_Speed = GPIO_Speed_50MHz, | ||
}; | ||
GPIO_Init(BUTTON_PORT, &button_init); | ||
#endif | ||
|
||
// UART TX is PA9 | ||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); | ||
GPIO_InitTypeDef usart_init = { | ||
.GPIO_Pin = GPIO_Pin_9, | ||
.GPIO_Speed = GPIO_Speed_50MHz, | ||
.GPIO_Mode = GPIO_Mode_AF_PP, | ||
}; | ||
GPIO_Init(GPIOA, &usart_init); | ||
|
||
USART_InitTypeDef usart = { | ||
.USART_BaudRate = 115200, | ||
.USART_WordLength = USART_WordLength_8b, | ||
.USART_StopBits = USART_StopBits_1, | ||
.USART_Parity = USART_Parity_No, | ||
.USART_Mode = USART_Mode_Tx, | ||
.USART_HardwareFlowControl = USART_HardwareFlowControl_None, | ||
}; | ||
USART_Init(USART1, &usart); | ||
USART_Cmd(USART1, ENABLE); | ||
|
||
__enable_irq(); | ||
|
||
board_led_write(true); | ||
} | ||
|
||
void board_led_write(bool state) { | ||
GPIO_WriteBit(LED_PORT, LED_PIN, state ? LED_STATE_ON : (1-LED_STATE_ON)); | ||
} | ||
|
||
uint32_t board_button_read(void) { | ||
return BUTTON_STATE_ACTIVE == GPIO_ReadInputDataBit(BUTTON_PORT, BUTTON_PIN); | ||
} | ||
|
||
int board_uart_read(uint8_t *buf, int len) { | ||
(void) buf; | ||
(void) len; | ||
return 0; | ||
} | ||
|
||
int board_uart_write(void const *buf, int len) { | ||
const char *bufc = (const char *) buf; | ||
for (int i = 0; i < len; i++) { | ||
while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET); | ||
USART_SendData(USART1, *bufc++); | ||
} | ||
|
||
return len; | ||
} |
Oops, something went wrong.