Skip to content

Commit c1fda54

Browse files
authored
Board definition for CH32X033F8P6 TSSOP20 #171
At the current stage it works for me. Have fun! Info below is also in the readme of the board definition directory. +------v------+ MISO/A6 D6~ 1-+PA6 PA5+-20 D5 SCK/A5 MOSI/A8/TX4 D7 2-+PA7=PB0 PA4+-19 D4~ CS/A4 A9/RX4 D8 3-+PB1 PC19+-18 D17 SWCLK /RST D9 4-+PB7 PA3+-17 D3~ RX2/A3* USBDM D10 5-+PC16=PC11 PA2+-16 D2~ TX2/A2 USBDP D11 6-+PC17=PC10 PA1+-15 D1~ A1 GND 7-+VSS PA0+-14 D0~ A0 SWDIO D16 8-+PC18 PC3+-13 D15~ A13 VCC 9-+VDD PA10+-12 D14 SCL/TX1 D12 10-+PA9 PA11+-11 D13 SDA/RX1 +-------------+ *A3, VREF and hardware I2C don't work on CH32X033F8P6 0-series (lot number with the penultimate bit 5 being 0). Tested features digitalWrite()/digitalRead() - can use Arduino pin numbers or PAx notation. analogWrite() - 12-bit resolution, pins marked with ~ in pinout above. analogRead() - very stable 12-bit resolution, but issues with A3/A0/PADC_VREF Serial.print() - Tested 115200 bps on Serial2 (PA2/PA3) and Serial1 (PA10/PA11), as set in variant_CH32X033F8P6.h EEPROM library - may need improvement (updated to support 122 bytes). Pin PB7 (Arduino pin 9) can be configured as hardware reset /RST using WCH Link Utility. (See issue Hardware reset pin doesn't work on CH32X033 or CH32X035 #123) Known issues/limitations Pins PA7/PB0, PC16/PC11 and PC17/PC10 cannot be used for output. Any signal on A0 seems to show on other ADC pins when disconnected. A3, PADC_VREF and I2C don't work on CH32X033F8P6 0-series (lot number with the penultimate bit 5 being 0). To counter missing I2C the Software_I2C library by Seeed Studio is a good alternative, although it needs some changes to improve compatibility in I2C scanning. openwch/arduino_core_ch32#171
1 parent 8f09be2 commit c1fda54

File tree

1 file changed

+202
-0
lines changed

1 file changed

+202
-0
lines changed
Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
/*
2+
*******************************************************************************
3+
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
4+
* All rights reserved.
5+
*
6+
* This software component is licensed by WCH under BSD 3-Clause license,
7+
* the "License"; You may not use this file except in compliance with the
8+
* License. You may obtain a copy of the License at:
9+
* opensource.org/licenses/BSD-3-Clause
10+
*
11+
*******************************************************************************
12+
*/
13+
#pragma once
14+
15+
/* ENABLE Peripherals */
16+
#ifndef IDE_MENU_PERIPHERALS // defined when peripherals are enabled/disabled via the IDE menu
17+
#define ADC_MODULE_ENABLED
18+
#define UART_MODULE_ENABLED
19+
#define SPI_MODULE_ENABLED
20+
#define I2C_MODULE_ENABLED
21+
#define TIM_MODULE_ENABLED
22+
#endif
23+
24+
/* CH32VX033F8P6 Pins */
25+
#define PA0 PIN_A0
26+
#define PA1 PIN_A1
27+
#define PA2 PIN_A2
28+
#define PA3 PIN_A3
29+
#define PA4 PIN_A4
30+
#define PA5 PIN_A5
31+
#define PA6 PIN_A6
32+
#define PA7 PIN_A8
33+
#define PB0 PIN_A8
34+
#define PB1 PIN_A9
35+
#define PB7 9 // can be configured as RST
36+
#define PC16 10
37+
#define PC17 11
38+
#define PA9 12
39+
#define PA11 13
40+
#define PA10 14
41+
#define PC3 15 // PIN_A13
42+
#define PC18 16
43+
#define PC19 17
44+
45+
// Alternate pins number TODO
46+
#define PA0_ALT1 (PA0 | ALT1)
47+
#define PA1_ALT1 (PA1 | ALT1)
48+
#define PA2_ALT1 (PA2 | ALT1)
49+
#define PA3_ALT1 (PA3 | ALT1)
50+
#define PA4_ALT1 (PA4 | ALT1)
51+
#define PA5_ALT1 (PA5 | ALT1)
52+
#define PA6_ALT1 (PA6 | ALT1)
53+
#define PA7_ALT1 (PA7 | ALT1)
54+
#define PB0_ALT1 (PB0 | ALT1)
55+
#define PB1_ALT1 (PB1 | ALT1)
56+
#define PC0_ALT1 (PC0 | ALT1)
57+
#define PC3_ALT1 (PC3 | ALT1)
58+
59+
60+
61+
#define NUM_DIGITAL_PINS 18 // 27
62+
#define NUM_ANALOG_INPUTS 14 // 14 to allow PIN_13/A13 definition for PC3 (no A10, A11, A12 on X033F8P6)
63+
#define ADC_RESOLUTION 12
64+
65+
66+
// On-board LED pin number
67+
#ifndef LED_BUILTIN
68+
#define LED_BUILTIN PNUM_NOT_DEFINED
69+
#endif
70+
71+
72+
73+
// On-board user button
74+
#ifndef USER_BTN
75+
#define USER_BTN PNUM_NOT_DEFINED
76+
#endif
77+
78+
// SPI definitions
79+
#ifndef PIN_SPI_SS
80+
#define PIN_SPI_SS PA4
81+
#endif
82+
#ifndef PIN_SPI_MOSI
83+
#define PIN_SPI_MOSI PA7
84+
#endif
85+
#ifndef PIN_SPI_MISO
86+
#define PIN_SPI_MISO PA6
87+
#endif
88+
#ifndef PIN_SPI_SCK
89+
#define PIN_SPI_SCK PA5
90+
#endif
91+
92+
// I2C definitions
93+
#ifndef PIN_WIRE_SDA
94+
#define PIN_WIRE_SDA PC17
95+
#endif
96+
#ifndef PIN_WIRE_SCL
97+
#define PIN_WIRE_SCL PC16
98+
#endif
99+
100+
// Timer Definitions
101+
#ifndef TIMER_TONE
102+
#define TIMER_TONE TIM3
103+
#endif
104+
#ifndef TIMER_SERVO
105+
#define TIMER_SERVO TIM2
106+
#endif
107+
108+
109+
// UART Definitions
110+
#ifndef SERIAL_UART_INSTANCES
111+
// Define the number of UART instances that can be used.
112+
// For CH32X033F8P6 SSOP20 the supported maximum is currently two.
113+
// These are UART1 and UART2 on pins PA10=TX1_1, PA11=RX1_1 and on PA2=TX2, PA3=RX2
114+
// (two instances will cost 132/136 bytes more flash/ram than one instance)
115+
#define SERIAL_UART_INSTANCES 2 // select 1 or 2 instances
116+
#endif
117+
118+
#if (SERIAL_UART_INSTANCES==1)
119+
// If using only one UART inactance, select which to use: UART1 or UART2
120+
#ifndef SERIAL_UART_INSTANCE
121+
// #define SERIAL_UART_INSTANCE 1 // UART1: PA10=TX1_1, PA11=RX1_1
122+
#define SERIAL_UART_INSTANCE 2 // UART2: PA2=TX2, PA3=RX2
123+
#endif
124+
#else
125+
// multiple instances, max 2 for CH32X033F8P SSOP20
126+
// NOTE: do not define SERIAL_UART_INSTANCE when using multiple instances!
127+
#undef SERIAL_UART_INSTANCE
128+
#define ENABLE_HWSERIAL1 1
129+
#define ENABLE_HWSERIAL2 1
130+
#endif
131+
132+
// Default pin used for generic 'Serial' instance
133+
// Mandatory for Firmata
134+
// For CH32X033F8P6 serial pins RX2=PA3/TX2=PA2 or alternative RX1_1=PA11/TX1_1=PA10
135+
136+
// Pins used for Serial2 instance (used by HardwareSerial constructor)
137+
#if (SERIAL_UART_INSTANCES==1)
138+
// one single UART instance, specify which oins to be used
139+
#if (SERIAL_UART_INSTANCE==1)
140+
// Use UART1 alternative pins RX1_1/TX1_1 (PA11/PA10)
141+
#ifndef PIN_SERIAL_RX
142+
#define PIN_SERIAL_RX PA11
143+
#endif
144+
#ifndef PIN_SERIAL_TX
145+
#define PIN_SERIAL_TX PA10
146+
#endif
147+
#elif (SERIAL_UART_INSTANCE==2)
148+
// Use UART2 RX2/TX2 (PA3/PA2)
149+
#ifndef PIN_SERIAL_RX
150+
#define PIN_SERIAL_RX PA3
151+
#endif
152+
#ifndef PIN_SERIAL_TX
153+
#define PIN_SERIAL_TX PA2
154+
#endif
155+
#endif
156+
#else
157+
// multiple instances. Define each pin for each UART (Serial=Serial2)
158+
#define Serial Serial2 // specify which UART to use as 'Serial'
159+
#ifndef PIN_SERIAL_RX
160+
#define PIN_SERIAL_RX PA11 // supported: PA3=RX2, alternative PA11=RX1_1 (X035: PB11)
161+
#endif
162+
#ifndef PIN_SERIAL_TX
163+
#define PIN_SERIAL_TX PA10 // supported: PA2=TX2, alternative PA10=TX1_1 (X035: PB10)
164+
#endif
165+
#ifndef PIN_SERIAL_RX2
166+
#define PIN_SERIAL_RX2 PA3 // supported: PA3=RX2, alternative PA11=RX1_1 (X035: PB11)
167+
#endif
168+
#ifndef PIN_SERIAL_TX2
169+
#define PIN_SERIAL_TX2 PA2 // supported: PA2=TX2, alternative PA10=TX1_1 (X035: PB10)
170+
#endif
171+
#endif
172+
173+
174+
175+
/*----------------------------------------------------------------------------
176+
* Arduino objects - C++ only
177+
*----------------------------------------------------------------------------*/
178+
179+
#ifdef __cplusplus
180+
// These serial port names are intended to allow libraries and architecture-neutral
181+
// sketches to automatically default to the correct port name for a particular type
182+
// of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
183+
// the first hardware serial port whose RX/TX pins are not dedicated to another use.
184+
//
185+
// SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor
186+
//
187+
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
188+
//
189+
// SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
190+
//
191+
// SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins.
192+
//
193+
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
194+
// pins are NOT connected to anything by default.
195+
#ifndef SERIAL_PORT_MONITOR
196+
#define SERIAL_PORT_MONITOR Serial
197+
#endif
198+
#ifndef SERIAL_PORT_HARDWARE
199+
#define SERIAL_PORT_HARDWARE Serial
200+
#endif
201+
#endif
202+

0 commit comments

Comments
 (0)