Compare commits
No commits in common. "629a634a3ef27ca502853ea4386d0362954c6403" and "0be7187865a70f711390f92cd272f0c353a9fce9" have entirely different histories.
629a634a3e
...
0be7187865
4 changed files with 1 additions and 379 deletions
|
@ -1,10 +1,3 @@
|
|||
# LOCATION: projectroot/src
|
||||
add_executable(main
|
||||
main.c
|
||||
ch32v20x_it.c
|
||||
main.c
|
||||
)
|
||||
|
||||
add_subdirectory(core)
|
||||
add_subdirectory(peripheral)
|
||||
add_subdirectory(system)
|
||||
add_subdirectory(startup)
|
||||
|
|
|
@ -1,191 +0,0 @@
|
|||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : debug.c
|
||||
* Author : WCH
|
||||
* Version : V1.0.0
|
||||
* Date : 2021/06/06
|
||||
* Description : This file contains all the functions prototypes for UART
|
||||
* Printf , Delay functions.
|
||||
*********************************************************************************
|
||||
* 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.
|
||||
*******************************************************************************/
|
||||
#include "debug.h"
|
||||
|
||||
static uint8_t p_us = 0;
|
||||
static uint16_t p_ms = 0;
|
||||
/*********************************************************************
|
||||
* @fn Delay_Init
|
||||
*
|
||||
* @brief Initializes Delay Funcation.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void Delay_Init(void)
|
||||
{
|
||||
p_us = SystemCoreClock / 8000000;
|
||||
p_ms = (uint16_t)p_us * 1000;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn Delay_Us
|
||||
*
|
||||
* @brief Microsecond Delay Time.
|
||||
*
|
||||
* @param n - Microsecond number.
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void Delay_Us(uint32_t n)
|
||||
{
|
||||
uint32_t i;
|
||||
|
||||
SysTick->SR &= ~(1 << 0);
|
||||
i = (uint32_t)n * p_us;
|
||||
|
||||
SysTick->CMP = i;
|
||||
SysTick->CTLR |= (1 << 4);
|
||||
SysTick->CTLR |= (1 << 5) | (1 << 0);
|
||||
|
||||
while((SysTick->SR & (1 << 0)) != (1 << 0));
|
||||
SysTick->CTLR &= ~(1 << 0);
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn Delay_Ms
|
||||
*
|
||||
* @brief Millisecond Delay Time.
|
||||
*
|
||||
* @param n - Millisecond number.
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void Delay_Ms(uint32_t n)
|
||||
{
|
||||
uint32_t i;
|
||||
|
||||
SysTick->SR &= ~(1 << 0);
|
||||
i = (uint32_t)n * p_ms;
|
||||
|
||||
SysTick->CMP = i;
|
||||
SysTick->CTLR |= (1 << 4);
|
||||
SysTick->CTLR |= (1 << 5) | (1 << 0);
|
||||
|
||||
while((SysTick->SR & (1 << 0)) != (1 << 0));
|
||||
SysTick->CTLR &= ~(1 << 0);
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn USART_Printf_Init
|
||||
*
|
||||
* @brief Initializes the USARTx peripheral.
|
||||
*
|
||||
* @param baudrate - USART communication baud rate.
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void USART_Printf_Init(uint32_t baudrate)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
USART_InitTypeDef USART_InitStructure;
|
||||
|
||||
#if(DEBUG == DEBUG_UART1)
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA, ENABLE);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
|
||||
GPIO_Init(GPIOA, &GPIO_InitStructure);
|
||||
|
||||
#elif(DEBUG == DEBUG_UART2)
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
|
||||
GPIO_Init(GPIOA, &GPIO_InitStructure);
|
||||
|
||||
#elif(DEBUG == DEBUG_UART3)
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
|
||||
GPIO_Init(GPIOB, &GPIO_InitStructure);
|
||||
|
||||
#endif
|
||||
|
||||
USART_InitStructure.USART_BaudRate = baudrate;
|
||||
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
|
||||
USART_InitStructure.USART_StopBits = USART_StopBits_1;
|
||||
USART_InitStructure.USART_Parity = USART_Parity_No;
|
||||
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
|
||||
USART_InitStructure.USART_Mode = USART_Mode_Tx;
|
||||
|
||||
#if(DEBUG == DEBUG_UART1)
|
||||
USART_Init(USART1, &USART_InitStructure);
|
||||
USART_Cmd(USART1, ENABLE);
|
||||
|
||||
#elif(DEBUG == DEBUG_UART2)
|
||||
USART_Init(USART2, &USART_InitStructure);
|
||||
USART_Cmd(USART2, ENABLE);
|
||||
|
||||
#elif(DEBUG == DEBUG_UART3)
|
||||
USART_Init(USART3, &USART_InitStructure);
|
||||
USART_Cmd(USART3, ENABLE);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn _write
|
||||
*
|
||||
* @brief Support Printf Function
|
||||
*
|
||||
* @param *buf - UART send Data.
|
||||
* size - Data length
|
||||
*
|
||||
* @return size: Data length
|
||||
*/
|
||||
__attribute__((used))
|
||||
int _write(int fd, char *buf, int size)
|
||||
{
|
||||
int i;
|
||||
|
||||
for(i = 0; i < size; i++){
|
||||
#if(DEBUG == DEBUG_UART1)
|
||||
while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET);
|
||||
USART_SendData(USART1, *buf++);
|
||||
#elif(DEBUG == DEBUG_UART2)
|
||||
while(USART_GetFlagStatus(USART2, USART_FLAG_TC) == RESET);
|
||||
USART_SendData(USART2, *buf++);
|
||||
#elif(DEBUG == DEBUG_UART3)
|
||||
while(USART_GetFlagStatus(USART3, USART_FLAG_TC) == RESET);
|
||||
USART_SendData(USART3, *buf++);
|
||||
#endif
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn _sbrk
|
||||
*
|
||||
* @brief Change the spatial position of data segment.
|
||||
*
|
||||
* @return size: Data length
|
||||
*/
|
||||
void *_sbrk(ptrdiff_t incr)
|
||||
{
|
||||
extern char _end[];
|
||||
extern char _heap_end[];
|
||||
static char *curbrk = _end;
|
||||
|
||||
if ((curbrk + incr < _end) || (curbrk + incr > _heap_end))
|
||||
return NULL - 1;
|
||||
|
||||
curbrk += incr;
|
||||
return curbrk - incr;
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : debug.h
|
||||
* Author : WCH
|
||||
* Version : V1.0.0
|
||||
* Date : 2021/06/06
|
||||
* Description : This file contains all the functions prototypes for UART
|
||||
* Printf , Delay functions.
|
||||
*********************************************************************************
|
||||
* 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 __DEBUG_H
|
||||
#define __DEBUG_H
|
||||
|
||||
#include "stdio.h"
|
||||
#include "ch32v20x.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* UART Printf Definition */
|
||||
#define DEBUG_UART1 1
|
||||
#define DEBUG_UART2 2
|
||||
#define DEBUG_UART3 3
|
||||
|
||||
/* DEBUG UATR Definition */
|
||||
#ifndef DEBUG
|
||||
#define DEBUG DEBUG_UART1
|
||||
#endif
|
||||
|
||||
void Delay_Init(void);
|
||||
void Delay_Us(uint32_t n);
|
||||
void Delay_Ms(uint32_t n);
|
||||
void USART_Printf_Init(uint32_t baudrate);
|
||||
|
||||
#if(DEBUG)
|
||||
#define PRINT(format, ...) printf(format, ##__VA_ARGS__)
|
||||
#else
|
||||
#define PRINT(X...)
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,132 +0,0 @@
|
|||
# LOCATION: projectroot/src/peripheral
|
||||
|
||||
#Example/template lines.
|
||||
#add_library(ch32v20x_xxx SHARED
|
||||
# src/ch32v20x_xxx.c
|
||||
#)
|
||||
#
|
||||
#target_include_directories(ch32v20x_xxx PUBLIC ./inc)
|
||||
|
||||
|
||||
|
||||
add_library(ch32v20x_adc SHARED
|
||||
src/ch32v20x_adc.c
|
||||
)
|
||||
|
||||
target_include_directories(ch32v20x_adc PUBLIC ./inc)
|
||||
|
||||
|
||||
add_library(ch32v20x_xxx SHARED
|
||||
src/ch32v20x_xxx.c
|
||||
)
|
||||
|
||||
target_include_directories(ch32v20x_xxx PUBLIC ./inc)
|
||||
|
||||
|
||||
add_library(ch32v20x_can SHARED
|
||||
src/ch32v20x_can.c
|
||||
)
|
||||
|
||||
target_include_directories(ch32v20x_can PUBLIC ./inc)
|
||||
|
||||
|
||||
add_library(ch32v20x_dbgmcu SHARED
|
||||
src/ch32v20x_dbgmcu.c
|
||||
)
|
||||
|
||||
target_include_directories(ch32v20x_dbgmcu PUBLIC ./inc)
|
||||
|
||||
add_library(ch32v20x_exti SHARED
|
||||
src/ch32v20x_exti.c
|
||||
)
|
||||
|
||||
target_include_directories(ch32v20x_exti PUBLIC ./inc)
|
||||
|
||||
add_library(ch32v20x_gpio SHARED
|
||||
src/ch32v20x_gpio.c
|
||||
)
|
||||
|
||||
target_include_directories(ch32v20x_gpio PUBLIC ./inc)
|
||||
|
||||
|
||||
add_library(ch32v20x_i2c SHARED
|
||||
src/ch32v20x_i2c.c
|
||||
)
|
||||
|
||||
target_include_directories(ch32v20x_i2c PUBLIC ./inc)
|
||||
|
||||
|
||||
add_library(ch32v20x_misc SHARED
|
||||
src/ch32v20x_misc.c
|
||||
)
|
||||
|
||||
target_include_directories(ch32v20x_misc PUBLIC ./inc)
|
||||
|
||||
|
||||
add_library(ch32v20x_pwr SHARED
|
||||
src/ch32v20x_pwr.c
|
||||
)
|
||||
|
||||
target_include_directories(ch32v20x_pwr PUBLIC ./inc)
|
||||
|
||||
|
||||
add_library(ch32v20x_rtc SHARED
|
||||
src/ch32v20x_rtc.c
|
||||
)
|
||||
|
||||
target_include_directories(ch32v20x_rtc PUBLIC ./inc)
|
||||
|
||||
|
||||
add_library(ch32v20x_tim SHARED
|
||||
src/ch32v20x_tim.c
|
||||
)
|
||||
|
||||
target_include_directories(ch32v20x_tim PUBLIC ./inc)
|
||||
|
||||
|
||||
add_library(ch32v20x_usb SHARED
|
||||
src/ch32v20x_usb.c
|
||||
)
|
||||
|
||||
target_include_directories(ch32v20x_usb PUBLIC ./inc)
|
||||
|
||||
|
||||
add_library(ch32v20x_bkp SHARED
|
||||
src/ch32v20x_bkp.c
|
||||
)
|
||||
|
||||
target_include_directories(ch32v20x_bkp PUBLIC ./inc)
|
||||
|
||||
|
||||
add_library(ch32v20x_crc SHARED
|
||||
src/ch32v20x_crc.c
|
||||
)
|
||||
|
||||
target_include_directories(ch32v20x_crc PUBLIC ./inc)
|
||||
|
||||
|
||||
add_library(ch32v20x_dma SHARED
|
||||
src/ch32v20x_dma.c
|
||||
)
|
||||
|
||||
target_include_directories(ch32v20x_dma PUBLIC ./inc)
|
||||
|
||||
|
||||
add_library(ch32v20x_flash SHARED
|
||||
src/ch32v20x_flash.c
|
||||
)
|
||||
|
||||
target_include_directories(ch32v20x_flash PUBLIC ./inc)
|
||||
|
||||
|
||||
add_library(ch32v20x SHARED
|
||||
src/ch32v20x.c
|
||||
)
|
||||
|
||||
# This one doesn't have source code.
|
||||
#target_include_directories(ch32v20x PUBLIC ./inc)
|
||||
#
|
||||
#add_library(ch32v20x SHARED
|
||||
# src/ch32v20x.c
|
||||
#)
|
||||
|
Loading…
Add table
Reference in a new issue