STM32 PlatformIO

That’s odd I don’t get that error. Does your user belong to the dialout groups? The pi user is in the dialout group by default in the Raspbian images

pi@raspberrypi:~ $ groups
pi adm dialout cdrom sudo audio video plugdev games users input netdev gpio i2c spi

Install or compile?

I get some warnings during compile too, I get some with the “make” routine and standard ARM toolchain too, but Ive never really studied the content, I did read it a couple of times when we started this but the info didn’t stick.

It could be because the usb device is mounted within a VM which isn’t quite the same as a physical machine.

Install. I don’t get any errors during compile.

Edit - in fact I do, the same errors occur during compile too, except the warnings are only visible if it’s run in verbose mode. - sudo pio run -t upload -v

Must admit, I was a sceptic about using Platformio, but having tried it I’m impressed.

I’m not sold on it, most of the negativity comes from having it thrust upon me at very regular intervals and having to explain why I’m not using it.

It is overkill for use on the Pi (and it currently doesn’t work which doesn’t help) the deb package and minicom works well and it’s maintained via apt-get, I have no need for more clutter. As I ve said before the serial monitor is nicer than minicom, but I wouldn’t install it just for a serial console.

Beware of using sudo with PIO. If you inadvertently use it for the compile command, it will write the temp files as root and not be able to delete them next time you compile as non-root. I have no doubt sudo make will probably do the same, but as I’m not using any sudo commands whilst compiling/flashing and viewing the serial output it’s a mistake less likely to happen for me.

Do you have to use sudo with minicom too?

1 Like

Well I never…

I just found Miniterm is installed as part of the standard Raspbian image. So there is no reason for me to install Minicom (which I dislike). I can just install the ARM toolchain alone and use Miniterm.

pi@raspberrypi:~ $ miniterm.py /dev/ttyACM0 115200
--- Miniterm on /dev/ttyACM0  115200,8,N,1 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
0: Vrms: 1133.46, Irms: 8.50, Papp: 9636.96, Preal: -28.42, PF: -0.003
1: Vrms: 1133.46, Irms: 87.93, Papp: 99662.74, Preal: 1469.25, PF: 0.015
2: Vrms: 1133.46, Irms: 87.93, Papp: 99662.74, Preal: 1469.25, PF: 0.015
3: Vrms: 1133.44, Irms: 87.93, Papp: 99660.94, Preal: 1316.91, PF: 0.013

--- exit ---
pi@raspberrypi:~ $

how great is that?

I can just set up an alias to include the settings and path like I have for Minicom and issue a single word command to open the Miniterm serial console at the right baud and path, Fantastic!

1 Like

Yes.

Well the compile command is run by root sudo pio run -t upload - see Trystan’s readme.md
…which results in the compiled data being;

paul@debian:~/STM32Cube/Repository/stm32tests/emonTxshield/.pioenvs$ ls -la stm32f303-dev
total 472
drwxr-xr-x 5 root root   4096 Mar 28 21:11 .
drwxr-xr-x 3 root root   4096 Mar 28 21:11 ..
-rwxr-xr-x 1 root root  29720 Mar 28 21:11 firmware.bin
-rwxr-xr-x 1 root root 155496 Mar 28 21:11 firmware.elf
drwxr-xr-x 3 root root   4096 Mar 28 21:11 FrameworkCMSISDevice
drwxr-xr-x 3 root root   4096 Mar 28 21:10 FrameworkHALDriver
-rw-r--r-- 1 root root   9816 Mar 28 21:11 libFrameworkCMSISDevice.a
-rw-r--r-- 1 root root 358016 Mar 28 21:11 libFrameworkHALDriver.a
drwxr-xr-x 2 root root   4096 Mar 28 21:10 src

Ohh! That’s not good! So make won’t work after using PIO either? Unless you use sudo too. That cannot be right, it installs it’s toolchain in the users home folder, not in the root filesystem, it shouldn’t then expect you to use sudo. Did you install with sudo or not?

[edit] Do you have a .platformio folder in your users home directory? Is there one at the root users home directory too?

[edit2] If you have more than one .platformio folder, can you tell which is being used? latest file times or rename one of them to see it is causes an issue.

[edit3] If you look at Glyns first post in this thread he doesn’t use sudo either (and his middle name is platformio), but I suppose he may be a root level user.

[edit4] In the PlatformIO: Compile & upload firmware. Blog post 1/3 thread, there is a variety of sudo and non-sudo commands but no explanation as to which or why. I think some clarification may be in order here.

Yes, I used the Platformio installation script (and yes sudo was required)

Yes, but it only contains a Platformio json config file - no other data

Yes, but that folder contains Platformio’s libraries, toolchains, etc.

Maybe. That’s one for Glyn to answer!

EDIT - there is a way to install Platformio local to a user, but pip is needed (the package management system for Python). I didn’t really want to install pip, as it’s yet more baggage I probably wouldn’t use again!!

I have both since I ran the compile with sudo by accident the other day and that’s how I came to learn about the issue with root owned temp files as I only made the error once and then couldn’t use non-sudo as I was used to.

pi@raspberrypi:~ $ ls -la .platformio
total 24
drwxr-xr-x  5 pi pi 4096 Mar 26 19:08 .
drwxr-xr-x 35 pi pi 4096 Mar 28 20:02 ..
-rw-r--r--  1 pi pi  186 Mar 26 19:08 appstate.json
drwxr-xr-x  2 pi pi 4096 Mar 23 17:00 lib
drwxr-xr-x  8 pi pi 4096 Mar 26 19:04 packages
drwxr-xr-x  3 pi pi 4096 Mar 26 18:57 platforms
pi@raspberrypi:~ $ sudo ls -la /root/.platformio
total 24
drwxr-xr-x 5 root root 4096 Mar 23 16:58 .
drwx------ 6 root root 4096 Mar 23 16:51 ..
-rw-r--r-- 1 root root  139 Mar 23 16:58 appstate.json
drwxr-xr-x 2 root root 4096 Mar 23 16:58 lib
drwxr-xr-x 8 root root 4096 Mar 23 16:57 packages
drwxr-xr-x 3 root root 4096 Mar 23 16:51 platforms

I too installed with sudo for the installer, I only asked to see if there was a difference.

If you delete the temp files in .pioenvs will it then compile without sudo?

sudo rm -r /home/pi/redo/txshield_demo_3/emonTxshield/.pioenvs

(edit to suit your user and path)

although it looks like all your files are root, you may need to chown the project folder instead.

PIP is also included as standard on the Raspbian image, but PIO installed it again, or so it told me, I don’t actually know if the message was accurate, but I recall I was annoyed whilst watching it apparently install PIP when I knew it was already there.

I use a lot of Python so PIP is generally something I use.

I think you have a non-sudo PIO, but once you use sudo you are stuck unless you remove or chown the files.

You souldn’t need sudo to flash the stm32 as it’s mounted to the users media folder so you shouldn’t need sudo at all for the run or upload commands.

For acces to the serial port to negate using sudo with miniterm try adding your user to the dialout group with

sudo usermod -a -G dialout $USER

you might need to log out and in, or start anew shell to get the new group permissions. Check it with groups .

My main project files are not root.
But, after deleting .pioenvs and running platformio without sudo, it again downloaded the toolchain, libraries and support files to my user root (so like you - I now have a set in root users home directory & a set in user home directory!!) it then went onto successfully flash the STM32.

However, the .pioenvs is now user owned;

user

I suppose the test now is to delete the library files (except the json config) from the root users home directory, but being a gentleman - you first!!

Paul

pi@raspberrypi:~ $ sudo mv /root/.platformio /root/X.platformio
pi@raspberrypi:~ $ cd ~/v5/stm32tests/emonTxshield
pi@raspberrypi:~/v5/stm32tests/emonTxshield $ pio run
[Wed Mar 28 21:21:33 2018] Processing stm32f303-dev (platform: ststm32; board: nucleo_f303re; framework: stm32cube)
----------------------------------------------------------------------------------------------------------------------------------------

...
...
...

Calculating size .pioenvs/stm32f303-dev/firmware.elf
text       data     bss     dec     hex filename
21408      1088    5908   28404    6ef4 .pioenvs/stm32f303-dev/firmware.elf
===================================================== [SUCCESS] Took 36.62 seconds =====================================================

============================================================== [SUMMARY] ==============================================================
Environment stm32f303-dev       [SUCCESS]
Environment stm32f303           [SKIP]
===================================================== [SUCCESS] Took 36.63 seconds =====================================================
pi@raspberrypi:~/v5/stm32tests/emonTxshield $

No problemo!

I just renamed the copy in the root folder so PIO couldn’t find them

1 Like

Sweet!
We need @glyn.hudson to drop the ‘sudo’ from the repo readme to avoid further confusion.

Thanks, I can access Miniterm now as user.

Paul

2 Likes

… and now I’ve deleted them and reclaimed 0.6GB of space!!!

pi@raspberrypi:~/v5/stm32tests/emonTxshield $ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root       7.2G  6.1G  843M  88% /
devtmpfs        460M     0  460M   0% /dev
tmpfs           464M     0  464M   0% /dev/shm
tmpfs           464M   13M  452M   3% /run
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           464M     0  464M   0% /sys/fs/cgroup
/dev/mmcblk0p1   42M   21M   21M  51% /boot
tmpfs            93M     0   93M   0% /run/user/1000
/dev/sda        540K  260K  280K  49% /media/pi/NODE_F303RE
pi@raspberrypi:~/v5/stm32tests/emonTxshield $ sudo rm -r /root/X.platformio
pi@raspberrypi:~/v5/stm32tests/emonTxshield $ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root       7.2G  5.5G  1.4G  81% /
devtmpfs        460M     0  460M   0% /dev
tmpfs           464M     0  464M   0% /dev/shm
tmpfs           464M   13M  452M   3% /run
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           464M     0  464M   0% /sys/fs/cgroup
/dev/mmcblk0p1   42M   21M   21M  51% /boot
tmpfs            93M     0   93M   0% /run/user/1000
/dev/sda        540K  260K  280K  49% /media/pi/NODE_F303RE

now I’m thinking the 2nd set of libs must be also 0.6GB, plus the actual PIO install, I bet I could claim back a full 1.0GB (give or take) by removing PIO entirely.

If you’re logged is as a non-root user, and you do

sudo usermod -a -G $USER

it’ll make the change for that user.

1 Like

Typo, I thought I had typed $USER that why the USER was in CAPS. Edited now cheers Bill.

YWS!

I ordered a Nucleo F303RE and a shield today. Thought I’d follow the thread a bit more than just reading it.
This has been one of the more enjoyable and (especially) educational reads on the forum in quite some time.

1 Like

I wonder how many users have 2 copies of the complete toolchain and libs etc on their emonPi’s?

Mmmmh! there’s a name for people that find enjoyment in the suffering of others :grin:

sudo usermod -a -G dialout paul works just fine for dialout.
I assume Bill is talking more global.

Great news Bill, look forward to your contribution!

Paul

1 Like

Yes it’s using a environment variable so that it that work’s without editing, even with sudo eg

pi@raspberrypi:~ $ sudo echo $USER
pi