Anytime i try to build my project using platform io on my raspberry pi pico i get the same error (in appended picture).
I have tried to set the upload_port to the listed D: drive when i plug the pico in whilst holding down the boot selection button. I have also tried downloading WinUSB drivers using Zadig (2.5 and 2.9).
Project Code: https://github.com/JuergenBachi/3BHWII_PING_PONG
The error still persist and nothing i have tried thus far made the problem any better.
The error is not about uploading but more about missing definitions.
[env:rpipico]
platform = raspberrypi
board = rpipico
There is no board “rppico” available in “raspberrypi” platform - See PlatformIO Registry
There are just 2 boards available:
board = pico
for the Raspberry Pi Pico
board = nanorp2040connect
for the Arduino Nano RP2040 Connect
lib_deps
and your main.cpp
:
Do this this step by step, beginning with a simple “Hello World”:
[env:pico]
platform = raspberrypi
board = pico
framework = arduino
monitor_speed = 115200
#include <Arduino.h>
void setup() {
Serial.begin(115200);
Serial.println("Hello World");
}
void loop() {
}
Compile, upload and check if it is working…
Sorry for the very late response!
When creating a new project in Platform IO i get more than just the 2 boards you mentioned as you can see in the following picture.
I have also tried your Hello World test code. When using the “pico” env i get a bunch of warnings during the build. When using the “rpipico” env i get no warnings or error during the build and the upload of the project.
I have also tried different environments for the main code in the GitHub repository with no luck. I still always get the same Error 1 when trying to build the project.
Maybe you have already installed a custom platform for RaspberryPi in the past. Please show the installed platforms.
What about the very basic sketch above?
Thanks for your continued support!
The only installed platform is the “Raspberry Pi RP2040” platform:
When looking at the boards included in the raspberry pi rp2040 platform i again find multiple entries of raspberry pi picos:
In red highlighted are the two boards i have tried to test the very basic sketch as well as the code on GitHub i linked in my original post.
The testing of the GitHub code resulted with the same error 1 on both boards but with a lot more warnings from the board shown as “Pico (Raspberry Pi)” than the “Raspberry Pi Pico” board.
The basic sketch you provided worked on both boards but again the “Pico (Raspberry Pi)” board threw a lot of warnings at me during the building.
Since as a new user i cant have more than one embed in a reply heres the screenshot with the in red highlighted boards i was talking about:
Interesting, that error is reproducible. The toolchain seems to have a bug or a missing option such that
static std::random_device rd; // Seed for the random number engine
static std::mt19937 gen; // Mersenne Twister engine
static std::uniform_int_distribution<> dis; // Distribution in range [1, 6]
is not usable.
When writing a small test program, it yields
Linking .pio\build\rpipico\firmware.elf
C:/Users/Max/.platformio/packages/toolchain-rp2040-earlephilhower/bin/../lib/gcc/arm-none-eabi/14.2.0/../../../../arm-none-eabi/bin/ld.exe: C:/Users/Max/.platformio/packages/toolchain-rp2040-earlephilhower/bin/../lib/gcc/arm-none-eabi/14.2.0/../../../../arm-none-eabi/lib/thumb\libstdc++.a(random.o): in function `_ZNSt12_GLOBAL__N_117__libc_getentropyEPv':
/workdir/repo/gcc-gnu/libstdc++-v3/src/c++11/random.cc:183:(.text._ZNSt12_GLOBAL__N_117__libc_getentropyEPv+0x8): undefined reference to `getentropy'
C:/Users/Max/.platformio/packages/toolchain-rp2040-earlephilhower/bin/../lib/gcc/arm-none-eabi/14.2.0/../../../../arm-none-eabi/bin/ld.exe: C:/Users/Max/.platformio/packages/toolchain-rp2040-earlephilhower/bin/../lib/gcc/arm-none-eabi/14.2.0/../../../../arm-none-eabi/lib/thumb\libstdc++.a(random.o): in function `_ZNSt13random_device7_M_initERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE':
/workdir/repo/gcc-gnu/libstdc++-v3/src/c++11/random.cc:468:(.text._ZNSt13random_device7_M_initERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+0x2e): undefined reference to `getentropy'
C:/Users/Max/.platformio/packages/toolchain-rp2040-earlephilhower/bin/../lib/gcc/arm-none-eabi/14.2.0/../../../../arm-none-eabi/bin/ld.exe: C:/Users/Max/.platformio/packages/toolchain-rp2040-earlephilhower/bin/../lib/gcc/arm-none-eabi/14.2.0/../../../../arm-none-eabi/lib/thumb\libc.a(libc_a-arc4random.o): in function `_rs_stir':
/workdir/repo/newlib/newlib/libc/stdlib/arc4random.c:101:(.text+0x58a): undefined reference to `getentropy'
Hinting at the missing getentropy()
function.
In any case, you really really don’t need a fancy std::uniform_int_distribution
C++ STL thingy to get a random number. For that, the core already has rp2040.hwrand();
to access a random number, generated by hardware.
Delete all references to the std::...
random stuff and instead use
long randomRangeHW(long howsmall, long howbig) {
if (howsmall >= howbig) {
return howsmall;
}
long diff = howbig - howsmall;
return (rp2040.hwrand32() % howbig) + howsmall;
}
void randomDirection() {
direction = static_cast<eDir>(randomRangeHW((int) STOP, ((int) DOWNRIGHT) + 1));
}
1 Like
Another option is to give it the missing getentropy()
function at the bottom of the sketch, e.g.,
// see https://man.archlinux.org/man/getentropy.3.en
extern "C" int getentropy (void * buffer, size_t how_many) {
uint8_t* pBuf = (uint8_t*) buffer;
while(how_many--) {
uint8_t rand_val = rp2040.hwrand32() % UINT8_MAX;
*pBuf++ = rand_val;
}
return 0; // return "no error". Can also do EFAULT, EIO, ENOSYS
}
While also pulling out
static std::random_device rd; // Seed for the random number engine
static std::mt19937 gen; // Mersenne Twister engine
static std::uniform_int_distribution<> dis; // Distribution in range [1, 6]
from inside the class cBall
to the global scope (weirdly complains about the “gen” variable then, no idea).
And finally, simply using the standard Arduino pattern for getting random numbers is to just use the included random()
function.
https://docs.arduino.cc/language-reference/en/functions/random-numbers/random/
For a game, this should be more than sufficient.
void randomDirection() {
direction = static_cast<eDir>(random((int) STOP, ((int) DOWNRIGHT) + 1));
}
If needed, this random number generator (C library rand()
btw) can be seeded once with a high-quality random value in e.g. setup()
randomSeed(rp2040.hwrand32());
1 Like
Simply using the random() function actually worked!!!
You actually fixed my professors code. My school is wild.
Thank you so much for all the replies and helpful advice.
Just to be fair, in a fully-featured desktop environment, random number generation by the means of
static std::random_device rd; // Seed for the random number engine
static std::mt19937 gen; // Mersenne Twister engine
static std::uniform_int_distribution<> dis; // Distribution in range [1, 6]
can be expected to reasonably work, but not in constrained embedded environments. So if the code was meant to be running on a regular desktop, it wasn’t wrong per-sé.