Code Monkey home page Code Monkey logo

arduino_core_ch32's People

Contributors

aselectroworks avatar deqingsun avatar hathach avatar kenjutsugh avatar maxint-rd avatar michpro avatar ngohungcuong avatar redstonee avatar theaudiobible avatar tianpeilee avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

arduino_core_ch32's Issues

CH32V30X SPI unable to set speed through SPI.setClockDivider

I have some issue setting SPI speed with the SPI driver. The code is simply
SPI.setDataMode(SPI_MODE0); SPI.setBitOrder(MSBFIRST); SPI.setClockDivider(SPI_CLOCK_DIV128); SPI.begin();

And I tried SPI_CLOCK_DIV32, SPI_CLOCK_DIV64, SPI_CLOCK_DIV128, all of them give a 3MHz SPI frequency. This is not too critical to me, but I would like to figure out what is wrong. It seems the driver has some code that should handle this.

No Linux/Ubuntu riscv-none-embed-gcc compiler available

I tried adding this core to my v1.8.19 Arduino IDE board manager on my Ubuntu 22.04/"Jammy Jellyfish" x86 Linux and got the error:
Tool riscv-none-embed-gcc is not available for your operating system.

I also tried v2.2.1 of the Arduino IDE and got a similar error:
Downloading packages
Failed to install platform: WCH:ch32v.
Error: 13 INTERNAL: Error downloading tool WCH:[email protected]: no versions available for the current OS, try contacting [email protected]

Is this core only available for Windows? Also is there anything I can do to help get this OS supported for arduino_core_ch32?

flashing Blink example to CH32V003F4P6-EVT fails

Hi,

I tried flashing my CH32V003F4P6-EVT with the blink example.

  1. add board URL to Arduino IDE
  2. install "CH32 EVT Boards Support" (searching for WCH didn't work)
  3. load blink example
  4. connect WCH-LinkE to EVT (VCC to 3.3V, Gnd to Gnd, PD1 to SWDIO)
    WCH32V003EVT_connection
  5. connect WCH-LinkE to PC
  6. setup board "CH32V00x"
    image
  7. select port, keep anything else as it is
    image
  8. upload

i got this error
image

Once I get it running I would like to compose a "getting started" documentation

Linux support? "Failed to install platform: WCH:ch32v.... no versions available for the current OS"

Cool project. Arduino support is very interesting, in addition to MounRiver.

No support for Linux at the moment, though?
"Failed to install platform: WCH:ch32v.
Error: 13 INTERNAL: Error downloading tool WCH:[email protected]: no versions available for the current OS, try contacting [email protected]"

I know the tools are available for Linux, as they're bundled with MounRiver. Are there plans to add support for Linux to this package too?

ADC Value not updating

I used Serial monitor to print ADC values that must be coming to be floating values but there was no values and it only showed zero

this is the code used by me , plz help

uint16_t adc = 0;
#define ADC A2
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(ADC,INPUT_ANALOG);
Serial.println("Ready");

}

void loop() {
// put your main code here, to run repeatedly:
adc = analogRead(ADC);
Serial.print("ADC value is :");
Serial.println(adc);
delay(500);

}

and same for PWM not working properly.

How to use PWM ?

How to use PWM ?

i try analogWrite() not work

#include <Arduino.h>

/* PC1 as blinky LED, change here as needed */
#define LED PD2

void setup() {
    pinMode(LED, OUTPUT);
    analogWriteFrequency(20000);
}

void loop() {
//    digitalWrite(LED, HIGH);
//    delay(500);
//    digitalWrite(LED, LOW);
//    delay(500);

    analogWrite(LED, 100);
}

Is there a plan for for firmware upload via CDC 'on the MCUs supporting USB)?

So, in arduino the "traditional" firmware upload method is via UART / CDC (when the MCU provides native USB).

On older WCH MCUs, such as CH5xx, the rom bootloader does support this, i assume it is also supported on newer MCUs such as CH32X035.
To be convenient upload should be automatic (no user action on tact switch).
If done via UART, no problem, we can use the control lines of the USB-UART bridge to toggle reset and BOOT, on CDC it should be done the baudrate change cdc command, using an odd/unused value such as 4800. When the host sets baudrate to 4800 the USB stack writes a persistant flag (usually in RTC memory) and resets the MCU, after reset the bootloader see the flag and stay in upload mode rather than jumping to the user application, waiting for datas.

I have done that some years ago on various STM32 for a client project and it was not particularly hard to implement, is there a plan to add this mechanism to the WCH core? It would be valuable.

CH32V003 setting I2C to SCL:PC2 SDA:PC6 leads to error "ERROR: at least one I2C pin has no peripheral"

So on CH32V003, i set I2C to

#define SCL     PC2
#define SDA     PC6

And i get the error

ERROR: at least one I2C pin has no peripheral

I tried to set it by 3 differnt way, as argument of the contructor
TwoWire i2c = TwoWire(PC6,PC2); //sda scl

as argument of the init function

TwoWire i2c = TwoWire();

void setup() {
  i2c.begin(PC6,PC2);

and as default pins in variant_CH32V003F4.h

#ifndef PIN_WIRE_SDA
  #define PIN_WIRE_SDA          PC6 
#endif
#ifndef PIN_WIRE_SCL
  #define PIN_WIRE_SCL          PC2
#endif

But i still get this error.
As far as i know the cause would be that PC6 cannot be mapped to SDA, however, when i check the alternatives functions of PC6 i can clearly see SDA is available so what is the problem?

image

error: 'tone' was not declared in this scope

I tried compiling the tonemelody example from the arduino examples sketchbook so i can play melodies from my ch32v003 and i got these errors.
I have selected CH32V00x in the board selecting options. I have not changed any configuration myself.

C:\Users\etore\AppData\Local\Temp\.arduinoIDE-unsaved202389-4580-s8bhqs.pch6l\toneMelody\toneMelody.ino: In function 'void setup()':
C:\Users\etore\AppData\Local\Temp\.arduinoIDE-unsaved202389-4580-s8bhqs.pch6l\toneMelody\toneMelody.ino:37:5: error: 'tone' was not declared in this scope
     tone(8, melody[thisNote], noteDuration);
     ^~~~
C:\Users\etore\AppData\Local\Temp\.arduinoIDE-unsaved202389-4580-s8bhqs.pch6l\toneMelody\toneMelody.ino:37:5: note: suggested alternative: 'tanh'
     tone(8, melody[thisNote], noteDuration);
     ^~~~
     tanh
C:\Users\etore\AppData\Local\Temp\.arduinoIDE-unsaved202389-4580-s8bhqs.pch6l\toneMelody\toneMelody.ino:44:5: error: 'noTone' was not declared in this scope
     noTone(8);
     ^~~~~~

exit status 1

Compilation error: 'tone' was not declared in this scope

I tried installing external tone library by Brett Hagman but it said it wasnt supported and compiling also failed due to some timers not being declared in scope.

instruction on basic upload and serial support?

It seems that I have some trouble getting the most basic serial print "hello world" to work.

  1. The upload does not work out of the box. I have to use WCH-Link utility to upload manually.
  2. After the upload, the simplest Serial print also does not seem to work.

I have programmed CH32V307 using MounRiver studio quite a bit before and I had no trouble, It would be great to have some instruction to walk through the basics.

WCH-Link required for CH32V307VCT6?

I just received my CH32V307VCT6 development board, is the WCH-Link required to upload code? Both Arduino IDE and MounRiver Studio seem to require the WCH-Link programmer, I am not able to upload by USB.
When I booted the device in bootloader mode (hold BOOT0 while powering up), Windows was not able to automatically install the driver.

How to use other than TIM1_CH1 for PWM?

On CH32V203, I am trying to use pin A6 for pwm, need 4 pwm channels, so far has been able to use standard code on pin A8, tim1_CH1 only. How to have more PWM outputs.
I am trying the following code, but it does not work.

void TIM2_PWMOut_Init(u16 arr, u16 psc, u16 ccp)
{
  GPIO_InitTypeDef GPIO_InitStructure={0};
  TIM_OCInitTypeDef TIM_OCInitStructure={0};
  TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure={0};

  RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA | RCC_APB1Periph_TIM3, ENABLE );

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init( GPIOA, &GPIO_InitStructure );

  TIM_TimeBaseInitStructure.TIM_Period = arr;
  TIM_TimeBaseInitStructure.TIM_Prescaler = psc;
  TIM_TimeBaseInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
  TIM_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
  TIM_TimeBaseInit( TIM3, &TIM_TimeBaseInitStructure);

#if (PWM_MODE == PWM_MODE1)
  TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;

#elif (PWM_MODE == PWM_MODE2)
  TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;

#endif

  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
  TIM_OCInitStructure.TIM_Pulse = ccp;
  TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
  TIM_OC1Init( TIM3, &TIM_OCInitStructure );

  TIM_CtrlPWMOutputs(TIM3, ENABLE );
  TIM_OC1PreloadConfig( TIM3, TIM_OCPreload_Disable );
  TIM_ARRPreloadConfig( TIM3, ENABLE );
  TIM_Cmd( TIM3, ENABLE );
}

Add license information

Hello!

Could you please add information about the license of this repository — is it allowed to copy, change and use the code in any purpose?
It would be great to see any popular open source license.

SPIFlash example may return incorrect id

The code in the SPIFlash example:

//Read Flash ID
uint16_t readFlashID(void)
{
  uint16_t id;
  digitalWrite(chipSelectPin, LOW);
  SPI.transfer(W25X_ManufactDeviceID);
  SPI.transfer(0x00);
  SPI.transfer(0x00);
  SPI.transfer(0x00);
  id |= SPI.transfer(0xFF) << 8;
  id |= SPI.transfer(0xFF);
  digitalWrite(chipSelectPin, HIGH);
  return id;
}

does not initialize id to 0 so whatever value it has will be or'ed with the chip id. A correct code would be using:

uint16_t id = 0

or replace the first |= with a straight assignment.

I2C error twi.c:(.text.i2c_custom_init+0xc): undefined reference to `PinMap_I2C_SDA'

So, we use CH32X035 and there is an error when intilizing the I2C on the ports we use.
What is the problem?

#include <Wire.h>

#define SDA         PC16
#define SCL         PC19

TwoWire i2c = TwoWire(SDA,SCL);

void setup() {

  Serial.setTx(TX1);
  Serial.setRx(-1);
  Serial.begin(115200);
  Serial.println("system init");
  Serial.println(DBGMCU_GetDEVID());
  i2c.begin();
}

void loop() {
}

Latest core doesn't build without warnings

See below when warnings are actually enabled, for CH32X035G8U as selected board.

C:\Users\Max\.platformio\packages\framework-arduino-openwch-ch32\variants\CH32X035\CH32X035G8U\PeripheralPins.c:43:24: warning: excess elements in struct initializer
   {NC,        NP,   0, 0, 0}
                        ^
C:\Users\Max\.platformio\packages\framework-arduino-openwch-ch32\variants\CH32X035\CH32X035G8U\PeripheralPins.c:43:24: note: (near initialization for 'PinMap_ADC[12]')
C:\Users\Max\.platformio\packages\framework-arduino-openwch-ch32\variants\CH32X035\CH32X035G8U\PeripheralPins.c:43:27: warning: excess elements in struct initializer
   {NC,        NP,   0, 0, 0}
                           ^
C:\Users\Max\.platformio\packages\framework-arduino-openwch-ch32\variants\CH32X035\CH32X035G8U\PeripheralPins.c:43:27: note: (near initialization for 'PinMap_ADC[12]')
C:\Users\Max\.platformio\packages\framework-arduino-openwch-ch32\variants\CH32X035\CH32X035G8U\PeripheralPins.c:108:21: warning: excess elements in struct initializer
   {NC,   NP,     0, 0}
                     ^
C:\Users\Max\.platformio\packages\framework-arduino-openwch-ch32\variants\CH32X035\CH32X035G8U\PeripheralPins.c:108:21: note: (near initialization for 'PinMap_UART_TX[4]')
C:\Users\Max\.platformio\packages\framework-arduino-openwch-ch32\variants\CH32X035\CH32X035G8U\PeripheralPins.c:118:22: warning: excess elements in struct initializer
   {NC,    NP,     0, 0}
                      ^
C:\Users\Max\.platformio\packages\framework-arduino-openwch-ch32\variants\CH32X035\CH32X035G8U\PeripheralPins.c:118:22: note: (near initialization for 'PinMap_UART_RX[4]')
C:\Users\Max\.platformio\packages\framework-arduino-openwch-ch32\variants\CH32X035\CH32X035G8U\PeripheralPins.c:128:22: warning: excess elements in struct initializer
   {NC,    NP,     0, 0}
                      ^
C:\Users\Max\.platformio\packages\framework-arduino-openwch-ch32\variants\CH32X035\CH32X035G8U\PeripheralPins.c:128:22: note: (near initialization for 'PinMap_UART_RTS[4]')
C:\Users\Max\.platformio\packages\framework-arduino-openwch-ch32\variants\CH32X035\CH32X035G8U\PeripheralPins.c:138:22: warning: excess elements in struct initializer
   {NC,    NP,     0, 0}
                      ^
C:\Users\Max\.platformio\packages\framework-arduino-openwch-ch32\variants\CH32X035\CH32X035G8U\PeripheralPins.c:138:22: note: (near initialization for 'PinMap_UART_CTS[4]')
C:\Users\Max\.platformio\packages\framework-arduino-openwch-ch32\variants\CH32X035\CH32X035G8U\PeripheralPins.c:147:19: warning: excess elements in struct initializer
   {NC,   NP,   0, 0}
                   ^
C:\Users\Max\.platformio\packages\framework-arduino-openwch-ch32\variants\CH32X035\CH32X035G8U\PeripheralPins.c:147:19: note: (near initialization for 'PinMap_SPI_MOSI[1]')
C:\Users\Max\.platformio\packages\framework-arduino-openwch-ch32\variants\CH32X035\CH32X035G8U\PeripheralPins.c:154:19: warning: excess elements in struct initializer
   {NC,   NP,   0, 0}
                   ^
C:\Users\Max\.platformio\packages\framework-arduino-openwch-ch32\variants\CH32X035\CH32X035G8U\PeripheralPins.c:154:19: note: (near initialization for 'PinMap_SPI_MISO[1]')
C:\Users\Max\.platformio\packages\framework-arduino-openwch-ch32\variants\CH32X035\CH32X035G8U\PeripheralPins.c:161:19: warning: excess elements in struct initializer
   {NC,   NP,   0, 0}
                   ^
C:\Users\Max\.platformio\packages\framework-arduino-openwch-ch32\variants\CH32X035\CH32X035G8U\PeripheralPins.c:161:19: note: (near initialization for 'PinMap_SPI_SCLK[1]')
C:\Users\Max\.platformio\packages\framework-arduino-openwch-ch32\variants\CH32X035\CH32X035G8U\PeripheralPins.c:168:20: warning: excess elements in struct initializer
   {NC,    NP,   0, 0}
                    ^
C:\Users\Max\.platformio\packages\framework-arduino-openwch-ch32\variants\CH32X035\CH32X035G8U\PeripheralPins.c:168:20: note: (near initialization for 'PinMap_SPI_SSEL[1]')
Compiling .pio\build\genericCH32X035G8U6\FrameworkArduino\ch32\hw_config.c.o
Compiling .pio\build\genericCH32X035G8U6\FrameworkArduino\ch32\interrupt.cpp.o
Compiling .pio\build\genericCH32X035G8U6\FrameworkArduino\ch32\lib\ch32yyxx_adc.c.o
Compiling .pio\build\genericCH32X035G8U6\FrameworkArduino\ch32\lib\ch32yyxx_bkp.c.o
In file included from C:\Users\Max\.platformio\packages\framework-arduino-openwch-ch32\cores\arduino\ch32\clock.c:13:
C:\Users\Max\.platformio\packages\framework-arduino-openwch-ch32\cores\arduino\ch32\backup.h: In function 'resetBackupDomain':
C:\Users\Max\.platformio\packages\framework-arduino-openwch-ch32\cores\arduino\ch32\backup.h:44:3: warning: implicit declaration of function 'RCC_BackupResetCmd'; did you mean 'RCC_AHBPeriphResetCmd'? [-Wimplicit-function-declaration]
   RCC_BackupResetCmd(ENABLE);
   ^~~~~~~~~~~~~~~~~~
   RCC_AHBPeriphResetCmd
Compiling .pio\build\genericCH32X035G8U6\FrameworkArduino\ch32\lib\ch32yyxx_can.c.o
C:\Users\Max\.platformio\packages\framework-arduino-openwch-ch32\cores\arduino\ch32\analog.cpp: In function 'uint16_t adc_read_value(PinName, uint32_t)':
C:\Users\Max\.platformio\packages\framework-arduino-openwch-ch32\cores\arduino\ch32\analog.cpp:548:12: warning: unused variable 'bank' [-Wunused-variable]
   uint32_t bank = 0;
            ^~~~
C:\Users\Max\.platformio\packages\framework-arduino-openwch-ch32\cores\arduino\ch32\analog.cpp: At global scope:
C:\Users\Max\.platformio\packages\framework-arduino-openwch-ch32\cores\arduino\ch32\analog.cpp:27:12: warning: 'calibration_value' defined but not used [-Wunused-variable]
 static int calibration_value = 0;
            ^~~~~~~~~~~~~~~~~

Servo.h library not supports. HELP PLS !

WARNING: library Servo claims to run on avr, megaavr, sam, samd, nrf52, stm32f4, mbed, mbed_nano, mbed_portenta, mbed_rp2040, renesas, renesas_portenta, renesas_uno architecture(s) and may be incompatible with your current board which runs on ch32v architecture(s).
In file included from C:\Users\luutr\AppData\Local\Temp.arduinoIDE-unsaved2023929-9732-14s9i1j.0ez7\Sweep\Sweep.ino:10:
C:\Users\luutr\AppData\Local\Arduino15\libraries\Servo\src/Servo.h:79:2: error: #error "This library only supports boards with an AVR, SAM, SAMD, NRF52 or STM32F4 processor."
#error "This library only supports boards with an AVR, SAM, SAMD, NRF52 or STM32F4 processor."
^~~~~

exit status 1

Compilation error: exit status 1

Installing, or updating, to version 1.0.4 fails under Windows (11)

When installing, or updating to, version 1.0.4, the installation fails when using Windows (11), with the following console output:

Tool WCH:[email protected] already installed

Tool WCH:[email protected] already installed

Downloading packages

WCH:[email protected]

WCH:[email protected]

Installing WCH:[email protected]

Failed to install platform: 'WCH:ch32v:1.0.4'.

Error: 13 INTERNAL: Cannot install tool WCH:[email protected]: extracting archive: Create link 
C:\Users\UserName\AppData\Local\Arduino15\tmp\package-332495206\wch_beforeinstall_linux-1.0.0\libhidapi-hidraw.so: symlink libhidapi-hidraw.so.0.0.0 C:\Users\UserName\AppData\Local\Arduino15\tmp\package-332495206\wch_beforeinstall_linux-1.0.0\libhidapi-hidraw.so: A required privilege is not held by the client.

Apparently the installer attempts to install linux binaries in windows...

Nothing can be compiled for EthernetShield (W5500).

Attempting to compile the WebServer.ino example (and others for Ethernet) ends in an error:

Using board 'CH32V10x_EVT' from platform in folder: D:\Work\arduino\portable\packages\WCH\hardware\ch32v\1.0.3
Using core 'arduino' from platform in folder: D:\Work\arduino\portable\packages\WCH\hardware\ch32v\1.0.3
Detecting libraries used...

...

Alternatives for Client.h: []
ResolveLibrary(Client.h)
In file included from D:\Work\arduino\portable\sketchbook\libraries\Ethernet\examples\WebServer\WebServer.ino:21: -> candidates: []

D:\Work\arduino\portable\sketchbook\libraries\Ethernet\src/Ethernet.h:52:10: fatal error: Client.h: No such file or directory
#include "Client.h"
^~~~~~~~~~
compilation terminated.
Using library SPI version 1.0.0 from: D:\Work\arduino\portable\packages\WCH\hardware\ch32v\1.0.3\libraries\SPI
Using library Ethernet version 2.0.2 from D:\Work\arduino\portable\sketchbook\libraries\Ethernet
exit status 1

C语言运行库链接错误

在Arduino IDE编译CH32V307的固件时,C语言运行库默认为Newlib nano。当切换成Newlib Standard时出现如下编译错误:

riscv-none-embed-g++: error: {build.flags.ldflags}: No such file or directory

微信截图_20230822105359

CH32X035 board: Upload error even when upload is successful

I followed all the instructions provided and am able to successfully compile and upload my CH32X035 through Arduino IDE. However, I get the upload error even when the upload seem to be working. I tested with multiple blinking patterns and uploaded them. The LED blinked according to my code. However, Arduino IDE gives an upload error. The port is the correct one too since I can see my code changes on the board.

This is the error message I am seeing:

Info : WCH-LinkE  mode:RV version 2.11 
Info : wlink_init ok
Info : clock speed 6000 kHz
Info : [wch_riscv.cpu.0] datacount=2 progbufsize=8
Info : [wch_riscv.cpu.0] Examined RISC-V core; found 1 harts
Info : [wch_riscv.cpu.0]  XLEN=32, misa=0x40901105
[wch_riscv.cpu.0] Target successfully examined.
Info : starting gdb server for wch_riscv.cpu.0 on 3333
Info : Listening on port 3333 for gdb connections
** Programming Started **
Info : device id = {someID}
Info : flash size = 62kbytes
** Programming Finished **
** Verify Started **
** Verified OK **

Failed uploading: uploading error: exit status 1

This is preventing me to use Serial Monitor because even if it uploads, I am getting the upload error.

Math function issue

Hello,

I'm testing arduino on the CH32V003 using platformio.
I'm getting the. following error when I try to use mathematical functions like sin().

Linking .pio/build/ch32v003f4p6_evt_r0/firmware.elf
/Users/xxxxxx/.platformio/packages/toolchain-riscv/bin/../lib/gcc/riscv-none-embed/8.2.0/../../../../riscv-none-embed/bin/ld: .pio/build/ch32v003f4p6_evt_r0/src/main.cpp.o: in function `loop':
main.cpp:(.text.loop+0x3e): undefined reference to `sinf'

Is math.h supported yet ?

Thank you.

Guidance for new variant

Thanks for the useful Arduino core that you have provided. I am trying to add a variant for CH32V203RB and have made a PR #20 and would appreciate some guidance on how to make variant_CH32V203RB.h correctly.

Parameter Mismatch Issue in attachInterrupt() of WInterrupts.h/cpp

Expected Behavior

According to the documentation and Arduino core api , the function attachInterrupt() should accept params like (pin_size_t interruptNum, voidTemplateFuncPtrParam<T> userFunc, PinStatus mode, T& param), and attachInterrupt(digitalPinToInterrupt(interruptPin), blink, CHANGE) should be OK.

Current Behavior

Err occurs when compiling:

C:\Users\xxx\AppData\Local\Temp\.arduinoIDE-unsaved202375-6936-ycii6s.ifkd\sketch_aug5a\sketch_aug5a.ino: In function 'void setup()':
C:\Users\xxx\AppData\Local\Temp\.arduinoIDE-unsaved202375-6936-ycii6s.ifkd\sketch_aug5a\sketch_aug5a.ino:15:56: error: cannot convert 'void (*)()' to 'GPIOMode_TypeDef'
   attachInterrupt(digitalPinToInterrupt(interruptPin), blink, CHANGE);
                                                        ^~~~~
In file included from C:\Users\xxx\AppData\Local\Arduino15\packages\WCH\hardware\ch32v\1.0.3\cores\arduino/wiring.h:46,
                 from C:\Users\xxx\AppData\Local\Arduino15\packages\WCH\hardware\ch32v\1.0.3\cores\arduino/Arduino.h:36,
                 from C:\Users\xxx\AppData\Local\Temp\arduino\sketches\0F31CA54BC21916D8E00040838882DBE\sketch\sketch_aug5a.ino.cpp:1:
C:\Users\xxx\AppData\Local\Arduino15\packages\WCH\hardware\ch32v\1.0.3\cores\arduino/WInterrupts.h:27:52: note:   initializing argument 2 of 'void attachInterrupt(uint32_t, GPIOMode_TypeDef, void (*)(), EXTIMode_TypeDef, EXTITrigger_TypeDef)'
 void attachInterrupt(uint32_t pin,GPIOMode_TypeDef io_mode, void (*callback)(void), EXTIMode_TypeDef it_mode, EXTITrigger_TypeDef trigger_mode);
                                   ~~~~~~~~~~~~~~~~~^~~~~~~

exit status 1

Compilation error: cannot convert 'void (*)()' to 'GPIOMode_TypeDef'

Possible Solution

  • Changing the form of function parameters?

Steps to Reproduce

compiling the program:

#include <arduino.h>

const byte ledPin = 3;
 
const byte interruptPin = 2;  
 
volatile byte state = LOW;
 
void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(interruptPin, INPUT_PULLUP); 
  attachInterrupt(digitalPinToInterrupt(interruptPin), blink, CHANGE);
}
 
void loop() {
  digitalWrite(ledPin, state);
}

void blink() {
  state = !state;
}

Context (Environment)

  • Platform: WIndows 10
  • Arduino ide
    • version:2.1.1
    • date:2023-06-30T16:04:40.277Z
    • CLI version:0.32.3
  • CH32 EVT MCU Boards: version 1.0.3

Can you make a offline install package?

Hi,

As it's hard to access github for some reason, could you make an offline package?

It would be more easy to install with offline package.

Thanks a lot.

Z.t

Support for MacOS

Hey all,
Thanks a lot for the great work porting this amazing chip to Arduino.
I am unable to use it on my M2 Pro MacBook Pro as when I install the toolchain I get the following error

Downloading packages
Failed to install platform: WCH:ch32v.
Error: 13 INTERNAL: Error downloading tool WCH:[email protected]: no versions available for the current OS, try contacting [email protected]

The unofficial port of the Arduino core works without any problems.

Can you support MacOS soon? I am building test projects using CH32V003 and want to use more peripherals that supported by Alexander's port.
Thanks!

incorect waiting for i2c data in at24c02_read_write example

The example code contains

uint8_t deviceReadOneByte(uint8_t addr)
{
  Wire.requestFrom(AT24C02_ADDR,1,addr,1,1);
  while (Wire.available())
  {
    return Wire.read();
  }
}

in a attempt to wait for the byte to be delivered from the EEPROM. However the while loop would exit and garbage by returned to the caller if no data is available and if it is available then the loop exists via the return. Instead, as shown in the example at https://www.arduino.cc/reference/en/language/functions/communication/wire/read/ the code should be something like:

uint8_t deviceReadOneByte(uint8_t addr)
{
  Wire.requestFrom(AT24C02_ADDR,1,addr,1,1);
  while (!Wire.available()) { /* wait */ }
  return Wire.read();
}

CH32X035 serial

👋
I've got a CH32X035G8U6-EVT. I'm a bit confused around the serial setup. Right now I'm not seeing anything on the serial monitor running any examples.

I have it connected to a WCH-link-E w/ the two wire interface (vcc, gnd, PC18, PC19), code uploads and runs fine otherwise.

Are Serial.printf ... commands supposed to travel over the two wire programming interface and show up on the serial monitor, like in mounriver?
Or is an extra UART required for this?

referencing this video (https://www.youtube.com/watch?v=6KNtoBLvirQ), it kinda looks like a uart is going back to the WCH-LinkE, but it's not described

Any hints appreciated 🙏

Consider checking compiler and linker optimization flags - even simple blink sketch produces very long binary

Consider checking compiler and linker optimization flags
A simple sketch produces very long binary!

Arduino 1.8.19
Board CH32V00x
Board Select: CH32V003F4 EVT
Optimize: Smallest (-0s default)
Debug symbols and core Iogs: None
C Runtime Library, Newlib Nano (default)
Upload method: WCH-SWD

target : CH32V00x
Program: A simple blink sketch (defining two pins as outputs, and blinking both of them in the loop using delay)
Result:
Program CH32V003_Blink size: 10.400 bytes (used 63% of a 16.384 byte maximum) (1,82 secs)
Minimum Memory Usage: 520 bytes (25% of a 2048 byte maximum)

The same sketch using Arduino Core for the CH32V003
produces only 1KB code.

Can you put quotes around file paths, so that the upload works.

Instead of this:
"C:\Users\John Doe\AppData\Local\Arduino15\packages\WCH\tools\openocd\1.0.0/bin/openocd" -f C:\Users\John Doe\AppData\Local\Arduino15\packages\WCH\tools\openocd\1.0.0/bin/wch-riscv.cfg -c init -c halt -c "program {C:\Temp\arduino\sketches\99C3567F238CDF94969DCDFC0EB02101/Blink.ino.elf} verify; wlink_reset_resume; exit;"
It should be:
"C:\Users\John Doe\AppData\Local\Arduino15\packages\WCH\tools\openocd\1.0.0/bin/openocd" -f "C:\Users\John Doe\AppData\Local\Arduino15\packages\WCH\tools\openocd\1.0.0/bin/wch-riscv.cfg" -c init -c halt -c "program {C:\Temp\arduino\sketches\99C3567F238CDF94969DCDFC0EB02101/Blink.ino.elf} verify; wlink_reset_resume; exit;"
with quotes around the path name for wch-riscv.cfg

Clock selection using Arduino IDE menu

While testing this Arduino core on my CH32V003, I found that using a bare CH32V003 TSSOP20 chip without external crystal requires a change of clock selection in system_ch32v00x.c. Not having the correct clock selected resulted in incorrect timing of millis() and micros(). In my test using the timestamp feature of the IDE, I saw that 500ms actually took a second, which illustrated that the default fallback clock is the 24MHz internal oscillator. Having the internal clock as automatic fallback is a nice feature, but having an IDE user changing core code should be avoided.

To make clock selection easier I modified the files boards.txt, platform.txt and system_ch32v00x.c. I now can select the clock using the menu of the Arduino IDE. I don't have other type of chips for testing, but perhaps you may want to make a similar change.


Changes made:

/packages/WCH/hardware/ch32/1.0.3/system/CH32V00x/USER/system_ch32v00x.c :
=> all clock related defines commented out

/packages/WCH/hardware/ch32/1.0.3/boards.txt :

# added Clock selection to menu
menu.clock=Clock

# added flags for Clock selection
CH32V00x_EVT.menu.clock.48MHzE=48 MHz External
CH32V00x_EVT.menu.clock.48MHzE.build.flags.clock=-DSYSCLK_FREQ_48MHz_HSE=48000000
CH32V00x_EVT.menu.clock.24MHzE=24 MHz External
CH32V00x_EVT.menu.clock.24MHzE.build.flags.clock=-DSYSCLK_FREQ_24MHz_HSE=HSE_VALUE
CH32V00x_EVT.menu.clock.8MHzE=8 MHz External
CH32V00x_EVT.menu.clock.8MHzE.build.flags.clock=-DSYSCLK_FREQ_8MHz_HSE=8000000
CH32V00x_EVT.menu.clock.48MHz=48 MHz Internal
CH32V00x_EVT.menu.clock.48MHz.build.flags.clock=-DSYSCLK_FREQ_48MHZ_HSI=48000000
CH32V00x_EVT.menu.clock.24MHz=24 MHz Internal
CH32V00x_EVT.menu.clock.24MHz.build.flags.clock=-DSYSCLK_FREQ_24MHZ_HSI=HSI_VALUE
CH32V00x_EVT.menu.clock.8MHz=8 MHz Internal
CH32V00x_EVT.menu.clock.8MHz.build.flags.clock=-DSYSCLK_FREQ_8MHz_HSI=8000000

/packages/WCH/hardware/ch32/1.0.3/platform.txt "

# added Clock flag to various compiler flags
compiler.S.flags={build.flags.clock} {compiler.extra_flags} -x assembler-with-cpp "-I{build.system.path}/{build.series}/SRC/Startup/" "-I{build.core.path}/ch32/"

compiler.c.flags={build.flags.clock} {compiler.extra_flags} -c {build.flags.optimize} {build.flags.debug} {compiler.warning_flags} -std=gnu99 -MMD {compiler.ch.extra_include}

compiler.cpp.flags={build.flags.clock} {compiler.extra_flags} -c {build.flags.optimize} {build.flags.debug} {compiler.warning_flags} -std={compiler.cpp.std}  -fno-threadsafe-statics  -fno-rtti -fno-exceptions -fno-use-cxa-atexit -MMD {compiler.ch.extra_include} -fpermissive

Using other HW UARTs (3-6)

Hi,

first of all, thank you for the effort to implement this.

I'm wondering how to use other UARTs/USARTs (I have boards that I need to use UART3-6) on PlatformIO, and I did not find a way to do it.

THX
Goran

P.S.
I'm trying to implement some ethernet functionalities, and for now they work as normal classes, but I will try to catch time to implement it in Arduino style (Ethernet, Client, ..) and if they work I send you a note to try to embed it into this. TXH

WCH-Link

It is necessary to use the WCH-Link?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.