ch32v003fun.h 714.09 KiB
// This contains a copy of ch32v00x.h and core_riscv.h ch32v00x_conf.h and other misc functions See copyright notice at end.
#ifndef __CH32V00x_H
#define __CH32V00x_H
#include "funconfig.h"
/*****************************************************************************
CH32V003 BASICS
1. Be sure to see configuration section below!
2. Backend Initialization
SystemInit();
3. Arduino-like I/O
funGpioInitAll();
funPinMode( PA2, GPIO_CFGLR_OUT_10Mhz_PP );
funDigitalWrite( PA2, FUN_HIGH );
funDigitalWrite( PA2, FUN_HIGH );
4. Delays
Delay_Us(n)
Delay_Ms(n)
DelaySysTick( uint32_t n );
5. printf
printf, _write may be semihosted, or printed to UART.
poll_input, handle_debug_input may be used with semihsoting.
For UART printf, on:
CH32V003, Port D5, 115200 8n1
CH32V203, Port A9, 115200 8n1
Modifications can be made to SetupUart, or your own version as desired.
*/
/*****************************************************************************
CH32V003 Fun Configs:
#define FUNCONF_USE_PLL 1 // Use built-in 2x PLL
#define FUNCONF_USE_HSI 1 // Use HSI Internal Oscillator
#define FUNCONF_USE_HSE 0 // Use External Oscillator
#define FUNCONF_HSITRIM 0x10 // Use factory calibration on HSI Trim.
#define FUNCONF_SYSTEM_CORE_CLOCK 48000000 // Computed Clock in Hz (Default only for 003, other chips have other defaults)
#define FUNCONF_HSE_BYPASS 0 // Use HSE Bypass feature (for oscillator input)
#define FUNCONF_USE_CLK_SEC 1 // Use clock security system, enabled by default
#define FUNCONF_USE_DEBUGPRINTF 1
#define FUNCONF_USE_UARTPRINTF 0
#define FUNCONF_NULL_PRINTF 0 // Have printf but direct it "nowhere"
#define FUNCONF_SYSTICK_USE_HCLK 0 // Should systick be at 48 MHz or 6MHz?
#define FUNCONF_TINYVECTOR 0 // If enabled, Does not allow normal interrupts.
#define FUNCONF_UART_PRINTF_BAUD 115200 // Only used if FUNCONF_USE_UARTPRINTF is set.
#define FUNCONF_DEBUGPRINTF_TIMEOUT 160000 // Arbitrary time units
#define FUNCONF_ENABLE_HPE 1 // Enable hardware interrupt stack. Very good on QingKeV4, i.e. x035, v10x, v20x, v30x, but questionable on 003.
#define FUNCONF_USE_5V_VDD 0 // Enable this if you plan to use your part at 5V - affects USB and PD configration on the x035.
*/
// Sanity check for when porting old code.
#if defined(CH32V10x) || defined(CH32V20x) || defined(CH32V30x) || defined(CH32X03x)
#if defined(CH32V003)
#error Cannot define CH32V003 and another arch.
#endif
#endif
#if !defined(FUNCONF_USE_DEBUGPRINTF) && !defined(FUNCONF_USE_UARTPRINTF)
#define FUNCONF_USE_DEBUGPRINTF 1