alexandermandera / arduino-wch32v003 Goto Github PK
View Code? Open in Web Editor NEWArduino Core for CH32V003 RISC-V microcontroller
License: GNU Lesser General Public License v2.1
Arduino Core for CH32V003 RISC-V microcontroller
License: GNU Lesser General Public License v2.1
c:/users/zanis/.platformio/packages/toolchain-riscv/bin/../lib/gcc/riscv-none-embed/8.2.0/../../../../riscv-none-embed/bin/ld.exe: .pio\build\genericCH32V003F4P6\src\main.cpp.o: in function loop': main.cpp:(.text.loop+0xa): undefined reference to
analogRead'
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\genericCH32V003F4P6\firmware.elf] Error 1
Hi,
I am succesfully using Ardulink as a programmer (with a 1K resistor) to flash the ch32v003:
https://gitlab.com/BlueSyncLine/arduino-ch32v003-swio
Could you add this programmer as a option, I just needed to add "-c /dev/ttyACM0" as an option to make it work.
Just to mention...
While trying to add board, it reports a CRC mismatch, retry later...
riscv-none-elf-g++: warning: '-x c++' after last input file has no effect
/tmp/.arduinoIDE-unsaved2023915-2954-4dhnw1.15zhd/sketch_oct15a/sketch_oct15a.ino: In function 'void editln()':
/tmp/.arduinoIDE-unsaved2023915-2954-4dhnw1.15zhd/sketch_oct15a/sketch_oct15a.ino:26:23: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
26 | p=findstr(buf," ");
| ^~~
/tmp/.arduinoIDE-unsaved2023915-2954-4dhnw1.15zhd/sketch_oct15a/sketch_oct15a.ino:27:24: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
27 | if(findstr(buf," ")) {
| ^~~
/tmp/.arduinoIDE-unsaved2023915-2954-4dhnw1.15zhd/sketch_oct15a/sketch_oct15a.ino: In function 'void loop()':
/tmp/.arduinoIDE-unsaved2023915-2954-4dhnw1.15zhd/sketch_oct15a/sketch_oct15a.ino:183:23: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
183 | puts2("\n\rOk\n\r");
| ^~~~~~~~~~~~
/tmp/.arduinoIDE-unsaved2023915-2954-4dhnw1.15zhd/sketch_oct15a/sketch_oct15a.ino:196:48: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
196 | if (!findstr(s,""")){
| ^~~~
/tmp/.arduinoIDE-unsaved2023915-2954-4dhnw1.15zhd/sketch_oct15a/sketch_oct15a.ino:197:59: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
197 | while(p=findstr(s,"<>"))
| ^~~~
/tmp/.arduinoIDE-unsaved2023915-2954-4dhnw1.15zhd/sketch_oct15a/sketch_oct15a.ino:199:59: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
199 | while(p=findstr(s,"<="))
| ^~~~
/tmp/.arduinoIDE-unsaved2023915-2954-4dhnw1.15zhd/sketch_oct15a/sketch_oct15a.ino:201:59: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
201 | while(p=findstr(s,">="))
| ^~~~
/tmp/.arduinoIDE-unsaved2023915-2954-4dhnw1.15zhd/sketch_oct15a/sketch_oct15a.ino:273:71: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
273 | if(quoted&1 || !findstr(" \t",F))//what in the world does this line do?
| ^~~~~
/tmp/.arduinoIDE-unsaved2023915-2954-4dhnw1.15zhd/sketch_oct15a/sketch_oct15a.ino:314:74: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
314 | ((q=findstr(buf,"TH"))=0,
| ^~~~
/tmp/.arduinoIDE-unsaved2023915-2954-4dhnw1.15zhd/sketch_oct15a/sketch_oct15a.ino:357:65: warning: ISO C++ forbids converting a string constant to 'char' [-Wwrite-strings]
357 | *(q=findstr(buf,"TO"))=0;
| ^~~~
/home/icelon/.arduino15/packages/alexandermandera/tools/riscv-none-elf-gcc/12.2.0-3-xPack/bin/../lib/gcc/riscv-none-elf/12.2.0/../../../../riscv-none-elf/bin/ld: /tmp/ccvXmO9o.ltrans0.ltrans.o: in function .L0 ': /tmp/.arduinoIDE-unsaved2023915-2954-4dhnw1.15zhd/sketch_oct15a/sketch_oct15a.ino:75: undefined reference to
strtol'
/home/icelon/.arduino15/packages/alexandermandera/tools/riscv-none-elf-gcc/12.2.0-3-xPack/bin/../lib/gcc/riscv-none-elf/12.2.0/../../../../riscv-none-elf/bin/ld: /tmp/.arduinoIDE-unsaved2023915-2954-4dhnw1.15zhd/sketch_oct15a/sketch_oct15a.ino:157: undefined reference to sprintf' /home/icelon/.arduino15/packages/alexandermandera/tools/riscv-none-elf-gcc/12.2.0-3-xPack/bin/../lib/gcc/riscv-none-elf/12.2.0/../../../../riscv-none-elf/bin/ld: /tmp/ccvXmO9o.ltrans0.ltrans.o:/tmp/.arduinoIDE-unsaved2023915-2954-4dhnw1.15zhd/sketch_oct15a/sketch_oct15a.ino:158: undefined reference to
strcat'
/home/icelon/.arduino15/packages/alexandermandera/tools/riscv-none-elf-gcc/12.2.0-3-xPack/bin/../lib/gcc/riscv-none-elf/12.2.0/../../../../riscv-none-elf/bin/ld: /tmp/ccvXmO9o.ltrans0.ltrans.o: in function .L0 ': /tmp/.arduinoIDE-unsaved2023915-2954-4dhnw1.15zhd/sketch_oct15a/sketch_oct15a.ino:180: undefined reference to
malloc'
/home/icelon/.arduino15/packages/alexandermandera/tools/riscv-none-elf-gcc/12.2.0-3-xPack/bin/../lib/gcc/riscv-none-elf/12.2.0/../../../../riscv-none-elf/bin/ld: /tmp/ccvXmO9o.ltrans0.ltrans.o:/tmp/.arduinoIDE-unsaved2023915-2954-4dhnw1.15zhd/sketch_oct15a/sketch_oct15a.ino:186: undefined reference to atoi' /home/icelon/.arduino15/packages/alexandermandera/tools/riscv-none-elf-gcc/12.2.0-3-xPack/bin/../lib/gcc/riscv-none-elf/12.2.0/../../../../riscv-none-elf/bin/ld: /tmp/ccvXmO9o.ltrans0.ltrans.o: in function
.L0 ':
/tmp/.arduinoIDE-unsaved2023915-2954-4dhnw1.15zhd/sketch_oct15a/sketch_oct15a.ino:26: undefined reference to malloc' /home/icelon/.arduino15/packages/alexandermandera/tools/riscv-none-elf-gcc/12.2.0-3-xPack/bin/../lib/gcc/riscv-none-elf/12.2.0/../../../../riscv-none-elf/bin/ld: /tmp/ccvXmO9o.ltrans0.ltrans.o:/tmp/.arduinoIDE-unsaved2023915-2954-4dhnw1.15zhd/sketch_oct15a/sketch_oct15a.ino:242: undefined reference to
sprintf'
/home/icelon/.arduino15/packages/alexandermandera/tools/riscv-none-elf-gcc/12.2.0-3-xPack/bin/../lib/gcc/riscv-none-elf/12.2.0/../../../../riscv-none-elf/bin/ld: /tmp/ccvXmO9o.ltrans0.ltrans.o:/tmp/.arduinoIDE-unsaved2023915-2954-4dhnw1.15zhd/sketch_oct15a/sketch_oct15a.ino:316: undefined reference to `sprintf'
collect2: error: ld returned 1 exit status
exit status 1
Compilation error: exit status 1
The Arduino String
class uses malloc, free and realloc to dynamically allocate memory for the strings. However, the core doesn't define the sbrk()
function as the base function needed for malloc to allocate more memory.
So a sketch like
#include <Arduino.h>
void setup() {
Serial.begin(115200);
}
static int i=0;
void loop() {
Serial.println("Hello " + String(i++));
}
fails with
Linking .pio\build\ch32v003f4p6_evt_r0\firmware.elf
c:/users/max/.platformio/packages/toolchain-riscv/bin/../lib/gcc/riscv-none-embed/8.2.0/../../../../riscv-none-embed/bin/ld.exe: .pio\build\ch32v003f4p6_evt_r0\FrameworkArduino\api\String.cpp.o: in function `arduino::String::~String()':
String.cpp:(.text._ZN7arduino6StringD2Ev+0x4): undefined reference to `free'
c:/users/max/.platformio/packages/toolchain-riscv/bin/../lib/gcc/riscv-none-embed/8.2.0/../../../../riscv-none-embed/bin/ld.exe: .pio\build\ch32v003f4p6_evt_r0\FrameworkArduino\api\String.cpp.o: in function `arduino::String::invalidate()':
String.cpp:(.text._ZN7arduino6String10invalidateEv+0xc): undefined reference to `free'
c:/users/max/.platformio/packages/toolchain-riscv/bin/../lib/gcc/riscv-none-embed/8.2.0/../../../../riscv-none-embed/bin/ld.exe: .pio\build\ch32v003f4p6_evt_r0\FrameworkArduino\api\String.cpp.o: in function `arduino::String::changeBuffer(unsigned int)':
String.cpp:(.text._ZN7arduino6String12changeBufferEj+0x10): undefined reference to `realloc'
c:/users/max/.platformio/packages/toolchain-riscv/bin/../lib/gcc/riscv-none-embed/8.2.0/../../../../riscv-none-embed/bin/ld.exe: .pio\build\ch32v003f4p6_evt_r0\FrameworkArduino\api\String.cpp.o: in function `arduino::String::String(int, unsigned char)':
String.cpp:(.text._ZN7arduino6StringC2Eih+0x18): undefined reference to `itoa'
So it also uses -nostdlib
which causes itoa
to not be found and stuff.
If I do make the required fixes per Community-PIO-CH32V@d098d4d, I get a successfull compile
Linking .pio\build\ch32v003f4p6_evt_r0\firmware.elf
Checking size .pio\build\ch32v003f4p6_evt_r0\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM: [=== ] 25.8% (used 528 bytes from 2048 bytes)
Flash: [== ] 19.9% (used 3260 bytes from 16384 bytes)
and it works during runtime.
Question is, do we want this? Should this be allowed usage on a chip with this little memory?
With the "main branch" / no malloc, a blinky sketch of
#include <Arduino.h>
#define LED C1
void setup() { pinMode(LED, OUTPUT); }
void loop() {
digitalWrite(LED, HIGH);
delay(1000);
digitalWrite(LED, LOW);
delay(1000);
}
uses
RAM: [== ] 18.4% (used 376 bytes from 2048 bytes)
Flash: [= ] 8.7% (used 1420 bytes from 16384 bytes)
and with the malloc branch it uses
RAM: [== ] 24.6% (used 504 bytes from 2048 bytes)
Flash: [= ] 11.2% (used 1832 bytes from 16384 bytes)
So.. even though this sketch shouldn't use malloc, the compiler still adds some baggage, probably because of the nosys and nano specs linking.. :(
Thanks for great resource to support CH32V003 on Arduino. It makes life much easier for beginner like me to play with. Is there any slave i2c example? I plan to use this dead cheap mcu in some of my sensors and convert them all to i2c module. Thanks.
I tried compiling an sketch for my ch32v003, everything else works fine, except analogwrite aswell and analogread i got this error
riscv-none-elf-g++: warning: '-x c++' after last input file has no effect
/home/etore/.arduino15/packages/alexandermandera/tools/riscv-none-elf-gcc/12.2.0-3-xPack/bin/../lib/gcc/riscv-none-elf/12.2.0/../../../../riscv-none-elf/bin/ld: /tmp/ccBBIZmj.ltrans0.ltrans.o: in function .L0 ': /home/etore/Arduino/pcmplayerch32v003/pcmplayerch32v003.ino:9: undefined reference to
analogRead' (this is the important part)
collect2: error: ld returned 1 exit status
exit status 1
Error compiling for board CH32V003.
And also an undefined reference to "analogwrite"
I understand you haven't implemented everything yet, but i would love for analogwrite and analogread to be implemented instead of having to resort to using digitalwrite and simulated pwm instead of analogwrite
Not an issue! But I just wanted to check in with you guys. And let you know I want to fully support your work in any way I can. I hope ch32v003 continues to earn your "upstream" business, and let us know if there are any things we can do to further support Arduino.
We'd like to avoid having weird ch32v003fun forks, so if there's any way for all the changes to stay unified, that would be very helpful.
Side-note: I am hoping (though no guarantee) that we can have a firmware-only USB bootloader for the CH32V003 in a few weeks. Feel free to follow the appropriate channels for more information there. But I hope that the "standard" one day will be to just use USB on two GPIOs.
Feel free to join our discord. https://discord.gg/CCeyWyZ
#define ledpin A2
#define ledpin2 A1
void setup() {
pinMode(ledpin, OUTPUT);
pinMode(ledpin2, OUTPUT);
}
void loop() {
digitalWrite(ledpin, HIGH);
delay(1000);
digitalWrite(ledpin, LOW);
delay(1000);
digitalWrite(ledpin2, HIGH);
delay(1000);
digitalWrite(ledpin2, LOW);
delay(1000);
}
At this code, A1 is blinking, but A2 is floating.
These pin was no problem when using ch32v003fun.
I think something wrong in cores/arduino/wiring_digital.cpp at specifying pin number
Hello, I have been following a few people using this Processor. I have a few of them a friend of mine gave me but never used them. I couldn't find anything on them with arduino.
I recently saw your GitHub and now I got excited and would love to use them. Are you still working on this project if so do you think you will get the native usb working as well as spi and i2c?
Joseph
First off, apretiate the work you put into this, it has great potential!
There are boards with external oscillator and also without. I guess this project supports the ones with oscillator but are you planning to add board definition for internal HSI oscillator?
For example this one:
https://hackaday.io/project/191287-ch32v003-a4m6-development-board
I tried to compile and flash blink with the Arduino IDE, but it was throwning an error that it could not execute miniblink:
"/home/zoobab/.arduino15/packages/alexandermandera/tools/minichlink/1.0.0/minichlink" -w "/tmp/arduino/sketches/72B0E73327037FF023DE2707CCD1ACDC/Blink.ino.bin" flash -b
Failed uploading: cannot execute upload tool: fork/exec /home/zoobab/.arduino15/packages/alexandermandera/tools/minichlink/1.0.0/minichlink: permission denied
I did a chmod +x /home/zoobab/.arduino15/packages/alexandermandera/tools/minichlink/1.0.0/minichlink , and then it worked.
Can you reproduce?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.