Comments (12)
Install riscv64-elf-newlib
:
# I use arch, btw
sudo pacman -S riscv64-elf-newlib
and add this include path parameter to Makefile:
-I/usr/riscv64-elf/include
It worked for me this way
from ch32v003fun.
Another solution is to import this library, it works too!!
from ch32v003fun.
Alternative I tried to use sprintf to format an value into a string now.
But only printf is available, sprintf cannot be found!
It is the same with other functions in <string.h> like strcat.
$ make
riscv64-unknown-elf-gcc -o spi_lcd.elf ../../ch32v003fun/ch32v003fun.c spi_lcd.c -g -Os -flto -ffunction-sections -static-libgcc -march=rv32ec -mabi=ilp32e -I/usr/include/newlib -I../../ch32v003fun/../extralibs -I../../ch32v003fun -nostdlib -I. -Wall -T ../../ch32v003fun/ch32v003fun.ld -Wl,--gc-sections -L../../ch32v003fun/../misc -lgcc
/usr/lib/riscv64-unknown-elf/bin/ld: /tmp/cccOzuwj.ltrans0.ltrans.o: in function `.L0 ':
/win/WCH/K/examples/spi_lcd/lcd.c:110: undefined reference to `sprintf'
/usr/lib/riscv64-unknown-elf/bin/ld: /win/WCH/K/examples/spi_lcd/lcd.c:167: undefined reference to `sprintf'
collect2: error: ld returned 1 exit status
make: *** [../../ch32v003fun/ch32v003fun.mk:24: spi_lcd.elf] Fehler 1
undefined reference to `sprintf'
Every conversion of a number into a string is not allowed? ;-)
Only printf to an UART?
Every string operation is a problem.
from ch32v003fun.
If someone else has the same problem and this bug will not be solved, you can copy as workaround the needed functions into your code. That is working.
https://github.com/vancegroup-mirrors/avr-libc/tree/master/avr-libc/tests/simulate/stdlib
For example:
static char *ultoa_recursive (unsigned long val, char *s, unsigned radix)
{
int c;
if (val >= radix)
s = ultoa_recursive (val / radix, s, radix);
c = val % radix;
c += (c < 10 ? '0' : 'a' - 10);
*s++ = c;
return s;
}
static char *ultoa (unsigned long val, char *s, int radix)
{
if (radix < 2 || radix > 36)
s[0] = 0;
else
*ultoa_recursive (val, s, radix) = 0;
return s;
}
from ch32v003fun.
Normally that comes with libgcc, but, I appreciate the answer - do you mind if we close the issue?
from ch32v003fun.
Addtionally installed package libgcc-10-dev-riscv64-cross and dependent packages with many MB data.
Install: gcc-10-cross-base-ports:amd64 (10.2.1-6cross1, automatic), libgcc-10-dev-riscv64-cross:amd64 (10.2.1-6cross1), libatomic1-riscv64-cross:amd64 (10.2.1-6cross1, automatic), libc6-dev-riscv64-cross:amd64 (2.31-9cross4, automatic), linux-libc-dev-riscv64-cross:amd64 (5.10.13-1cross4, automatic), libgomp1-riscv64-cross:amd64 (10.2.1-6cross1, automatic), libc6-riscv64-cross:amd64 (2.31-9cross4, automatic), libgcc-s1-riscv64-cross:amd64 (10.2.1-6cross1, automatic)
No change - it still does not find an ultoa or sprintf.
I have no idea where to search?
Maybe a newer version of gcc-riscv64-unknown-elf will help, but it is not easy to get it into the stable system.
from ch32v003fun.
The Makefile explicitly builds with -nostdlib
, maybe that's the problem?
In the MounRiver toolchain I can build with stdlib functions perfectly fine, but I also add --specs=nano.specs --specs=nosys.specs
, which doesn't work with the standard GCC because they don't seem to have those libs precompiled for rv32ec
from ch32v003fun.
A version of sprint() is included in the fun-library, but it's not in the .h file so you need to declare it yourself to avoid warnings.
int mini_snprintf(char* buffer, unsigned int buffer_len, const char *fmt, ...);
int main() {
char buf[20];
mini_snprintf(buf, sizeof(buf), "%s %x", "Hello", 10);
}
from ch32v003fun.
The Makefile explicitly builds with
-nostdlib
, maybe that's the problem?
Yes - I already did see this too and tried to compile without this option, but there where other problems I cannot remember.
In the MounRiver toolchain I can build with stdlib functions perfectly fine, but I also add
--specs=nano.specs --specs=nosys.specs
, which doesn't work with the standard GCC because they don't seem to have those libs precompiled for rv32ec
O.K. Thanks. The meaning for the gcc-riscv64-unknown-elf is not clear to me at this time, but it is a good hint.
I will try to setup a small Debian testing (trixie) with a newer gcc-riscv64-unknown-elf 12.2.0-14 first and see how the behaviour will be there. https://packages.debian.org/sid/gcc-riscv64-unknown-elf
I did not notice that there is a new Debian stable (bookworm) since June 10th, 2023. Hmmm - it has the newer compiler too - more work for an upgrade instead of an separate install of testing.
from ch32v003fun.
System upgrade to Debian 12 (bookworm) done. The positive message is that this part works without problems.
The negative message is that the upgrade does not effect the described problem with the missing library functions.
$ make
riscv64-unknown-elf-gcc -o spi_lcd.elf ../../ch32v003fun/ch32v003fun.c spi_lcd.c -g -Os -flto -ffunction-sections -static-libgcc -march=rv32ec -mabi=ilp32e -I/usr/include/newlib -I../../ch32v003fun/../extralibs -I../../ch32v003fun -nostdlib -I. -Wall -T ../../ch32v003fun/ch32v003fun.ld -Wl,--gc-sections -L../../ch32v003fun/../misc -lgcc
spi_lcd.c: In function 'main':
spi_lcd.c:93:9: warning: implicit declaration of function 'ultoa'; did you mean 'utoa'? [-Wimplicit-function-declaration]
93 | ultoa(SYSTEM_CORE_CLOCK / 1000000, lpuffer, 10);
| ^~~~~
| utoa
/usr/lib/gcc/riscv64-unknown-elf/12.2.0/../../../riscv64-unknown-elf/bin/ld: /tmp/ccPVLYzm.ltrans0.ltrans.o: in function `.L0 ':
/win/WCH/K/examples/spi_lcd/lcd.c:110: undefined reference to `ultoa'
/usr/lib/gcc/riscv64-unknown-elf/12.2.0/../../../riscv64-unknown-elf/bin/ld: /win/WCH/K/examples/spi_lcd/lcd.c:167: undefined reference to `ultoa'
collect2: error: ld returned 1 exit status
make: *** [../../ch32v003fun/ch32v003fun.mk:27: spi_lcd.elf] Fehler 1
undefined reference to `ultoa'
$ make
riscv64-unknown-elf-gcc -o spi_lcd.elf ../../ch32v003fun/ch32v003fun.c spi_lcd.c -g -Os -flto -ffunction-sections -static-libgcc -march=rv32ec -mabi=ilp32e -I/usr/include/newlib -I../../ch32v003fun/../extralibs -I../../ch32v003fun -nostdlib -I. -Wall -T ../../ch32v003fun/ch32v003fun.ld -Wl,--gc-sections -L../../ch32v003fun/../misc -lgcc
/usr/lib/gcc/riscv64-unknown-elf/12.2.0/../../../riscv64-unknown-elf/bin/ld: /tmp/cc98ACmE.ltrans0.ltrans.o: in function `.L0 ':
/win/WCH/K/examples/spi_lcd/lcd.c:116: undefined reference to `sprintf'
/usr/lib/gcc/riscv64-unknown-elf/12.2.0/../../../riscv64-unknown-elf/bin/ld: /win/WCH/K/examples/spi_lcd/lcd.c:166: undefined reference to `sprintf'
collect2: error: ld returned 1 exit status
make: *** [../../ch32v003fun/ch32v003fun.mk:27: spi_lcd.elf] Fehler 1
kars
undefined reference to `sprintf'
$ riscv64-unknown-elf-gcc -v
Using built-in specs.
COLLECT_GCC=riscv64-unknown-elf-gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/riscv64-unknown-elf/12.2.0/lto-wrapper
Target: riscv64-unknown-elf
Configured with: ../gcc-12.2.0/configure --build=x86_64-linux-gnu --prefix=/usr --includedir='/usr/lib/include' --mandir='/usr/lib/share/man' --infodir='/usr/lib/share/info' --sysconfdir=/etc --localstatedir=/var --disable-option-checking --disable-silent-rules --libdir='/usr/lib/lib/x86_64-linux-gnu' --libexecdir='/usr/lib/lib/x86_64-linux-gnu' --disable-maintainer-mode --disable-dependency-tracking --enable-languages=c,c++ --prefix=/usr/lib --infodir=/usr/share/doc/gcc-riscv64-unknown-elf/info --mandir=/usr/share/man --htmldir=/usr/share/doc/gcc-riscv64-unknown-elf/html --pdfdir=/usr/share/doc/gcc-riscv64-unknown-elf/pdf --bindir=/usr/bin --libexecdir=/usr/lib --libdir=/usr/lib --with-system-zlib --enable-multilib --disable-decimal-float --disable-libffi --disable-libgomp --disable-libmudflap --disable-libquadmath --disable-libssp --disable-libstdcxx-pch --disable-libstdc++-v3 --disable-nls --disable-shared --disable-threads --with-arch=rv64imafdc --enable-tls --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=riscv64-unknown-elf --with-gnu-as --with-gnu-ld --with-headers=no --without-newlib --with-pkgversion=12.2.0-14+11+b1 --without-included-gettext SED=/bin/sed SHELL=/bin/sh BASH=/bin/bash CONFIG_SHELL=/bin/bash AR_FOR_TARGET=riscv64-unknown-elf-ar AS_FOR_TARGET=riscv64-unknown-elf-as LD_FOR_TARGET=riscv64-unknown-elf-ld NM_FOR_TARGET=riscv64-unknown-elf-nm OBJDUMP_FOR_TARGET=riscv64-unknown-elf-objdump RANLIB_FOR_TARGET=riscv64-unknown-elf-ranlib READELF_FOR_TARGET=riscv64-unknown-elf-readelf STRIP_FOR_TARGET=riscv64-unknown-elf-strip ASFLAGS= CFLAGS='-g -O2 -ffile-prefix-map=/build/gcc-riscv64-unknown-elf-jdqiw5/gcc-riscv64-unknown-elf-11+b1=. -fstack-protector-strong' CPPFLAGS='-Wdate-time -D_FORTIFY_SOURCE=2' CXXFLAGS='-g -O2 -ffile-prefix-map=/build/gcc-riscv64-unknown-elf-jdqiw5/gcc-riscv64-unknown-elf-11+b1=. -fstack-protector-strong' DFLAGS=-frelease FCFLAGS='-g -O2 -ffile-prefix-map=/build/gcc-riscv64-unknown-elf-jdqiw5/gcc-riscv64-unknown-elf-11+b1=. -fstack-protector-strong' FFLAGS='-g -O2 -ffile-prefix-map=/build/gcc-riscv64-unknown-elf-jdqiw5/gcc-riscv64-unknown-elf-11+b1=. -fstack-protector-strong' GCJFLAGS='-g -O2 -ffile-prefix-map=/build/gcc-riscv64-unknown-elf-jdqiw5/gcc-riscv64-unknown-elf-11+b1=. -fstack-protector-strong' LDFLAGS='-Wl,-z,relro -Wl,-z,now' OBJCFLAGS='-g -O2 -ffile-prefix-map=/build/gcc-riscv64-unknown-elf-jdqiw5/gcc-riscv64-unknown-elf-11+b1=. -fstack-protector-strong' OBJCXXFLAGS='-g -O2 -ffile-prefix-map=/build/gcc-riscv64-unknown-elf-jdqiw5/gcc-riscv64-unknown-elf-11+b1=. -fstack-protector-strong' INHIBIT_LIBC_CFLAGS=-DUSE_TM_CLONE_REGISTRY=0 'CFLAGS_FOR_TARGET=-Os -mcmodel=medany' 'CXXFLAGS_FOR_TARGET=-Os -mcmodel=medany'
Thread model: single
Supported LTO compression algorithms: zlib
gcc version 12.2.0 (12.2.0-14+11+b1)
from ch32v003fun.
I'm going to mark this as complete now.
from ch32v003fun.
In the MounRiver toolchain I can build with stdlib functions perfectly fine, but I also add
--specs=nano.specs --specs=nosys.specs
, which doesn't work with the standard GCC because they don't seem to have those libs precompiled for rv32ec
Poking an old (closed) issue but, in case it helps anyone, the xPack GNU RISC-V Embedded GCC toolchain bundles Newlib nano support for rv32ec/ilp32
:
from ch32v003fun.
Related Issues (20)
- Wrong definition of funPinMode? HOT 2
- FUN_HIGH and FUN_LOW behave reversed for funDigitalWrite HOT 1
- Convoluted UART_BRR calculation HOT 3
- Redundant `blink[_raw].bin` files source controlled in repo? HOT 11
- TODO For new updates
- Configurable RAM sizes for V20x, V30x HOT 8
- Compilation results in no code HOT 1
- Make minichlink print flash amount HOT 1
- Make semihosting printf speed along if it times out.
- Empty LD file on missing build tools HOT 2
- prebuilt blink.bin example doesn't seem to work on a CH32V003 board HOT 1
- PWM 8 KHz 16 bit HOT 11
- Onewire slave
- CH32V003A4M6 SPI? HOT 2
- Is this board right for me? HOT 5
- Are there defined symbolic constants for AFIO_EXTICR register values? HOT 5
- minichlink not detecting esp32 programmer on MacOS. HOT 1
- DISCUSSION - Could this run Klipper ? I think it really could omg HOT 8
- Why does my code stop when I connect minichlink terminal? HOT 8
- v30x blink example don't run if TARGET_MCU_PACKAGE sets to CH32V307VCT6 HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ch32v003fun.