Updated template libraries

This commit is contained in:
Logan G 2023-11-25 01:18:19 -07:00
parent ba886be444
commit 37f81d5652
Signed by: logan
GPG key ID: E328528C921E7A7A
39 changed files with 15226 additions and 14395 deletions

View file

@ -4,8 +4,10 @@
* Version : V1.0.0
* Date : 2022/08/08
* Description : RISC-V Core Peripheral Access Layer Source File
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* SPDX-License-Identifier: Apache-2.0
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#include <stdint.h>

View file

@ -4,20 +4,26 @@
* Version : V1.0.0
* Date : 2022/08/08
* Description : RISC-V Core Peripheral Access Layer Header File
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* SPDX-License-Identifier: Apache-2.0
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef __CORE_RISCV_H__
#define __CORE_RISCV_H__
#ifdef __cplusplus
extern "C" {
#endif
/* IO definitions */
#ifdef __cplusplus
#define __I volatile /*!< defines 'read only' permissions */
#define __I volatile /* defines 'read only' permissions */
#else
#define __I volatile const /*!< defines 'read only' permissions */
#define __I volatile const /* defines 'read only' permissions */
#endif
#define __O volatile /*!< defines 'write only' permissions */
#define __IO volatile /*!< defines 'read / write' permissions */
#define __O volatile /* defines 'write only' permissions */
#define __IO volatile /* defines 'read / write' permissions */
/* Standard Peripheral Library old types (maintained for legacy purpose) */
typedef __I uint32_t vuc32; /* Read Only */
@ -115,9 +121,13 @@ typedef struct
*
* @return none
*/
RV_STATIC_INLINE void __enable_irq()
__attribute__( ( always_inline ) ) RV_STATIC_INLINE void __enable_irq()
{
__asm volatile ("csrw mstatus, %0" : : "r" (0x1888) );
uint32_t result;
__asm volatile("csrr %0," "mstatus": "=r"(result));
result |= 0x88;
__asm volatile ("csrw mstatus, %0" : : "r" (result) );
}
/*********************************************************************
@ -127,9 +137,13 @@ RV_STATIC_INLINE void __enable_irq()
*
* @return none
*/
RV_STATIC_INLINE void __disable_irq()
__attribute__( ( always_inline ) ) RV_STATIC_INLINE void __disable_irq()
{
__asm volatile ("csrw mstatus, %0" : : "r" (0x1800) );
uint32_t result;
__asm volatile("csrr %0," "mstatus": "=r"(result));
result &= ~0x88;
__asm volatile ("csrw mstatus, %0" : : "r" (result) );
}
/*********************************************************************
@ -139,7 +153,7 @@ RV_STATIC_INLINE void __disable_irq()
*
* @return none
*/
RV_STATIC_INLINE void __NOP()
__attribute__( ( always_inline ) ) RV_STATIC_INLINE void __NOP()
{
__asm volatile ("nop");
}
@ -147,13 +161,13 @@ RV_STATIC_INLINE void __NOP()
/*********************************************************************
* @fn NVIC_EnableIRQ
*
* @brief Disable Interrupt
* @brief Enable Interrupt
*
* @param IRQn - Interrupt Numbers
*
* @return none
*/
RV_STATIC_INLINE void NVIC_EnableIRQ(IRQn_Type IRQn)
__attribute__( ( always_inline ) ) RV_STATIC_INLINE void NVIC_EnableIRQ(IRQn_Type IRQn)
{
NVIC->IENR[((uint32_t)(IRQn) >> 5)] = (1 << ((uint32_t)(IRQn) & 0x1F));
}
@ -167,7 +181,7 @@ RV_STATIC_INLINE void NVIC_EnableIRQ(IRQn_Type IRQn)
*
* @return none
*/
RV_STATIC_INLINE void NVIC_DisableIRQ(IRQn_Type IRQn)
__attribute__( ( always_inline ) ) RV_STATIC_INLINE void NVIC_DisableIRQ(IRQn_Type IRQn)
{
NVIC->IRER[((uint32_t)(IRQn) >> 5)] = (1 << ((uint32_t)(IRQn) & 0x1F));
}
@ -179,10 +193,10 @@ RV_STATIC_INLINE void NVIC_DisableIRQ(IRQn_Type IRQn)
*
* @param IRQn - Interrupt Numbers
*
* @return 1 - 1: Interrupt Pending Enable
* @return 1 - Interrupt Pending Enable
* 0 - Interrupt Pending Disable
*/
RV_STATIC_INLINE uint32_t NVIC_GetStatusIRQ(IRQn_Type IRQn)
__attribute__( ( always_inline ) ) RV_STATIC_INLINE uint32_t NVIC_GetStatusIRQ(IRQn_Type IRQn)
{
return((uint32_t) ((NVIC->ISR[(uint32_t)(IRQn) >> 5] & (1 << ((uint32_t)(IRQn) & 0x1F)))?1:0));
}
@ -194,10 +208,10 @@ RV_STATIC_INLINE uint32_t NVIC_GetStatusIRQ(IRQn_Type IRQn)
*
* @param IRQn - Interrupt Numbers
*
* @return 1 - 1: Interrupt Pending Enable
* @return 1 - Interrupt Pending Enable
* 0 - Interrupt Pending Disable
*/
RV_STATIC_INLINE uint32_t NVIC_GetPendingIRQ(IRQn_Type IRQn)
__attribute__( ( always_inline ) ) RV_STATIC_INLINE uint32_t NVIC_GetPendingIRQ(IRQn_Type IRQn)
{
return((uint32_t) ((NVIC->IPR[(uint32_t)(IRQn) >> 5] & (1 << ((uint32_t)(IRQn) & 0x1F)))?1:0));
}
@ -211,7 +225,7 @@ RV_STATIC_INLINE uint32_t NVIC_GetPendingIRQ(IRQn_Type IRQn)
*
* @return none
*/
RV_STATIC_INLINE void NVIC_SetPendingIRQ(IRQn_Type IRQn)
__attribute__( ( always_inline ) ) RV_STATIC_INLINE void NVIC_SetPendingIRQ(IRQn_Type IRQn)
{
NVIC->IPSR[((uint32_t)(IRQn) >> 5)] = (1 << ((uint32_t)(IRQn) & 0x1F));
}
@ -225,7 +239,7 @@ RV_STATIC_INLINE void NVIC_SetPendingIRQ(IRQn_Type IRQn)
*
* @return none
*/
RV_STATIC_INLINE void NVIC_ClearPendingIRQ(IRQn_Type IRQn)
__attribute__( ( always_inline ) ) RV_STATIC_INLINE void NVIC_ClearPendingIRQ(IRQn_Type IRQn)
{
NVIC->IPRR[((uint32_t)(IRQn) >> 5)] = (1 << ((uint32_t)(IRQn) & 0x1F));
}
@ -240,7 +254,7 @@ RV_STATIC_INLINE void NVIC_ClearPendingIRQ(IRQn_Type IRQn)
* @return 1 - Interrupt Active
* 0 - Interrupt No Active
*/
RV_STATIC_INLINE uint32_t NVIC_GetActive(IRQn_Type IRQn)
__attribute__( ( always_inline ) ) RV_STATIC_INLINE uint32_t NVIC_GetActive(IRQn_Type IRQn)
{
return((uint32_t)((NVIC->IACTR[(uint32_t)(IRQn) >> 5] & (1 << ((uint32_t)(IRQn) & 0x1F)))?1:0));
}
@ -251,13 +265,13 @@ RV_STATIC_INLINE uint32_t NVIC_GetActive(IRQn_Type IRQn)
* @brief Set Interrupt Priority
*
* @param IRQn - Interrupt Numbers
* priority: bit7 - pre-emption priority
* bit6 - subpriority
* bit[5-0] - reserved
* priority: bit[7] - pre-emption priority
* bit[6] - subpriority
* bit[5:0] - reserved
*
* @return none
*/
RV_STATIC_INLINE void NVIC_SetPriority(IRQn_Type IRQn, uint8_t priority)
__attribute__( ( always_inline ) ) RV_STATIC_INLINE void NVIC_SetPriority(IRQn_Type IRQn, uint8_t priority)
{
NVIC->IPRIOR[(uint32_t)(IRQn)] = priority;
}
@ -275,6 +289,36 @@ __attribute__( ( always_inline ) ) RV_STATIC_INLINE void __WFI(void)
asm volatile ("wfi");
}
/*********************************************************************
* @fn _SEV
*
* @brief Set Event
*
* @return none
*/
__attribute__( ( always_inline ) ) RV_STATIC_INLINE void _SEV(void)
{
uint32_t t;
t = NVIC->SCTLR;
NVIC->SCTLR |= (1<<3)|(1<<5);
NVIC->SCTLR = (NVIC->SCTLR & ~(1<<5)) | ( t & (1<<5));
}
/*********************************************************************
* @fn _WFE
*
* @brief Wait for Events
*
* @return none
*/
__attribute__( ( always_inline ) ) RV_STATIC_INLINE void _WFE(void)
{
NVIC->SCTLR |= (1<<3);
asm volatile ("wfi");
}
/*********************************************************************
* @fn __WFE
*
@ -284,13 +328,9 @@ __attribute__( ( always_inline ) ) RV_STATIC_INLINE void __WFI(void)
*/
__attribute__( ( always_inline ) ) RV_STATIC_INLINE void __WFE(void)
{
uint32_t t;
t = NVIC->SCTLR;
NVIC->SCTLR |= (1<<3)|(1<<5); // (wfi->wfe)+(__sev)
NVIC->SCTLR = (NVIC->SCTLR & ~(1<<5)) | ( t & (1<<5));
asm volatile ("wfi");
asm volatile ("wfi");
_SEV();
_WFE();
_WFE();
}
/*********************************************************************
@ -305,7 +345,7 @@ __attribute__( ( always_inline ) ) RV_STATIC_INLINE void __WFE(void)
*
* @return none
*/
RV_STATIC_INLINE void SetVTFIRQ(uint32_t addr, IRQn_Type IRQn, uint8_t num, FunctionalState NewState){
__attribute__( ( always_inline ) ) RV_STATIC_INLINE void SetVTFIRQ(uint32_t addr, IRQn_Type IRQn, uint8_t num, FunctionalState NewState){
if(num > 1) return ;
if (NewState != DISABLE)
@ -326,7 +366,7 @@ RV_STATIC_INLINE void SetVTFIRQ(uint32_t addr, IRQn_Type IRQn, uint8_t num, Func
*
* @return none
*/
RV_STATIC_INLINE void NVIC_SystemReset(void)
__attribute__( ( always_inline ) ) RV_STATIC_INLINE void NVIC_SystemReset(void)
{
NVIC->CFGR = NVIC_KEY3|(1<<7);
}
@ -351,6 +391,9 @@ extern uint32_t __get_MIMPID(void);
extern uint32_t __get_MHARTID(void);
extern uint32_t __get_SP(void);
#ifdef __cplusplus
}
#endif
#endif/* __CORE_RISCV_H__ */

View file

@ -5,14 +5,19 @@
* Date : 2022/08/08
* Description : This file contains all the functions prototypes for UART
* Printf , Delay functions.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* SPDX-License-Identifier: Apache-2.0
* 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;
#define DEBUG_DATA0_ADDRESS ((volatile uint32_t*)0xE00000F4)
#define DEBUG_DATA1_ADDRESS ((volatile uint32_t*)0xE00000F8)
/*********************************************************************
* @fn Delay_Init
*
@ -44,7 +49,7 @@ void Delay_Us(uint32_t n)
SysTick->CMP = i;
SysTick->CNT = 0;
SysTick->CTLR |= (1 << 5) | (1 << 0);
SysTick->CTLR |=(1 << 0);
while((SysTick->SR & (1 << 0)) != (1 << 0));
SysTick->CTLR &= ~(1 << 0);
@ -68,7 +73,7 @@ void Delay_Ms(uint32_t n)
SysTick->CMP = i;
SysTick->CNT = 0;
SysTick->CTLR |= (1 << 5) | (1 << 0);
SysTick->CTLR |=(1 << 0);
while((SysTick->SR & (1 << 0)) != (1 << 0));
SysTick->CTLR &= ~(1 << 0);
@ -88,6 +93,7 @@ void USART_Printf_Init(uint32_t baudrate)
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
#if (DEBUG == DEBUG_UART1_NoRemap)
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_USART1, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
@ -95,6 +101,35 @@ void USART_Printf_Init(uint32_t baudrate)
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOD, &GPIO_InitStructure);
#elif (DEBUG == DEBUG_UART1_Remap1)
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_USART1 | RCC_APB2Periph_AFIO, ENABLE);
GPIO_PinRemapConfig(GPIO_PartialRemap1_USART1, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOD, &GPIO_InitStructure);
#elif (DEBUG == DEBUG_UART1_Remap2)
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_USART1 | RCC_APB2Periph_AFIO, ENABLE);
GPIO_PinRemapConfig(GPIO_PartialRemap2_USART1, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOD, &GPIO_InitStructure);
#elif (DEBUG == DEBUG_UART1_Remap3)
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_USART1 | RCC_APB2Periph_AFIO, ENABLE);
GPIO_PinRemapConfig(GPIO_FullRemap_USART1, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOC, &GPIO_InitStructure);
#endif
USART_InitStructure.USART_BaudRate = baudrate;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
@ -106,6 +141,22 @@ void USART_Printf_Init(uint32_t baudrate)
USART_Cmd(USART1, ENABLE);
}
/*********************************************************************
* @fn SDI_Printf_Enable
*
* @brief Initializes the SDI printf Function.
*
* @param None
*
* @return None
*/
void SDI_Printf_Enable(void)
{
*(DEBUG_DATA0_ADDRESS) = 0;
Delay_Init();
Delay_Ms(1);
}
/*********************************************************************
* @fn _write
*
@ -119,14 +170,51 @@ void USART_Printf_Init(uint32_t baudrate)
__attribute__((used))
int _write(int fd, char *buf, int size)
{
int i;
int i = 0;
int writeSize = size;
#if (SDI_PRINT == SDI_PR_OPEN)
do
{
/**
* data0 data1 8 bytes
* data0 The lowest byte storage length, the maximum is 7
*
*/
while( (*(DEBUG_DATA0_ADDRESS) != 0u))
{
}
if(writeSize>7)
{
*(DEBUG_DATA1_ADDRESS) = (*(buf+i+3)) | (*(buf+i+4)<<8) | (*(buf+i+5)<<16) | (*(buf+i+6)<<24);
*(DEBUG_DATA0_ADDRESS) = (7u) | (*(buf+i)<<8) | (*(buf+i+1)<<16) | (*(buf+i+2)<<24);
i += 7;
writeSize -= 7;
}
else
{
*(DEBUG_DATA1_ADDRESS) = (*(buf+i+3)) | (*(buf+i+4)<<8) | (*(buf+i+5)<<16) | (*(buf+i+6)<<24);
*(DEBUG_DATA0_ADDRESS) = (writeSize) | (*(buf+i)<<8) | (*(buf+i+1)<<16) | (*(buf+i+2)<<24);
writeSize = 0;
}
} while (writeSize);
#else
for(i = 0; i < size; i++){
while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET);
USART_SendData(USART1, *buf++);
}
return size;
#endif
return writeSize;
}
/*********************************************************************
@ -136,6 +224,7 @@ int _write(int fd, char *buf, int size)
*
* @return size: Data length
*/
__attribute__((used))
void *_sbrk(ptrdiff_t incr)
{
extern char _end[];

View file

@ -5,24 +5,48 @@
* Date : 2022/08/08
* Description : This file contains all the functions prototypes for UART
* Printf , Delay functions.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* SPDX-License-Identifier: Apache-2.0
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef __DEBUG_H
#define __DEBUG_H
#ifdef __cplusplus
extern "C" {
#endif
#include <ch32v00x.h>
#include <stdio.h>
/* UART Printf Definition */
#define DEBUG_UART1 1
#define DEBUG_UART1_NoRemap 1 //Tx-PD5
#define DEBUG_UART1_Remap1 2 //Tx-PD0
#define DEBUG_UART1_Remap2 3 //Tx-PD6
#define DEBUG_UART1_Remap3 4 //Tx-PC0
/* DEBUG UATR Definition */
#define DEBUG DEBUG_UART1
#ifndef DEBUG
#define DEBUG DEBUG_UART1_NoRemap
#endif
/* SDI Printf Definition */
#define SDI_PR_CLOSE 0
#define SDI_PR_OPEN 1
#ifndef SDI_PRINT
#define SDI_PRINT SDI_PR_CLOSE
#endif
void Delay_Init(void);
void Delay_Us(uint32_t n);
void Delay_Ms(uint32_t n);
void USART_Printf_Init(uint32_t baudrate);
void SDI_Printf_Enable(void);
#ifdef __cplusplus
}
#endif
#endif /* __DEBUG_H */

View file

@ -1,6 +1,6 @@
ENTRY( _start )
__stack_size = 512;
__stack_size = 256;
PROVIDE( _stack_size = __stack_size );

View file

@ -4,8 +4,10 @@
* Version : V1.0.0
* Date : 2022/08/08
* Description : CH32V00x Device Peripheral Access Layer Header File.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* SPDX-License-Identifier: Apache-2.0
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef __CH32V00x_H
#define __CH32V00x_H
@ -24,6 +26,11 @@ extern "C" {
#define HSI_VALUE ((uint32_t)24000000) /* Value of the Internal oscillator in Hz */
/* CH32V00x Standard Peripheral Library version number */
#define __CH32V00x_STDPERIPH_VERSION_MAIN (0x01) /* [15:8] main version */
#define __CH32V00x_STDPERIPH_VERSION_SUB (0x06) /* [7:0] sub version */
#define __CH32V00x_STDPERIPH_VERSION ( (__CH32V00x_STDPERIPH_VERSION_MAIN << 8)\
|(__CH32V00x_STDPERIPH_VERSION_SUB << 0))
/* Interrupt Number Definition, according to the selected device */
typedef enum IRQn
@ -328,7 +335,6 @@ typedef struct
typedef struct
{
__IO uint32_t EXTEN_CTR;
__IO uint32_t EXTEN_KR;
} EXTEN_TypeDef;
/* Peripheral memory map */
@ -368,7 +374,6 @@ typedef struct
#define FLASH_R_BASE (AHBPERIPH_BASE + 0x2000) /* Flash registers base address */
#define OB_BASE ((uint32_t)0x1FFFF800) /* Flash Option Bytes base address */
#define DBGMCU_BASE ((uint32_t)0xE000D000)
#define EXTEN_BASE ((uint32_t)0x40023800)
/* Peripheral declaration */
@ -397,7 +402,6 @@ typedef struct
#define RCC ((RCC_TypeDef *)RCC_BASE)
#define FLASH ((FLASH_TypeDef *)FLASH_R_BASE)
#define OB ((OB_TypeDef *)OB_BASE)
#define DBGMCU ((DBGMCU_TypeDef *)DBGMCU_BASE)
#define EXTEN ((EXTEN_TypeDef *)EXTEN_BASE)
/******************************************************************************/
@ -2385,31 +2389,11 @@ typedef struct
/******************************************************************************/
/**************************** Enhanced register *****************************/
#define EXTEN_PLLCLK_DLY ((uint32_t)0x0000000F) /* PLLCLK_DLY[3:0] */
#define EXTEN_PLLCLK_DLY_No ((uint32_t)0x00000001)
#define EXTEN_PLLCLK_DLY_6ns ((uint32_t)0x00000004)
#define EXTEN_PLLCLK_DLY_8ns ((uint32_t)0x00000005)
#define EXTEN_PLLCLK_DLY_9ns ((uint32_t)0x00000006)
#define EXTEN_PLLCLK_DLY_10ns ((uint32_t)0x00000007)
#define EXTEN_LOCKUP_EN ((uint32_t)0x00000040) /* Bit 6 */
#define EXTEN_LOCKUP_RSTF ((uint32_t)0x00000080) /* Bit 7 */
#define EXTEN_ULLDO_TRIM ((uint32_t)0x00000300) /* ULLDO_TRIM[1:0] bits */
#define EXTEN_ULLDO_TRIM0 ((uint32_t)0x00000100) /* Bit 0 */
#define EXTEN_ULLDO_TRIM1 ((uint32_t)0x00000200) /* Bit 1 */
#define EXTEN_ULLDO_TRIM2 ((uint32_t)0x00000300) /* Bit [1:0] */
#define EXTEN_LDO_TRIM ((uint32_t)0x00000400) /* Bit 10 */
#define EXTEN_FLASH_CLK_TRIM ((uint32_t)0x00003800) /* FLASH_CLK_TRIM[2:0] bits */
#define EXTEN_FLASH_CLK_TRIM_0ns ((uint32_t)0x0000800)
#define EXTEN_FLASH_CLK_TRIM_1ns ((uint32_t)0x00001000)
#define EXTEN_FLASH_CLK_TRIM_2ns ((uint32_t)0x00002000)
#define EXTEN_FLASH_CLK_TRIM_3ns ((uint32_t)0x00003000)
#define EXTEN_WR_EN ((uint32_t)0x00004000)
#define EXTEN_WR_LOCK ((uint32_t)0x00008000)
#define EXTEN_OPA_EN ((uint32_t)0x00010000)
#define EXTEN_OPA_NSEL ((uint32_t)0x00020000)
#define EXTEN_OPA_PSEL ((uint32_t)0x00040000)

View file

@ -5,8 +5,10 @@
* Date : 2022/08/08
* Description : This file contains all the functions prototypes for the
* ADC firmware library.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* SPDX-License-Identifier: Apache-2.0
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef __CH32V00x_ADC_H
#define __CH32V00x_ADC_H

View file

@ -5,8 +5,10 @@
* Date : 2022/08/08
* Description : This file contains all the functions prototypes for the
* DBGMCU firmware library.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* SPDX-License-Identifier: Apache-2.0
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef __CH32V00x_DBGMCU_H
#define __CH32V00x_DBGMCU_H
@ -28,7 +30,7 @@ uint32_t DBGMCU_GetDEVID(void);
uint32_t __get_DEBUG_CR(void);
void __set_DEBUG_CR(uint32_t value);
void DBGMCU_Config(uint32_t DBGMCU_Periph, FunctionalState NewState);
uint32_t DBGMCU_GetCHIPID( void );
#ifdef __cplusplus
}
#endif

View file

@ -5,8 +5,10 @@
* Date : 2022/08/08
* Description : This file contains all the functions prototypes for the
* DMA firmware library.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* SPDX-License-Identifier: Apache-2.0
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef __CH32V00x_DMA_H
#define __CH32V00x_DMA_H

View file

@ -5,8 +5,10 @@
* Date : 2022/08/08
* Description : This file contains all the functions prototypes for the
* EXTI firmware library.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* SPDX-License-Identifier: Apache-2.0
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef __CH32V00x_EXTI_H
#define __CH32V00x_EXTI_H

View file

@ -5,8 +5,10 @@
* Date : 2022/08/08
* Description : This file contains all the functions prototypes for the FLASH
* firmware library.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* SPDX-License-Identifier: Apache-2.0
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef __CH32V00x_FLASH_H
#define __CH32V00x_FLASH_H
@ -24,7 +26,10 @@ typedef enum
FLASH_ERROR_PG,
FLASH_ERROR_WRP,
FLASH_COMPLETE,
FLASH_TIMEOUT
FLASH_TIMEOUT,
FLASH_OP_RANGE_ERROR = 0xFD,
FLASH_ALIGN_ERROR = 0xFE,
FLASH_ADR_RANGE_ERROR = 0xFF,
} FLASH_Status;
/* Flash_Latency */
@ -68,7 +73,11 @@ typedef enum
#define OB_RST_NoEN ((uint16_t)0x0018) /* Reset IO disable (PD7)*/
#define OB_RST_EN_DT12ms ((uint16_t)0x0010) /* Reset IO enable (PD7) and Ignore delay time 12ms */
#define OB_RST_EN_DT1ms ((uint16_t)0x0008) /* Reset IO enable (PD7) and Ignore delay time 1ms */
#define OB_RST_EN_DT128ms ((uint16_t)0x0000) /* Reset IO enable (PD7) and Ignore delay time 128ms */
#define OB_RST_EN_DT128us ((uint16_t)0x0000) /* Reset IO enable (PD7) and Ignore delay time 128us */
/* Option_Bytes_Power_ON_Start_Mode */
#define OB_PowerON_Start_Mode_BOOT ((uint16_t)0x0020) /* from Boot after power on */
#define OB_PowerON_Start_Mode_USER ((uint16_t)0x0000) /* from User after power on */
/* FLASH_Interrupts */
#define FLASH_IT_ERROR ((uint32_t)0x00000400) /* FPEC error interrupt source */
@ -103,7 +112,7 @@ FLASH_Status FLASH_ProgramHalfWord(uint32_t Address, uint16_t Data);
FLASH_Status FLASH_ProgramOptionByteData(uint32_t Address, uint8_t Data);
FLASH_Status FLASH_EnableWriteProtection(uint32_t FLASH_Pages);
FLASH_Status FLASH_ReadOutProtection(FunctionalState NewState);
FLASH_Status FLASH_UserOptionByteConfig(uint16_t OB_IWDG, uint16_t OB_STOP, uint16_t OB_STDBY, uint16_t OB_RST);
FLASH_Status FLASH_UserOptionByteConfig(uint16_t OB_IWDG, uint16_t OB_STOP, uint16_t OB_STDBY, uint16_t OB_RST, uint16_t OB_PowerON_Start_Mode);
uint32_t FLASH_GetUserOptionByte(void);
uint32_t FLASH_GetWriteProtectionOptionByte(void);
FlagStatus FLASH_GetReadOutProtectionStatus(void);
@ -118,6 +127,9 @@ void FLASH_BufReset(void);
void FLASH_BufLoad(uint32_t Address, uint32_t Data0);
void FLASH_ErasePage_Fast(uint32_t Page_Address);
void FLASH_ProgramPage_Fast(uint32_t Page_Address);
void SystemReset_StartMode(uint32_t Mode);
FLASH_Status FLASH_ROM_ERASE(uint32_t StartAddr, uint32_t Length);
FLASH_Status FLASH_ROM_WRITE(uint32_t StartAddr, uint32_t *pbuf, uint32_t Length);
#ifdef __cplusplus
}

View file

@ -5,8 +5,10 @@
* Date : 2022/08/08
* Description : This file contains all the functions prototypes for the
* GPIO firmware library.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* SPDX-License-Identifier: Apache-2.0
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef __CH32V00x_GPIO_H
#define __CH32V00x_GPIO_H

View file

@ -5,8 +5,10 @@
* Date : 2022/08/08
* Description : This file contains all the functions prototypes for the
* I2C firmware library.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* SPDX-License-Identifier: Apache-2.0
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef __CH32V00x_I2C_H
#define __CH32V00x_I2C_H
@ -118,27 +120,169 @@ typedef struct
/****************I2C Master Events (Events grouped in order of communication)********************/
/********************************************************************************************************************
* @brief Start communicate
*
* After master use I2C_GenerateSTART() function sending the START condition,the master
* has to wait for event 5(the Start condition has been correctly
* released on the I2C bus ).
*
*/
/* EVT5 */
#define I2C_EVENT_MASTER_MODE_SELECT ((uint32_t)0x00030001) /* BUSY, MSL and SB flag */
/********************************************************************************************************************
* @brief Address Acknowledge
*
* When start condition correctly released on the bus(check EVT5), the
* master use I2C_Send7bitAddress() function sends the address of the slave(s) with which it will communicate
* it also determines master as transmitter or Receiver. Then the master has to wait that a slave acknowledges
* his address. If an acknowledge is sent on the bus, one of the following events will be set:
*
*
*
* 1) In case of Master Receiver (7-bit addressing): the I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED
* event is set.
*
* 2) In case of Master Transmitter (7-bit addressing): the I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED
* is set
*
* 3) In case of 10-Bit addressing mode, the master (after generating the START
* and checking on EVT5) use I2C_SendData() function send the header of 10-bit addressing mode.
* Then master wait EVT9. EVT9 means that the 10-bit addressing header has been correctly sent
* on the bus. Then master should use the function I2C_Send7bitAddress() to send the second part
* of the 10-bit address (LSB) . Then master should wait for event 6.
*
*
*/
/* EVT6 */
#define I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED ((uint32_t)0x00070082) /* BUSY, MSL, ADDR, TXE and TRA flags */
#define I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED ((uint32_t)0x00030002) /* BUSY, MSL and ADDR flags */
/*EVT9 */
#define I2C_EVENT_MASTER_MODE_ADDRESS10 ((uint32_t)0x00030008) /* BUSY, MSL and ADD10 flags */
/********************************************************************************************************************
* @brief Communication events
*
* If START condition has generated and slave address
* been acknowledged. then the master has to check one of the following events for
* communication procedures:
*
* 1) Master Receiver mode: The master has to wait on the event EVT7 then use
* I2C_ReceiveData() function to read the data received from the slave .
*
* 2) Master Transmitter mode: The master use I2C_SendData() function to send data
* then to wait on event EVT8 or EVT8_2.
* These two events are similar:
* - EVT8 means that the data has been written in the data register and is
* being shifted out.
* - EVT8_2 means that the data has been physically shifted out and output
* on the bus.
* In most cases, using EVT8 is sufficient for the application.
* Using EVT8_2 will leads to a slower communication speed but will more reliable .
* EVT8_2 is also more suitable than EVT8 for testing on the last data transmission
*
*
* Note:
* In case the user software does not guarantee that this event EVT7 is managed before
* the current byte end of transfer, then user may check on I2C_EVENT_MASTER_BYTE_RECEIVED
* and I2C_FLAG_BTF flag at the same time .But in this case the communication may be slower.
*
*
*/
/* Master Receive mode */
/* EVT7 */
#define I2C_EVENT_MASTER_BYTE_RECEIVED ((uint32_t)0x00030040) /* BUSY, MSL and RXNE flags */
/* Master Transmitter mode*/
/* EVT8 */
#define I2C_EVENT_MASTER_BYTE_TRANSMITTING ((uint32_t)0x00070080) /* TRA, BUSY, MSL, TXE flags */
/* EVT8_2 */
#define I2C_EVENT_MASTER_BYTE_TRANSMITTED ((uint32_t)0x00070084) /* TRA, BUSY, MSL, TXE and BTF flags */
/******************I2C Slave Events (Events grouped in order of communication)******************/
/********************************************************************************************************************
* @brief Start Communicate events
*
* Wait on one of these events at the start of the communication. It means that
* the I2C peripheral detected a start condition of master device generate on the bus.
* If the acknowledge feature is enabled through function I2C_AcknowledgeConfig()),The peripheral generates an ACK condition on the bus.
*
*
*
* a) In normal case (only one address managed by the slave), when the address
* sent by the master matches the own address of the peripheral (configured by
* I2C_OwnAddress1 field) the I2C_EVENT_SLAVE_XXX_ADDRESS_MATCHED event is set
* (where XXX could be TRANSMITTER or RECEIVER).
*
* b) In case the address sent by the master matches the second address of the
* peripheral (configured by the function I2C_OwnAddress2Config() and enabled
* by the function I2C_DualAddressCmd()) the events I2C_EVENT_SLAVE_XXX_SECONDADDRESS_MATCHED
* (where XXX could be TRANSMITTER or RECEIVER) are set.
*
* c) In case the address sent by the master is General Call (address 0x00) and
* if the General Call is enabled for the peripheral (using function I2C_GeneralCallCmd())
* the following event is set I2C_EVENT_SLAVE_GENERALCALLADDRESS_MATCHED.
*
*/
/* EVT1 */
/* a) Case of One Single Address managed by the slave */
#define I2C_EVENT_SLAVE_RECEIVER_ADDRESS_MATCHED ((uint32_t)0x00020002) /* BUSY and ADDR flags */
#define I2C_EVENT_SLAVE_TRANSMITTER_ADDRESS_MATCHED ((uint32_t)0x00060082) /* TRA, BUSY, TXE and ADDR flags */
/* b) Case of Dual address managed by the slave */
#define I2C_EVENT_SLAVE_RECEIVER_SECONDADDRESS_MATCHED ((uint32_t)0x00820000) /* DUALF and BUSY flags */
#define I2C_EVENT_SLAVE_TRANSMITTER_SECONDADDRESS_MATCHED ((uint32_t)0x00860080) /* DUALF, TRA, BUSY and TXE flags */
/* c) Case of General Call enabled for the slave */
#define I2C_EVENT_SLAVE_GENERALCALLADDRESS_MATCHED ((uint32_t)0x00120000) /* GENCALL and BUSY flags */
/********************************************************************************************************************
* @brief Communication events
*
* Wait on one of these events when EVT1 has already been checked :
*
* - Slave Receiver mode:
* - EVT2--The device is expecting to receive a data byte .
* - EVT4--The device is expecting the end of the communication: master
* sends a stop condition and data transmission is stopped.
*
* - Slave Transmitter mode:
* - EVT3--When a byte has been transmitted by the slave and the Master is expecting
* the end of the byte transmission. The two events I2C_EVENT_SLAVE_BYTE_TRANSMITTED and
* I2C_EVENT_SLAVE_BYTE_TRANSMITTING are similar. If the user software doesn't guarantee
* the EVT3 is managed before the current byte end of transfer The second one can optionally
* be used.
* - EVT3_2--When the master sends a NACK to tell slave device that data transmission
* shall end . The slave device has to stop sending
* data bytes and wait a Stop condition from bus.
*
* Note:
* If the user software does not guarantee that the event 2 is
* managed before the current byte end of transfer, User may check on I2C_EVENT_SLAVE_BYTE_RECEIVED
* and I2C_FLAG_BTF flag at the same time .
* In this case the communication will be slower.
*
*/
/* Slave Receiver mode*/
/* EVT2 */
#define I2C_EVENT_SLAVE_BYTE_RECEIVED ((uint32_t)0x00020040) /* BUSY and RXNE flags */
/* EVT4 */
#define I2C_EVENT_SLAVE_STOP_DETECTED ((uint32_t)0x00000010) /* STOPF flag */
/* Slave Transmitter mode -----------------------*/
/* EVT3 */
#define I2C_EVENT_SLAVE_BYTE_TRANSMITTED ((uint32_t)0x00060084) /* TRA, BUSY, TXE and BTF flags */
#define I2C_EVENT_SLAVE_BYTE_TRANSMITTING ((uint32_t)0x00060080) /* TRA, BUSY and TXE flags */
/*EVT3_2 */
#define I2C_EVENT_SLAVE_ACK_FAILURE ((uint32_t)0x00000400) /* AF flag */
void I2C_DeInit(I2C_TypeDef *I2Cx);
void I2C_Init(I2C_TypeDef *I2Cx, I2C_InitTypeDef *I2C_InitStruct);
void I2C_StructInit(I2C_InitTypeDef *I2C_InitStruct);
@ -166,12 +310,98 @@ void I2C_ARPCmd(I2C_TypeDef *I2Cx, FunctionalState NewState);
void I2C_StretchClockCmd(I2C_TypeDef *I2Cx, FunctionalState NewState);
void I2C_FastModeDutyCycleConfig(I2C_TypeDef *I2Cx, uint16_t I2C_DutyCycle);
/****************************************************************************************
* I2C State Monitoring Functions
****************************************************************************************/
/*****************************************************************************************
*
* I2C State Monitoring Functions
*
****************************************************************************************
* This I2C driver provides three different ways for I2C state monitoring
* profit the application requirements and constraints:
*
*
* a) First way:
* Using I2C_CheckEvent() function:
* It compares the status registers (STARR1 and STAR2) content to a given event
* (can be the combination of more flags).
* If the current status registers includes the given flags will return SUCCESS.
* and if the current status registers miss flags will returns ERROR.
* - When to use:
* - This function is suitable for most applications as well as for startup
* activity since the events are fully described in the product reference manual
* (CH32V03RM).
* - It is also suitable for users who need to define their own events.
* - Limitations:
* - If an error occurs besides to the monitored error,
* the I2C_CheckEvent() function may return SUCCESS despite the communication
* in corrupted state. it is suggeted to use error interrupts to monitor the error
* events and handle them in IRQ handler.
*
*
* Note:
* The following functions are recommended for error management: :
* - I2C_ITConfig() main function of configure and enable the error interrupts.
* - I2Cx_ER_IRQHandler() will be called when the error interrupt happen.
* Where x is the peripheral instance (I2C1, I2C2 ...)
* - I2Cx_ER_IRQHandler() will call I2C_GetFlagStatus() or I2C_GetITStatus() functions
* to determine which error occurred.
* - I2C_ClearFlag() \ I2C_ClearITPendingBit() \ I2C_SoftwareResetCmd()
* \ I2C_GenerateStop() will be use to clear the error flag and source,
* and return to correct communication status.
*
*
* b) Second way:
* Using the function to get a single word(uint32_t) composed of status register 1 and register 2.
* (Status Register 2 value is shifted left by 16 bits and concatenated to Status Register 1).
* - When to use:
*
* - This function is suitable for the same applications above but it
* don't have the limitations of I2C_GetFlagStatus() function .
* The returned value could be compared to events already defined in the
* library (CH32V00x_i2c.h) or to custom values defined by user.
* - This function can be used to monitor the status of multiple flags simultaneously.
* - Contrary to the I2C_CheckEvent () function, this function can choose the time to
* accept the event according to the user's needs (when all event flags are set and
* no other flags are set, or only when the required flags are set)
*
* - Limitations:
* - User may need to define his own events.
* - Same remark concerning the error management is applicable for this
* function if user decides to check only regular communication flags (and
* ignores error flags).
*
*
* c) Third way:
* Using the function I2C_GetFlagStatus() get the status of
* one single flag .
* - When to use:
* - This function could be used for specific applications or in debug phase.
* - It is suitable when only one flag checking is needed .
*
* - Limitations:
* - Call this function to access the status register. Some flag bits may be cleared.
* - Function may need to be called twice or more in order to monitor one single event.
*/
/*********************************************************
*
* a) Basic state monitoring(First way)
********************************************************
*/
ErrorStatus I2C_CheckEvent(I2C_TypeDef* I2Cx, uint32_t I2C_EVENT);
/*********************************************************
*
* b) Advanced state monitoring(Second way:)
********************************************************
*/
uint32_t I2C_GetLastEvent(I2C_TypeDef* I2Cx);
/*********************************************************
*
* c) Flag-based state monitoring(Third way)
*********************************************************
*/
FlagStatus I2C_GetFlagStatus(I2C_TypeDef* I2Cx, uint32_t I2C_FLAG);
void I2C_ClearFlag(I2C_TypeDef *I2Cx, uint32_t I2C_FLAG);

View file

@ -5,8 +5,10 @@
* Date : 2022/08/08
* Description : This file contains all the functions prototypes for the
* IWDG firmware library.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* SPDX-License-Identifier: Apache-2.0
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef __CH32V00x_IWDG_H
#define __CH32V00x_IWDG_H

View file

@ -5,8 +5,10 @@
* Date : 2022/08/08
* Description : This file contains all the functions prototypes for the
* miscellaneous firmware library functions.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* SPDX-License-Identifier: Apache-2.0
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef __CH32V00X_MISC_H
#define __CH32V00X_MISC_H

View file

@ -5,8 +5,10 @@
* Date : 2022/08/08
* Description : This file contains all the functions prototypes for the
* OPA firmware library.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* SPDX-License-Identifier: Apache-2.0
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef __CH32V00x_OPA_H
#define __CH32V00x_OPA_H

View file

@ -5,8 +5,10 @@
* Date : 2022/08/08
* Description : This file contains all the functions prototypes for the PWR
* firmware library.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* SPDX-License-Identifier: Apache-2.0
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef __CH32V00x_PWR_H
#define __CH32V00x_PWR_H

View file

@ -4,8 +4,10 @@
* Version : V1.0.0
* Date : 2022/08/08
* Description : This file provides all the RCC firmware functions.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* SPDX-License-Identifier: Apache-2.0
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef __CH32V00x_RCC_H
#define __CH32V00x_RCC_H
@ -64,17 +66,17 @@ typedef struct
/* ADC_clock_source */
#define RCC_PCLK2_Div2 ((uint32_t)0x00000000)
#define RCC_PCLK2_Div4 ((uint32_t)0x00000800)
#define RCC_PCLK2_Div6 ((uint32_t)0x00001000)
#define RCC_PCLK2_Div8 ((uint32_t)0x00001800)
#define RCC_PCLK2_Div12 ((uint32_t)0x00009000)
#define RCC_PCLK2_Div16 ((uint32_t)0x00009100)
#define RCC_PCLK2_Div24 ((uint32_t)0x0000B000)
#define RCC_PCLK2_Div32 ((uint32_t)0x0000B100)
#define RCC_PCLK2_Div48 ((uint32_t)0x0000D000)
#define RCC_PCLK2_Div64 ((uint32_t)0x0000D100)
#define RCC_PCLK2_Div96 ((uint32_t)0x0000F000)
#define RCC_PCLK2_Div128 ((uint32_t)0x0000F100)
#define RCC_PCLK2_Div4 ((uint32_t)0x00004000)
#define RCC_PCLK2_Div6 ((uint32_t)0x00008000)
#define RCC_PCLK2_Div8 ((uint32_t)0x0000C000)
#define RCC_PCLK2_Div12 ((uint32_t)0x0000A000)
#define RCC_PCLK2_Div16 ((uint32_t)0x0000E000)
#define RCC_PCLK2_Div24 ((uint32_t)0x0000A800)
#define RCC_PCLK2_Div32 ((uint32_t)0x0000E800)
#define RCC_PCLK2_Div48 ((uint32_t)0x0000B000)
#define RCC_PCLK2_Div64 ((uint32_t)0x0000F000)
#define RCC_PCLK2_Div96 ((uint32_t)0x0000B800)
#define RCC_PCLK2_Div128 ((uint32_t)0x0000F800)
/* AHB_peripheral */
#define RCC_AHBPeriph_DMA1 ((uint32_t)0x00000001)
@ -124,7 +126,7 @@ void RCC_HSEConfig(uint32_t RCC_HSE);
ErrorStatus RCC_WaitForHSEStartUp(void);
void RCC_AdjustHSICalibrationValue(uint8_t HSICalibrationValue);
void RCC_HSICmd(FunctionalState NewState);
void RCC_PLLConfig(uint32_t RCC_PLLSource, uint32_t RCC_PLLMul);
void RCC_PLLConfig(uint32_t RCC_PLLSource);
void RCC_PLLCmd(FunctionalState NewState);
void RCC_SYSCLKConfig(uint32_t RCC_SYSCLKSource);
uint8_t RCC_GetSYSCLKSource(void);

View file

@ -5,8 +5,10 @@
* Date : 2022/08/08
* Description : This file contains all the functions prototypes for the
* SPI firmware library.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* SPDX-License-Identifier: Apache-2.0
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef __CH32V00x_SPI_H
#define __CH32V00x_SPI_H
@ -86,8 +88,9 @@ typedef struct
#define SPI_BaudRatePrescaler_128 ((uint16_t)0x0030)
#define SPI_BaudRatePrescaler_256 ((uint16_t)0x0038)
/* SPI_MSB transmission */
/* SPI_MSB_LSB transmission */
#define SPI_FirstBit_MSB ((uint16_t)0x0000)
#define SPI_FirstBit_LSB ((uint16_t)0x0080)//not support SPI slave mode
/* SPI_I2S_DMA_transfer_requests */
#define SPI_I2S_DMAReq_Tx ((uint16_t)0x0002)

View file

@ -5,8 +5,10 @@
* Date : 2022/08/08
* Description : This file contains all the functions prototypes for the
* TIM firmware library.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* SPDX-License-Identifier: Apache-2.0
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef __CH32V00x_TIM_H
#define __CH32V00x_TIM_H
@ -40,7 +42,7 @@ typedef struct
- the number of PWM periods in edge-aligned mode
- the number of half PWM period in center-aligned mode
This parameter must be a number between 0x00 and 0xFF.
@note This parameter is valid only for TIM1 and TIM8. */
@note This parameter is valid only for TIM1. */
} TIM_TimeBaseInitTypeDef;
/* TIM Output Compare Init structure definition */
@ -54,7 +56,7 @@ typedef struct
uint16_t TIM_OutputNState; /* Specifies the TIM complementary Output Compare state.
This parameter can be a value of @ref TIM_Output_Compare_N_state
@note This parameter is valid only for TIM1 and TIM8. */
@note This parameter is valid only for TIM1. */
uint16_t TIM_Pulse; /* Specifies the pulse value to be loaded into the Capture Compare Register.
This parameter can be a number between 0x0000 and 0xFFFF */
@ -64,15 +66,15 @@ typedef struct
uint16_t TIM_OCNPolarity; /* Specifies the complementary output polarity.
This parameter can be a value of @ref TIM_Output_Compare_N_Polarity
@note This parameter is valid only for TIM1 and TIM8. */
@note This parameter is valid only for TIM1. */
uint16_t TIM_OCIdleState; /* Specifies the TIM Output Compare pin state during Idle state.
This parameter can be a value of @ref TIM_Output_Compare_Idle_State
@note This parameter is valid only for TIM1 and TIM8. */
@note This parameter is valid only for TIM1. */
uint16_t TIM_OCNIdleState; /* Specifies the TIM Output Compare pin state during Idle state.
This parameter can be a value of @ref TIM_Output_Compare_N_Idle_State
@note This parameter is valid only for TIM1 and TIM8. */
@note This parameter is valid only for TIM1. */
} TIM_OCInitTypeDef;
/* TIM Input Capture Init structure definition */
@ -498,6 +500,7 @@ FlagStatus TIM_GetFlagStatus(TIM_TypeDef *TIMx, uint16_t TIM_FLAG);
void TIM_ClearFlag(TIM_TypeDef *TIMx, uint16_t TIM_FLAG);
ITStatus TIM_GetITStatus(TIM_TypeDef *TIMx, uint16_t TIM_IT);
void TIM_ClearITPendingBit(TIM_TypeDef *TIMx, uint16_t TIM_IT);
void TIM_IndicateCaptureLevelCmd(TIM_TypeDef *TIMx, FunctionalState NewState);
#ifdef __cplusplus
}

View file

@ -5,8 +5,10 @@
* Date : 2022/08/08
* Description : This file contains all the functions prototypes for the
* USART firmware library.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* SPDX-License-Identifier: Apache-2.0
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef __CH32V00x_USART_H
#define __CH32V00x_USART_H

View file

@ -5,8 +5,10 @@
* Date : 2022/08/08
* Description : This file contains all the functions prototypes for the WWDG
* firmware library.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* SPDX-License-Identifier: Apache-2.0
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef __CH32V00x_WWDG_H
#define __CH32V00x_WWDG_H

View file

@ -4,8 +4,10 @@
* Version : V1.0.0
* Date : 2022/08/08
* Description : This file provides all the ADC firmware functions.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* SPDX-License-Identifier: Apache-2.0
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#include <ch32v00x_adc.h>
#include <ch32v00x_rcc.h>
@ -789,7 +791,7 @@ void ADC_InjectedSequencerLengthConfig(ADC_TypeDef *ADCx, uint8_t Length)
* ADC_InjectedChannel_3 - Injected Channel3 selected.
* ADC_InjectedChannel_4 - Injected Channel4 selected.
* Offset - the offset value for the selected ADC injected channel.
* This parameter must be a 12bit value.
* This parameter must be a 10bit value.
*
* @return None
*/
@ -1051,7 +1053,7 @@ void ADC_Calibration_Vol(ADC_TypeDef *ADCx, uint32_t ADC_CALVOL)
*/
void ADC_ExternalTrig_DLY(ADC_TypeDef *ADCx, uint32_t channel, uint16_t DelayTim)
{
ADCx->DLYR &= ~(uint32_t)(0x2FF);
ADCx->DLYR &= ~(uint32_t)(0x3FF);
ADCx->DLYR |= channel;
ADCx->DLYR |= DelayTim;
}

View file

@ -4,9 +4,11 @@
* Version : V1.0.0
* Date : 2022/08/08
* Description : This file provides all the DBGMCU firmware functions.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* SPDX-License-Identifier: Apache-2.0
****************************************************************************************/
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#include <ch32v00x_dbgmcu.h>
@ -95,5 +97,20 @@ void DBGMCU_Config(uint32_t DBGMCU_Periph, FunctionalState NewState)
val &= ~(uint32_t)DBGMCU_Periph;
__set_DEBUG_CR(val);
}
}
/*********************************************************************
* @fn DBGMCU_GetCHIPID
*
* @brief Returns the CHIP identifier.
*
* @return Device identifier.
* ChipID List-
* CH32V003F4P6-0x003005x0
* CH32V003F4U6-0x003105x0
* CH32V003A4M6-0x003205x0
* CH32V003J4M6-0x003305x0
*/
uint32_t DBGMCU_GetCHIPID( void )
{
return( *( uint32_t * )0x1FFFF7C4 );
}

View file

@ -4,8 +4,10 @@
* Version : V1.0.0
* Date : 2022/08/08
* Description : This file provides all the DMA firmware functions.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* SPDX-License-Identifier: Apache-2.0
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#include <ch32v00x_dma.h>
#include <ch32v00x_rcc.h>

View file

@ -4,9 +4,11 @@
* Version : V1.0.0
* Date : 2022/08/08
* Description : This file provides all the EXTI firmware functions.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* SPDX-License-Identifier: Apache-2.0
***************************************************************************************/
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#include <ch32v00x_exti.h>
/* No interrupt selected */

View file

@ -4,9 +4,11 @@
* Version : V1.0.0
* Date : 2022/08/08
* Description : This file provides all the FLASH firmware functions.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* SPDX-License-Identifier: Apache-2.0
***************************************************************************************/
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#include <ch32v00x_flash.h>
/* Flash Access Control Register bits */
@ -25,6 +27,7 @@
#define CR_OPTER_Reset ((uint32_t)0xFFFFFFDF)
#define CR_STRT_Set ((uint32_t)0x00000040)
#define CR_LOCK_Set ((uint32_t)0x00000080)
#define CR_FLOCK_Set ((uint32_t)0x00008000)
#define CR_PAGE_PG ((uint32_t)0x00010000)
#define CR_PAGE_ER ((uint32_t)0x00020000)
#define CR_BUF_LOAD ((uint32_t)0x00040000)
@ -58,6 +61,10 @@
#define ValidAddrStart (FLASH_BASE)
#define ValidAddrEnd (FLASH_BASE + 0x4000)
/* FLASH Size */
#define Size_64B 0x40
#define Size_1KB 0x400
/********************************************************************************
* @fn FLASH_SetLatency
*
@ -426,12 +433,15 @@ FLASH_Status FLASH_ReadOutProtection(FunctionalState NewState)
* OB_RST_NoEN - Reset IO disable (PD7)
* OB_RST_EN_DT12ms - Reset IO enable (PD7) and Ignore delay time 12ms
* OB_RST_EN_DT1ms - Reset IO enable (PD7) and Ignore delay time 1ms
* OB_RST_EN_DT128ms - Reset IO enable (PD7) and Ignore delay time 128ms
* OB_RST_EN_DT128us - Reset IO enable (PD7) and Ignore delay time 128us
* OB_PowerON_Start_Mode - Selects start mode after power on.
* OB_PowerON_Start_Mode_BOOT - from Boot after power on.
* OB_PowerON_Start_Mode_USER - from User after power on.
*
* @return FLASH Status - The returned value can be: FLASH_BUSY, FLASH_ERROR_PG,
* FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
*/
FLASH_Status FLASH_UserOptionByteConfig(uint16_t OB_IWDG, uint16_t OB_STOP, uint16_t OB_STDBY, uint16_t OB_RST)
FLASH_Status FLASH_UserOptionByteConfig(uint16_t OB_IWDG, uint16_t OB_STOP, uint16_t OB_STDBY, uint16_t OB_RST, uint16_t OB_PowerON_Start_Mode)
{
FLASH_Status status = FLASH_COMPLETE;
@ -443,7 +453,7 @@ FLASH_Status FLASH_UserOptionByteConfig(uint16_t OB_IWDG, uint16_t OB_STOP, uint
{
FLASH->CTLR |= CR_OPTPG_Set;
OB->USER = OB_IWDG | (uint16_t)(OB_STOP | (uint16_t)(OB_STDBY | (uint16_t)(OB_RST | (uint16_t)0xE0)));
OB->USER = OB_IWDG | (uint16_t)(OB_STOP | (uint16_t)(OB_STDBY | (uint16_t)(OB_RST | (uint16_t)(OB_PowerON_Start_Mode| (uint16_t)0xC0))));
status = FLASH_WaitForLastOperation(ProgramTimeout);
if(status != FLASH_TIMEOUT)
@ -715,15 +725,15 @@ void FLASH_Unlock_Fast(void)
}
/*********************************************************************
* @fn FLASH_Unlock_Fast
* @fn FLASH_Lock_Fast
*
* @brief Unlocks the Fast Program Erase Mode.
* @brief Locks the Fast Program Erase Mode.
*
* @return none
*/
void FLASH_Lock_Fast(void)
{
FLASH->CTLR |= CR_LOCK_Set;
FLASH->CTLR |= CR_FLOCK_Set;
}
/*********************************************************************
@ -826,9 +836,234 @@ void SystemReset_StartMode(uint32_t Mode)
FLASH->BOOT_MODEKEYR = FLASH_KEY1;
FLASH->BOOT_MODEKEYR = FLASH_KEY2;
FLASH->STATR |= (1<<15);
FLASH->STATR &= ~(1<<14);
if(Mode == Start_Mode_BOOT){
FLASH->STATR |= (1<<14);
}
FLASH_Lock();
}
/*********************************************************************
* @fn ROM_ERASE
*
* @brief Select erases a specified FLASH .
*
* @param StartAddr - Erases Flash start address(StartAddr%64 == 0).
* Cnt - Erases count.
* Erase_Size - Erases size select.The returned value can be:
* Size_1KB, Size_64B.
*
* @return none.
*/
static void ROM_ERASE(uint32_t StartAddr, uint32_t Cnt, uint32_t Erase_Size)
{
do{
if(Erase_Size == Size_1KB)
{
FLASH->CTLR |= CR_PER_Set;
}
else if(Erase_Size == Size_64B)
{
FLASH->CTLR |= CR_PAGE_ER;
}
FLASH->ADDR = StartAddr;
FLASH->CTLR |= CR_STRT_Set;
while(FLASH->STATR & SR_BSY)
;
if(Erase_Size == Size_1KB)
{
FLASH->CTLR &= ~CR_PER_Set;
StartAddr += Size_1KB;
}
else if(Erase_Size == Size_64B)
{
FLASH->CTLR &= ~CR_PAGE_ER;
StartAddr += Size_64B;
}
}while(--Cnt);
}
/*********************************************************************
* @fn FLASH_ROM_ERASE
*
* @brief Erases a specified FLASH .
*
* @param StartAddr - Erases Flash start address(StartAddr%64 == 0).
* Length - Erases Flash start Length(Length%64 == 0).
*
* @return FLASH Status - The returned value can be: FLASH_ADR_RANGE_ERROR,
* FLASH_ALIGN_ERROR, FLASH_OP_RANGE_ERROR or FLASH_COMPLETE.
*/
FLASH_Status FLASH_ROM_ERASE( uint32_t StartAddr, uint32_t Length )
{
uint32_t Addr0 = 0, Addr1 = 0, Length0 = 0, Length1 = 0;
FLASH_Status status = FLASH_COMPLETE;
if((StartAddr < ValidAddrStart) || (StartAddr >= ValidAddrEnd))
{
return FLASH_ADR_RANGE_ERROR;
}
if((StartAddr + Length) > ValidAddrEnd)
{
return FLASH_OP_RANGE_ERROR;
}
if((StartAddr & (Size_64B-1)) || (Length & (Size_64B-1)) || (Length == 0))
{
return FLASH_ALIGN_ERROR;
}
/* Authorize the FPEC of Bank1 Access */
FLASH->KEYR = FLASH_KEY1;
FLASH->KEYR = FLASH_KEY2;
/* Fast program mode unlock */
FLASH->MODEKEYR = FLASH_KEY1;
FLASH->MODEKEYR = FLASH_KEY2;
Addr0 = StartAddr;
if(Length >= Size_1KB)
{
Length0 = Size_1KB - (Addr0 & (Size_1KB - 1));
Addr1 = StartAddr + Length0;
Length1 = Length - Length0;
}
else if(Length >= Size_64B)
{
Length0 = Length;
}
/* Erase 1KB */
if(Length0 >= Size_1KB) //front
{
Length = Length0;
if(Addr0 & (Size_1KB - 1))
{
Length0 = Size_1KB - (Addr0 & (Size_1KB - 1));
}
else
{
Length0 = 0;
}
ROM_ERASE((Addr0 + Length0), ((Length - Length0) >> 10), Size_1KB);
}
if(Length1 >= Size_1KB) //back
{
StartAddr = Addr1;
Length = Length1;
if((Addr1 + Length1) & (Size_1KB - 1))
{
Addr1 = ((StartAddr + Length1) & (~(Size_1KB - 1)));
Length1 = (StartAddr + Length1) & (Size_1KB - 1);
}
else
{
Length1 = 0;
}
ROM_ERASE(StartAddr, ((Length - Length1) >> 10), Size_1KB);
}
/* Erase 64B */
if(Length0)//front
{
ROM_ERASE(Addr0, (Length0 >> 6), Size_64B);
}
if(Length1)//back
{
ROM_ERASE(Addr1, (Length1 >> 6), Size_64B);
}
FLASH->CTLR |= CR_FLOCK_Set;
FLASH->CTLR |= CR_LOCK_Set;
return status;
}
/*********************************************************************
* @fn FLASH_ROM_WRITE
*
* @brief Writes a specified FLASH .
*
* @param StartAddr - Writes Flash start address(StartAddr%64 == 0).
* Length - Writes Flash start Length(Length%64 == 0).
* pbuf - Writes Flash value buffer.
*
* @return FLASH Status - The returned value can be: FLASH_ADR_RANGE_ERROR,
* FLASH_ALIGN_ERROR, FLASH_OP_RANGE_ERROR or FLASH_COMPLETE.
*/
FLASH_Status FLASH_ROM_WRITE( uint32_t StartAddr, uint32_t *pbuf, uint32_t Length )
{
uint32_t i, adr;
uint8_t size;
FLASH_Status status = FLASH_COMPLETE;
if((StartAddr < ValidAddrStart) || (StartAddr >= ValidAddrEnd))
{
return FLASH_ADR_RANGE_ERROR;
}
if((StartAddr + Length) > ValidAddrEnd)
{
return FLASH_OP_RANGE_ERROR;
}
if((StartAddr & (Size_64B-1)) || (Length & (Size_64B-1)) || (Length == 0))
{
return FLASH_ALIGN_ERROR;
}
adr = StartAddr;
i = Length >> 6;
/* Authorize the FPEC of Bank1 Access */
FLASH->KEYR = FLASH_KEY1;
FLASH->KEYR = FLASH_KEY2;
/* Fast program mode unlock */
FLASH->MODEKEYR = FLASH_KEY1;
FLASH->MODEKEYR = FLASH_KEY2;
do{
FLASH->CTLR |= CR_PAGE_PG;
FLASH->CTLR |= CR_BUF_RST;
while(FLASH->STATR & SR_BSY)
;
size = 16;
while(size)
{
*(__IO uint32_t *)(StartAddr) = *(uint32_t *)pbuf;
FLASH->CTLR |= CR_BUF_LOAD;
while(FLASH->STATR & SR_BSY)
;
StartAddr += 4;
pbuf += 1;
size -= 1;
}
FLASH->CTLR |= CR_PAGE_PG;
FLASH->ADDR = adr;
FLASH->CTLR |= CR_STRT_Set;
while(FLASH->STATR & SR_BSY)
;
FLASH->CTLR &= ~CR_PAGE_PG;
adr += 64;
}while(--i);
FLASH->CTLR |= CR_FLOCK_Set;
FLASH->CTLR |= CR_LOCK_Set;
return status;
}

View file

@ -4,8 +4,10 @@
* Version : V1.0.0
* Date : 2022/08/08
* Description : This file provides all the GPIO firmware functions.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* SPDX-License-Identifier: Apache-2.0
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#include <ch32v00x_gpio.h>
#include <ch32v00x_rcc.h>
@ -283,8 +285,8 @@ void GPIO_ResetBits(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
* @param GPIO_Pin - specifies the port bit to be written.
* This parameter can be one of GPIO_Pin_x where x can be (0..15).
* BitVal - specifies the value to be written to the selected bit.
* Bit_SetL - to clear the port pin.
* Bit_SetH - to set the port pin.
* Bit_RESET - to clear the port pin.
* Bit_SET - to set the port pin.
*
* @return none
*/
@ -346,7 +348,7 @@ void GPIO_PinLockConfig(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
* @param GPIO_Remap - selects the pin to remap.
* GPIO_Remap_SPI1 - SPI1 Alternate Function mapping
* GPIO_PartialRemap_I2C1 - I2C1 Partial Alternate Function mapping
* GPIO_PartialRemap_I2C1 - I2C1 Full Alternate Function mapping
* GPIO_FullRemap_I2C1 - I2C1 Full Alternate Function mapping
* GPIO_PartialRemap1_USART1 - USART1 Partial1 Alternate Function mapping
* GPIO_PartialRemap2_USART1 - USART1 Partial2 Alternate Function mapping
* GPIO_FullRemap_USART1 - USART1 Full Alternate Function mapping
@ -356,11 +358,11 @@ void GPIO_PinLockConfig(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
* GPIO_PartialRemap1_TIM2 - TIM2 Partial1 Alternate Function mapping
* GPIO_PartialRemap2_TIM2 - TIM2 Partial2 Alternate Function mapping
* GPIO_FullRemap_TIM2 - TIM2 Full Alternate Function mapping
* GPIO_Remap_PA12 - PA12 Alternate Function mapping
* GPIO_Remap_PA1_2 - PA1_2 Alternate Function mapping
* GPIO_Remap_ADC1_ETRGINJ - ADC1 External Trigger Injected Conversion remapping
* GPIO_Remap_ADC1_ETRGREG - ADC1 External Trigger Regular Conversion remapping
* GPIO_Remap_LSI_CAL - LSI calibration Alternate Function mapping
* GPIO_Remap_SWJ_Disable - SDI Disabled
* GPIO_Remap_SDI_Disable - SDI Disabled
* NewState - ENABLE or DISABLE.
*
* @return none
@ -451,6 +453,55 @@ void GPIO_EXTILineConfig(uint8_t GPIO_PortSource, uint8_t GPIO_PinSource)
AFIO->EXTICR |= ((uint32_t)(GPIO_PortSource<<(GPIO_PinSource<<1)));
}
/*********************************************************************
* @fn GPIO_IPD_Unused
*
* @brief Configure unused GPIO as input pull-up.
*
* @param none
*
* @return none
*/
void GPIO_IPD_Unused(void)
{
GPIO_InitTypeDef GPIO_InitStructure = {0};
uint32_t chip = 0;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOC, ENABLE);
chip = *( uint32_t * )0x1FFFF7C4 & (~0x000000F0);
switch(chip)
{
case 0x00320500: //CH32V003A4M6
{
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_2\
|GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOC, &GPIO_InitStructure);
break;
}
case 0x00330500: //CH32V003J4M6
{
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_2|GPIO_Pin_3\
|GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_3\
|GPIO_Pin_5|GPIO_Pin_6\
|GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOC, &GPIO_InitStructure);
break;
}
default:
{
break;
}
}
}

View file

@ -4,8 +4,10 @@
* Version : V1.0.0
* Date : 2022/08/08
* Description : This file provides all the I2C firmware functions.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* SPDX-License-Identifier: Apache-2.0
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#include <ch32v00x_i2c.h>
#include <ch32v00x_rcc.h>
@ -538,7 +540,10 @@ void I2C_SoftwareResetCmd(I2C_TypeDef *I2Cx, FunctionalState NewState)
* the last received byte.
* I2C_NACKPosition_Current - indicates that current byte is the
* last received byte.
*
* Note-
* This function configures the same bit (POS) as I2C_PECPositionConfig()
* but is intended to be used in I2C mode while I2C_PECPositionConfig()
* is intended to used in SMBUS mode.
* @return none
*/
void I2C_NACKPositionConfig(I2C_TypeDef *I2Cx, uint16_t I2C_NACKPosition)
@ -711,28 +716,28 @@ void I2C_FastModeDutyCycleConfig(I2C_TypeDef *I2Cx, uint16_t I2C_DutyCycle)
*
* @param I2Cx- where x can be 1 to select the I2C peripheral.
* I2C_EVENT: specifies the event to be checked.
* I2C_EVENT_SLAVE_TRANSMITTER_ADDRESS_MATCHED - EV1.
* I2C_EVENT_SLAVE_RECEIVER_ADDRESS_MATCHED - EV1.
* I2C_EVENT_SLAVE_TRANSMITTER_SECONDADDRESS_MATCHED - EV1.
* I2C_EVENT_SLAVE_RECEIVER_SECONDADDRESS_MATCHED - EV1.
* I2C_EVENT_SLAVE_GENERALCALLADDRESS_MATCHED - EV1.
* I2C_EVENT_SLAVE_BYTE_RECEIVED - EV2.
* (I2C_EVENT_SLAVE_BYTE_RECEIVED | I2C_FLAG_DUALF) - EV2.
* (I2C_EVENT_SLAVE_BYTE_RECEIVED | I2C_FLAG_GENCALL) - EV2.
* I2C_EVENT_SLAVE_BYTE_TRANSMITTED - EV3.
* (I2C_EVENT_SLAVE_BYTE_TRANSMITTED | I2C_FLAG_DUALF) - EV3.
* (I2C_EVENT_SLAVE_BYTE_TRANSMITTED | I2C_FLAG_GENCALL) - EV3.
* I2C_EVENT_SLAVE_ACK_FAILURE - EV3_2.
* I2C_EVENT_SLAVE_STOP_DETECTED - EV4.
* I2C_EVENT_MASTER_MODE_SELECT - EV5.
* I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED - EV6.
* I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED - EV6.
* I2C_EVENT_MASTER_BYTE_RECEIVED - EV7.
* I2C_EVENT_MASTER_BYTE_TRANSMITTING - EV8.
* I2C_EVENT_MASTER_BYTE_TRANSMITTED - EV8_2.
* I2C_EVENT_MASTER_MODE_ADDRESS10 - EV9.
* I2C_EVENT_SLAVE_TRANSMITTER_ADDRESS_MATCHED - EVT1.
* I2C_EVENT_SLAVE_RECEIVER_ADDRESS_MATCHED - EVT1.
* I2C_EVENT_SLAVE_TRANSMITTER_SECONDADDRESS_MATCHED - EVT1.
* I2C_EVENT_SLAVE_RECEIVER_SECONDADDRESS_MATCHED - EVT1.
* I2C_EVENT_SLAVE_GENERALCALLADDRESS_MATCHED - EVT1.
* I2C_EVENT_SLAVE_BYTE_RECEIVED - EVT2.
* (I2C_EVENT_SLAVE_BYTE_RECEIVED | I2C_FLAG_DUALF) - EVT2.
* (I2C_EVENT_SLAVE_BYTE_RECEIVED | I2C_FLAG_GENCALL) - EVT2.
* I2C_EVENT_SLAVE_BYTE_TRANSMITTED - EVT3.
* (I2C_EVENT_SLAVE_BYTE_TRANSMITTED | I2C_FLAG_DUALF) - EVT3.
* (I2C_EVENT_SLAVE_BYTE_TRANSMITTED | I2C_FLAG_GENCALL) - EVT3.
* I2C_EVENT_SLAVE_ACK_FAILURE - EVT3_2.
* I2C_EVENT_SLAVE_STOP_DETECTED - EVT4.
* I2C_EVENT_MASTER_MODE_SELECT - EVT5.
* I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED - EVT6.
* I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED - EVT6.
* I2C_EVENT_MASTER_BYTE_RECEIVED - EVT7.
* I2C_EVENT_MASTER_BYTE_TRANSMITTING - EVT8.
* I2C_EVENT_MASTER_BYTE_TRANSMITTED - EVT8_2.
* I2C_EVENT_MASTER_MODE_ADDRESS10 - EVT9.
*
* @return none
* @return ErrorStatus - READY or NoREADY.
*/
ErrorStatus I2C_CheckEvent(I2C_TypeDef *I2Cx, uint32_t I2C_EVENT)
{
@ -807,7 +812,7 @@ uint32_t I2C_GetLastEvent(I2C_TypeDef *I2Cx)
* Address matched flag (Slave mode)"ENDA".
* I2C_FLAG_SB - Start bit flag (Master mode).
*
* @return none
* @return FlagStatus - SET or RESET.
*/
FlagStatus I2C_GetFlagStatus(I2C_TypeDef *I2Cx, uint32_t I2C_FLAG)
{
@ -854,7 +859,22 @@ FlagStatus I2C_GetFlagStatus(I2C_TypeDef *I2Cx, uint32_t I2C_FLAG)
* I2C_FLAG_AF - Acknowledge failure flag.
* I2C_FLAG_ARLO - Arbitration lost flag (Master mode).
* I2C_FLAG_BERR - Bus error flag.
*
* Note-
* - STOPF (STOP detection) is cleared by software sequence: a read operation
* to I2C_STAR1 register (I2C_GetFlagStatus()) followed by a write operation
* to I2C_CTLR1 register (I2C_Cmd() to re-enable the I2C peripheral).
* - ADD10 (10-bit header sent) is cleared by software sequence: a read
* operation to I2C_SATR1 (I2C_GetFlagStatus()) followed by writing the
* second byte of the address in DATAR register.
* - BTF (Byte Transfer Finished) is cleared by software sequence: a read
* operation to I2C_SATR1 register (I2C_GetFlagStatus()) followed by a
* read/write to I2C_DATAR register (I2C_SendData()).
* - ADDR (Address sent) is cleared by software sequence: a read operation to
* I2C_SATR1 register (I2C_GetFlagStatus()) followed by a read operation to
* I2C_SATR2 register ((void)(I2Cx->SR2)).
* - SB (Start Bit) is cleared software sequence: a read operation to I2C_STAR1
* register (I2C_GetFlagStatus()) followed by a write operation to I2C_DATAR
* register (I2C_SendData()).
* @return none
*/
void I2C_ClearFlag(I2C_TypeDef *I2Cx, uint32_t I2C_FLAG)
@ -920,6 +940,22 @@ ITStatus I2C_GetITStatus(I2C_TypeDef *I2Cx, uint32_t I2C_IT)
* I2C_IT_AF - Acknowledge failure interrupt.
* I2C_IT_ARLO - Arbitration lost interrupt (Master mode).
* I2C_IT_BERR - Bus error interrupt.
* Note-
* - STOPF (STOP detection) is cleared by software sequence: a read operation
* to I2C_STAR1 register (I2C_GetITStatus()) followed by a write operation to
* I2C_CTLR1 register (I2C_Cmd() to re-enable the I2C peripheral).
* - ADD10 (10-bit header sent) is cleared by software sequence: a read
* operation to I2C_STAR1 (I2C_GetITStatus()) followed by writing the second
* byte of the address in I2C_DATAR register.
* - BTF (Byte Transfer Finished) is cleared by software sequence: a read
* operation to I2C_STAR1 register (I2C_GetITStatus()) followed by a
* read/write to I2C_DATAR register (I2C_SendData()).
* - ADDR (Address sent) is cleared by software sequence: a read operation to
* I2C_STAR1 register (I2C_GetITStatus()) followed by a read operation to
* I2C_STAR2 register ((void)(I2Cx->SR2)).
* - SB (Start Bit) is cleared by software sequence: a read operation to
* I2C_STAR1 register (I2C_GetITStatus()) followed by a write operation to
* I2C_DATAR register (I2C_SendData()).
*
* @return none
*/

View file

@ -4,8 +4,10 @@
* Version : V1.0.0
* Date : 2022/08/08
* Description : This file provides all the IWDG firmware functions.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* SPDX-License-Identifier: Apache-2.0
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#include <ch32v00x_iwdg.h>

View file

@ -4,9 +4,11 @@
* Version : V1.0.0
* Date : 2022/08/08
* Description : This file provides all the miscellaneous firmware functions .
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* SPDX-License-Identifier: Apache-2.0
*********************************************************************************/
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#include <ch32v00x_misc.h>
__IO uint32_t NVIC_Priority_Group = 0;

View file

@ -4,9 +4,11 @@
* Version : V1.0.0
* Date : 2022/08/08
* Description : This file provides all the OPA firmware functions.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* SPDX-License-Identifier: Apache-2.0
***************************************************************************************/
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#include <ch32v00x_opa.h>
@ -37,7 +39,7 @@ void OPA_Init(OPA_InitTypeDef *OPA_InitStruct)
{
uint32_t tmp = 0;
tmp = EXTEN->EXTEN_CTR;
tmp &= ~(uint32_t)(2<<17);
tmp &= ~(uint32_t)(3<<17);
tmp |= (OPA_InitStruct->PSEL << 18) | (OPA_InitStruct->NSEL << 17);
EXTEN->EXTEN_CTR = tmp;
}

View file

@ -4,9 +4,11 @@
* Version : V1.0.0
* Date : 2022/08/08
* Description : This file provides all the PWR firmware functions.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#include <ch32v00x_pwr.h>
#include <ch32v00x_rcc.h>
@ -59,14 +61,14 @@ void PWR_PVDCmd(FunctionalState NewState)
* Detector(PVD).
*
* @param PWR_PVDLevel - specifies the PVD detection level
* PWR_PVDLevel_2V2 - PVD detection level set to 2.2V
* PWR_PVDLevel_2V3 - PVD detection level set to 2.3V
* PWR_PVDLevel_2V4 - PVD detection level set to 2.4V
* PWR_PVDLevel_2V5 - PVD detection level set to 2.5V
* PWR_PVDLevel_2V6 - PVD detection level set to 2.6V
* PWR_PVDLevel_2V7 - PVD detection level set to 2.7V
* PWR_PVDLevel_2V8 - PVD detection level set to 2.8V
* PWR_PVDLevel_2V9 - PVD detection level set to 2.9V
* PWR_PVDLevel_3V1 - PVD detection level set to 3.1V
* PWR_PVDLevel_3V3 - PVD detection level set to 3.3V
* PWR_PVDLevel_3V5 - PVD detection level set to 3.5V
* PWR_PVDLevel_3V7 - PVD detection level set to 3.7V
* PWR_PVDLevel_3V9 - PVD detection level set to 3.9V
* PWR_PVDLevel_4V1 - PVD detection level set to 4.1V
* PWR_PVDLevel_4V4 - PVD detection level set to 4.4V
*
* @return none
*/

View file

@ -4,8 +4,10 @@
* Version : V1.0.0
* Date : 2022/08/08
* Description : This file provides all the RCC firmware functions.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* SPDX-License-Identifier: Apache-2.0
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#include <ch32v00x_rcc.h>
@ -86,7 +88,8 @@ void RCC_DeInit(void)
* RCC_HSE_OFF - HSE oscillator OFF.
* RCC_HSE_ON - HSE oscillator ON.
* RCC_HSE_Bypass - HSE oscillator bypassed with external clock.
*
* Note-
* HSE can not be stopped if it is used directly or through the PLL as system clock.
* @return none
*/
void RCC_HSEConfig(uint32_t RCC_HSE)
@ -114,8 +117,8 @@ void RCC_HSEConfig(uint32_t RCC_HSE)
*
* @brief Waits for HSE start-up.
*
* @return SUCCESS - HSE oscillator is stable and ready to use.
* ERROR - HSE oscillator not yet ready.
* @return READY - HSE oscillator is stable and ready to use.
* NoREADY - HSE oscillator not yet ready.
*/
ErrorStatus RCC_WaitForHSEStartUp(void)
{
@ -196,13 +199,13 @@ void RCC_HSICmd(FunctionalState NewState)
*
* @return none
*/
void RCC_PLLConfig(uint32_t RCC_PLLSource, uint32_t RCC_PLLMul)
void RCC_PLLConfig(uint32_t RCC_PLLSource)
{
uint32_t tmpreg = 0;
tmpreg = RCC->CFGR0;
tmpreg &= CFGR0_PLL_Mask;
tmpreg |= RCC_PLLSource | RCC_PLLMul;
tmpreg |= RCC_PLLSource;
RCC->CFGR0 = tmpreg;
}
@ -210,6 +213,8 @@ void RCC_PLLConfig(uint32_t RCC_PLLSource, uint32_t RCC_PLLMul)
* @fn RCC_PLLCmd
*
* @brief Enables or disables the PLL.
* Note-The PLL can not be disabled if it is used as system clock.
*
*
* @param NewState - ENABLE or DISABLE.
*
@ -358,6 +363,8 @@ void RCC_ADCCLKConfig(uint32_t RCC_PCLK2)
* @fn RCC_LSICmd
*
* @brief Enables or disables the Internal Low Speed oscillator (LSI).
* Note-
* LSI can not be disabled if the IWDG is running.
*
* @param NewState - ENABLE or DISABLE.
*
@ -437,6 +444,7 @@ void RCC_GetClocksFreq(RCC_ClocksTypeDef *RCC_Clocks)
RCC_Clocks->PCLK2_Frequency = RCC_Clocks->HCLK_Frequency;
tmp = RCC->CFGR0 & CFGR0_ADCPRE_Set_Mask;
tmp = tmp >> 11;
tmp = ((tmp & 0x18) >> 3) | ((tmp & 0x7) << 2);
if((tmp & 0x13) >= 4)
{
@ -455,6 +463,8 @@ void RCC_GetClocksFreq(RCC_ClocksTypeDef *RCC_Clocks)
* @param RCC_AHBPeriph - specifies the AHB peripheral to gates its clock.
* RCC_AHBPeriph_DMA1.
* RCC_AHBPeriph_SRAM.
* Note-
* SRAM clock can be disabled only during sleep mode.
* NewState: ENABLE or DISABLE.
*
* @return none
@ -677,7 +687,9 @@ FlagStatus RCC_GetFlagStatus(uint8_t RCC_FLAG)
* @fn RCC_ClearFlag
*
* @brief Clears the RCC reset flags.
*
* Note-
* The reset flags are: RCC_FLAG_PINRST, RCC_FLAG_PORRST, RCC_FLAG_SFTRST,
* RCC_FLAG_IWDGRST, RCC_FLAG_WWDGRST, RCC_FLAG_LPWRRST
* @return none
*/
void RCC_ClearFlag(void)

View file

@ -4,9 +4,11 @@
* Version : V1.0.0
* Date : 2022/08/08
* Description : This file provides all the SPI firmware functions.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* SPDX-License-Identifier: Apache-2.0
*********************************************************************************/
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#include <ch32v00x_rcc.h>
#include <ch32v00x_spi.h>
@ -93,6 +95,7 @@ void SPI_StructInit(SPI_InitTypeDef *SPI_InitStruct)
SPI_InitStruct->SPI_CPOL = SPI_CPOL_Low;
SPI_InitStruct->SPI_CPHA = SPI_CPHA_1Edge;
SPI_InitStruct->SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;
/*"SPI_FirstBit_LSB" not support SPI slave mode*/
SPI_InitStruct->SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStruct->SPI_CRCPolynomial = 7;
}
@ -422,7 +425,15 @@ FlagStatus SPI_I2S_GetFlagStatus(SPI_TypeDef *SPIx, uint16_t SPI_I2S_FLAG)
* - 1 in SPI mode.
* SPI_I2S_FLAG - specifies the SPI flag to clear.
* SPI_FLAG_CRCERR - CRC Error flag.
*
* Note-
* - OVR (OverRun error) flag is cleared by software sequence: a read
* operation to SPI_DATAR register (SPI_I2S_ReceiveData()) followed by a read
* operation to SPI_STATR register (SPI_I2S_GetFlagStatus()).
* - UDR (UnderRun error) flag is cleared by a read operation to
* SPI_STATR register (SPI_I2S_GetFlagStatus()).
* - MODF (Mode Fault) flag is cleared by software sequence: a read/write
* operation to SPI_STATR register (SPI_I2S_GetFlagStatus()) followed by a
* write operation to SPI_CTLR1 register (SPI_Cmd() to enable the SPI).
* @return FlagStatus: SET or RESET.
*/
void SPI_I2S_ClearFlag(SPI_TypeDef *SPIx, uint16_t SPI_I2S_FLAG)
@ -478,7 +489,16 @@ ITStatus SPI_I2S_GetITStatus(SPI_TypeDef *SPIx, uint8_t SPI_I2S_IT)
* - 1 in SPI mode.
* SPI_I2S_IT - specifies the SPI interrupt pending bit to clear.
* SPI_IT_CRCERR - CRC Error interrupt.
*
* Note-
* - OVR (OverRun Error) interrupt pending bit is cleared by software
* sequence: a read operation to SPI_DATAR register (SPI_I2S_ReceiveData())
* followed by a read operation to SPI_STATR register (SPI_I2S_GetITStatus()).
* - UDR (UnderRun Error) interrupt pending bit is cleared by a read
* operation to SPI_STATR register (SPI_I2S_GetITStatus()).
* - MODF (Mode Fault) interrupt pending bit is cleared by software sequence:
* a read/write operation to SPI_STATR register (SPI_I2S_GetITStatus())
* followed by a write operation to SPI_CTLR1 register (SPI_Cmd() to enable
* the SPI).
* @return none
*/
void SPI_I2S_ClearITPendingBit(SPI_TypeDef *SPIx, uint8_t SPI_I2S_IT)

View file

@ -4,8 +4,10 @@
* Version : V1.0.0
* Date : 2022/08/08
* Description : This file provides all the TIM firmware functions.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* SPDX-License-Identifier: Apache-2.0
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#include <ch32v00x_rcc.h>
#include <ch32v00x_tim.h>
@ -1054,7 +1056,7 @@ void TIM_SelectCCDMA(TIM_TypeDef *TIMx, FunctionalState NewState)
* @fn TIM_CCPreloadControl
*
* @brief DSets or Resets the TIM peripheral Capture Compare Preload Control bit.
* reset values (Affects also the I2Ss).
* reset values .
* @param TIMx - where x can be 1 to 2 to select the TIM peripheral.
* NewState - ENABLE or DISABLE.
*
@ -1962,13 +1964,13 @@ uint16_t TIM_GetCapture2(TIM_TypeDef *TIMx)
}
/*********************************************************************
* @fn TIM_GetCapture2
* @fn TIM_GetCapture3
*
* @brief Gets the TIMx Input Capture 2 value.
* @brief Gets the TIMx Input Capture 3 value.
*
* @param TIMx - where x can be 1 to 2 select the TIM peripheral.
*
* @return TIMx->CH2CVR - Capture Compare 2 Register value.
* @return TIMx->CH3CVR - Capture Compare 3 Register value.
*/
uint16_t TIM_GetCapture3(TIM_TypeDef *TIMx)
{
@ -2341,3 +2343,25 @@ static void TI4_Config(TIM_TypeDef *TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_
TIMx->CHCTLR2 = tmpccmr2;
TIMx->CCER = tmpccer;
}
/*********************************************************************
* @fn TIM_IndicateCaptureLevelCmd
*
* @brief Enables or disables the TIMx capture level indication.
*
* @param TIMx - where x can be 1 to 2 select the TIM peripheral.
* NewState - ENABLE or DISABLE.
*
* @return none
*/
void TIM_IndicateCaptureLevelCmd(TIM_TypeDef *TIMx, FunctionalState NewState)
{
if(NewState)
{
TIMx->CTLR1 |= (1<<15);
}
else{
TIMx->CTLR1 &= ~(1<<15);
}
}

View file

@ -4,8 +4,10 @@
* Version : V1.0.0
* Date : 2022/08/08
* Description : This file provides all the USART firmware functions.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* SPDX-License-Identifier: Apache-2.0
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#include <ch32v00x_rcc.h>
#include <ch32v00x_usart.h>
@ -217,7 +219,7 @@ void USART_ClockStructInit(USART_ClockInitTypeDef *USART_ClockInitStruct)
* @fn USART_Cmd
*
* @brief Enables or disables the specified USART peripheral.
* reset values (Affects also the I2Ss).
* reset values .
*
* @param USARTx - where x can be 1 to select the USART peripheral.
* NewState: ENABLE or DISABLE.
@ -240,11 +242,10 @@ void USART_Cmd(USART_TypeDef *USARTx, FunctionalState NewState)
* @fn USART_ITConfig
*
* @brief Enables or disables the specified USART interrupts.
* reset values (Affects also the I2Ss).
* reset values .
*
* @param USARTx - where x can be to select the USART peripheral.
* USART_IT - specifies the USART interrupt sources to be enabled or disabled.
* USART_IT_CTS - CTS change interrupt.
* USART_IT_LBD - LIN Break detection interrupt.
* USART_IT_TXE - Transmit Data Register empty interrupt.
* USART_IT_TC - Transmission complete interrupt.
@ -261,9 +262,6 @@ void USART_ITConfig(USART_TypeDef *USARTx, uint16_t USART_IT, FunctionalState Ne
uint32_t usartreg = 0x00, itpos = 0x00, itmask = 0x00;
uint32_t usartxbase = 0x00;
if(USART_IT == USART_IT_CTS)
{
}
usartxbase = (uint32_t)USARTx;
usartreg = (((uint8_t)USART_IT) >> 0x05);
@ -562,7 +560,9 @@ void USART_HalfDuplexCmd(USART_TypeDef *USARTx, FunctionalState NewState)
*
* @param USARTx - where x can be 1 to select the USART peripheral.
* NewState - ENABLE or DISABLE.
*
* Note-
* This function has to be called before calling USART_Init()
* function in order to have correct baudrate Divider value.
* @return none
*/
void USART_OverSampling8Cmd(USART_TypeDef *USARTx, FunctionalState NewState)
@ -646,7 +646,6 @@ void USART_IrDACmd(USART_TypeDef *USARTx, FunctionalState NewState)
*
* @param USARTx - where x can be 1 to select the USART peripheral.
* USART_FLAG - specifies the flag to check.
* USART_FLAG_CTS - CTS Change flag.
* USART_FLAG_LBD - LIN Break detection flag.
* USART_FLAG_TXE - Transmit data register empty flag.
* USART_FLAG_TC - Transmission Complete flag.
@ -663,10 +662,6 @@ FlagStatus USART_GetFlagStatus(USART_TypeDef *USARTx, uint16_t USART_FLAG)
{
FlagStatus bitstatus = RESET;
if(USART_FLAG == USART_FLAG_CTS)
{
}
if((USARTx->STATR & USART_FLAG) != (uint16_t)RESET)
{
bitstatus = SET;
@ -685,18 +680,25 @@ FlagStatus USART_GetFlagStatus(USART_TypeDef *USARTx, uint16_t USART_FLAG)
*
* @param USARTx - where x can be 1 to select the USART peripheral.
* USART_FLAG - specifies the flag to clear.
* USART_FLAG_CTS - CTS Change flag.
* USART_FLAG_LBD - LIN Break detection flag.
* USART_FLAG_TC - Transmission Complete flag.
* USART_FLAG_RXNE - Receive data register not empty flag.
*
* Note-
* - PE (Parity error), FE (Framing error), NE (Noise error), ORE (OverRun
* error) and IDLE (Idle line detected) flags are cleared by software
* sequence: a read operation to USART_STATR register (USART_GetFlagStatus())
* followed by a read operation to USART_DATAR register (USART_ReceiveData()).
* - RXNE flag can be also cleared by a read to the USART_DATAR register
* (USART_ReceiveData()).
* - TC flag can be also cleared by software sequence: a read operation to
* USART_STATR register (USART_GetFlagStatus()) followed by a write operation
* to USART_DATAR register (USART_SendData()).
* - TXE flag is cleared only by a write to the USART_DATAR register
* (USART_SendData()).
* @return none
*/
void USART_ClearFlag(USART_TypeDef *USARTx, uint16_t USART_FLAG)
{
if((USART_FLAG & USART_FLAG_CTS) == USART_FLAG_CTS)
{
}
USARTx->STATR = (uint16_t)~USART_FLAG;
}
@ -708,7 +710,6 @@ void USART_ClearFlag(USART_TypeDef *USARTx, uint16_t USART_FLAG)
*
* @param USARTx - where x can be 1 to select the USART peripheral.
* USART_IT - specifies the USART interrupt source to check.
* USART_IT_CTS - CTS change interrupt.
* USART_IT_LBD - LIN Break detection interrupt.
* USART_IT_TXE - Tansmit Data Register empty interrupt.
* USART_IT_TC - Transmission complete interrupt.
@ -727,10 +728,6 @@ ITStatus USART_GetITStatus(USART_TypeDef *USARTx, uint16_t USART_IT)
uint32_t bitpos = 0x00, itmask = 0x00, usartreg = 0x00;
ITStatus bitstatus = RESET;
if(USART_IT == USART_IT_CTS)
{
}
usartreg = (((uint8_t)USART_IT) >> 0x05);
itmask = USART_IT & IT_Mask;
itmask = (uint32_t)0x01 << itmask;
@ -771,21 +768,28 @@ ITStatus USART_GetITStatus(USART_TypeDef *USARTx, uint16_t USART_IT)
*
* @param USARTx - where x can be 1 to select the USART peripheral.
* USART_IT - specifies the interrupt pending bit to clear.
* USART_IT_CTS - CTS change interrupt.
* USART_IT_LBD - LIN Break detection interrupt.
* USART_IT_TC - Transmission complete interrupt.
* USART_IT_RXNE - Receive Data register not empty interrupt.
*
* Note-
* - PE (Parity error), FE (Framing error), NE (Noise error), ORE (OverRun
* error) and IDLE (Idle line detected) pending bits are cleared by
* software sequence: a read operation to USART_STATR register
* (USART_GetITStatus()) followed by a read operation to USART_DATAR register
* (USART_ReceiveData()).
* - RXNE pending bit can be also cleared by a read to the USART_DATAR register
* (USART_ReceiveData()).
* - TC pending bit can be also cleared by software sequence: a read
* operation to USART_STATR register (USART_GetITStatus()) followed by a write
* operation to USART_DATAR register (USART_SendData()).
* - TXE pending bit is cleared only by a write to the USART_DATAR register
* (USART_SendData()).
* @return none
*/
void USART_ClearITPendingBit(USART_TypeDef *USARTx, uint16_t USART_IT)
{
uint16_t bitpos = 0x00, itmask = 0x00;
if(USART_IT == USART_IT_CTS)
{
}
bitpos = USART_IT >> 0x08;
itmask = ((uint16_t)0x01 << (uint16_t)bitpos);
USARTx->STATR = (uint16_t)~itmask;

View file

@ -4,9 +4,11 @@
* Version : V1.0.0
* Date : 2022/08/08
* Description : This file provides all the WWDG firmware functions.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* SPDX-License-Identifier: Apache-2.0
**********************************************************************************/
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#include <ch32v00x_rcc.h>
#include <ch32v00x_wwdg.h>

View file

@ -4,8 +4,10 @@
;* Version : V1.0.0
;* Date : 2022/08/08
;* Description : vector table for eclipse toolchain.
;*********************************************************************************
;* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
;* SPDX-License-Identifier: Apache-2.0
;* Attention: This software (modified or not) and binary are used for
;* microcontroller manufactured by Nanjing Qinheng Microelectronics.
;*******************************************************************************/
.section .init, "ax", @progbits