Playground gist for exploring PlatformIO, now that we're equipped with more electronics, microcontroller, and C++ knowledge
We're going to be using PlatformIO Core to see how robust it is vs Arduino
I feel like it's more since we'll have controls for items like fuses at programming but not 100% certain
https://platformio.org/install/cli
We've used PlatformIO Core before in:
https://github.com/twolfson/arduino-playground
but it's been a loooong while
We're going to be using virtualenvwrapper
to keep everything contained
Although I believe Pipenv
is the new hotness which does this as well, without maintaining requirements.txt
by hand
# Create our virtual env
mkvirtualenv gist-platformio-explore
# `workon gist-platformio-explore` in future runs
# Install our dependencies
pip install platformio
# Init our project
# DEV: Verified name via `platformio boards attiny`
# https://docs.platformio.org/en/latest/core/quickstart.html
platformio project init --board attiny85
aaand damn, this requires folders...
Well... Let's work around that with symlinks I guess
ln -s ../main.cpp src/main.cpp
Aaaand build now
platformio run
Nice that it show how much RAM and Flash are used =D
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM: [ ] 1.8% (used 9 bytes from 512 bytes)
Flash: [= ] 8.3% (used 676 bytes from 8192 bytes)
Uploading via:
platformio run --target upload
Looks like it's running avrdude
, neato =)
Uploading .pio/build/attiny85/firmware.hex
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.00s
avrdude: Device signature = 0x1e930b (probably t85)
avrdude: erasing chip
avrdude: reading input file ".pio/build/attiny85/firmware.hex"
avrdude: writing flash (676 bytes):
Writing | ################################################## | 100% 1.09s
avrdude: 676 bytes of flash written
avrdude: verifying flash memory against .pio/build/attiny85/firmware.hex:
avrdude: load data flash data from input file .pio/build/attiny85/firmware.hex:
avrdude: input file .pio/build/attiny85/firmware.hex contains 676 bytes
avrdude: reading on-chip flash data:
Reading | ################################################## | 100% 1.02s
avrdude: verifying ...
avrdude: 676 bytes of flash verified
avrdude: safemode: Fuses OK (E:FF, H:DF, L:62)
avrdude done. Thank you.
Looks like it even has fuses listed out =D
-
DONE: What other frameworks are there? (as per
platformio.ini
)- Via demo (see later), we can see that
atmelavr
offers support for 2 platformsplatformio platform search attiny
- Frameworks: arduino, simba
- Teensy offers: arduino, mbed
- Arduino we know well ... -ish
- Simba, much more OS oriented than MCU oriented, https://simba-os.readthedocs.io/en/latest/library-reference.html via https://platformio.org/frameworks/simba
- Mbed, similar to Simba but a little bit more compatible with Serial and such (maybe just perception), https://os.mbed.com/docs/mbed-os/v6.3/apis/index.html via https://platformio.org/frameworks/mbed
- Via demo (see later), we can see that
-
DONE: It's odd we don't have to specify Tiny USB programmer. How does it know? Does it even know???
- DONE: Does this have to do with
platform
andboard
in theplatformio.ini
?- Via demo: https://docs.platformio.org/en/latest/core/userguide/demo.html
platformio platform search
to find full list, there's a lot of platforms (e.g. AVR, ARM (SAM), Teensy)- No idea what
board
means yet though... - Based on "quickstart", it seems board the microcontroller development board (e.g Arduino UNO) (makes sense)
- https://docs.platformio.org/en/latest/core/quickstart.html
- There doesn't seem to be a specific board for TinyISP (
platformio boards tiny
) butattiny85
"Generic ATtiny85" seems to work for us so far =D
- DONE: Does this have to do with
-
DONE: Explore their notes on debugging, unit testing, static code analysis, so many things!! =D
-
DONE: Check out
platformio device list
when we have a device connected, it might answer Tiny USB question Huh, interesting that there's no info when plugged in/dev/ttyS4 ---------- Hardware ID: n/a Description: n/a
Switching to Arduino UNO, we still see
/dev/ttyS4
but also:/dev/ttyACM0 ------------ Hardware ID: USB VID:PID=2341:0043 SER=XXX LOCATION=1-6:1.0 Description: ttyACM0
-
We can use
platformio ci
to build in CI (obviously no board testing here) -
Debug support intends to run it with GDB on the local computer, https://docs.platformio.org/en/latest/core/userguide/cmd_debug.html
- There's deeper IDE support potentially but that might be different from this (e.g.
debugWIRE
)
- There's deeper IDE support potentially but that might be different from this (e.g.
-
PlatformIO Home is a GUI tool for analysis and apparently collaboration
- https://docs.platformio.org/en/latest/home/index.html#piohome
- Really need local web server tool. Can inspect symbols and warnings, all in the window =D
-
Dependency management via
platformio lib
, neat -
pio
alias forplatformio
-
Supports client/server interaction for programming (this tool is so powerful ._.)
-
Testing seems rather verbose, https://docs.platformio.org/en/latest/core/userguide/cmd_test.html
- Can upload, can run against a test port
-
DONE: I see serial monitor notes in testing, I want to read how they handle this
- It seems their monitor is done via their VS Code IDE =/
- https://docs.platformio.org/en/latest/tutorials/espressif32/arduino_debugging_unit_testing.html
- SKIP: Is there any serial monitor which is read only? Like in the tests?
- Oh never mind! It looks like this just runs:
platformio device monitor
- Oooooh! These even have extensions =D
--- Available filters and text transformations: colorize, debug, default, direct, hexlify, log2file, nocontrol, printable, send_on_enter, time --- More details at http://bit.ly/pio-monitor-filters
- DONE: Play around with serial monitor
pio device monitor
, works great with Arduino UNO. Need to figure out debugging for ATtiny85
-
DONE: Dig into this test example more, seems straightforward but also intruiging... like they override loop? https://docs.platformio.org/en/latest/tutorials/core/unit_testing_blink.html
- So it probably talks back to computer via serial (since it says this)
- And really, there's nothing related to the
main.cpp
here =/ - It's more just verifying the constants are correct and
digitalRead/digitalWrite
work =/ - Decent demo I guess, odd though that it is essentially asserting itself...
-
SKIP: Play with unit test example, https://docs.platformio.org/en/latest/tutorials/core/unit_testing_blink.html
- Not vibing at the moment, reading was enough...
-
It seems that there is debugging support for ESP32 in IDE, unsure about other boards though...
-
Lots of neat options in config, https://docs.platformio.org/en/latest/projectconf/index.html
- It goes on... and on... ._.
-
List of platforms, frameworks, and boards
- https://docs.platformio.org/en/latest/platforms/atmelavr.html
- Oooh! We should say
upload_protocol = usbtiny
, I guess it works fine with the ISP commany but ours is different, right? - Actually, not what we use: https://learn.adafruit.com/usbtinyisp
- AVR ISP is the default I guess and that's what we use
- We can also set custom fuses in this same setup =D
- Notes about debug supported/not are listed which is neat, ATtiny85 says "on-board" so pretty sure that's debugWIRE
- For ESP32, they do list External at times, https://docs.platformio.org/en/latest/platforms/espressif32.html#boards DONE: Look into cores mentioned on Arduino framework page, https://docs.platformio.org/en/latest/frameworks/arduino.html https://github.com/MCUdude Each core is for a different set of cores, neat =)
Some boards seem to support external debug, https://docs.platformio.org/en/latest/frameworks/arduino.html#external-debug-tools
We can debug via simavr
apparently? https://docs.platformio.org/en/latest/boards/atmelavr/attiny85.html
DONE: Explore simavr
debugging
Ahh, seems to be local emulator. Not amazing but decent, https://github.com/buserror/simavr
DONE: Resume reading on debugging, https://docs.platformio.org/en/latest/plus/debugging.html Really digging these comprehensive docs so far =D
Build command for arduino_uno
:
platformio run --target upload --environment arduino_uno
DONE: Explore debugging options for ATtiny85, since built-in serial monitor doesn't work (likely due to pins). Prob should find out "why" more first Yep, need a serial adapter in our programmer as well as a UART serial (for easier sending of packets, not really required -- as per SoftwareSerial.h, https://github.com/quitmeyer/ATtinyBareDemos/blob/0ec44ca7192d9a40a2277fae36fba533626ec149/ATTinyAnalogInputTOSerial/ATTinyAnalogInputTOSerial.ino) https://arduino.stackexchange.com/a/24932 So prob easiest to figure out some I2C screen solution then =/ Buying extra hardware to just send back to computer seems silly https://www.instructables.com/Easy-ATTiny-Serial-Communication-with-Tiny-AVR-Pro/ This one just passes through RX and TX to ATtiny which is pretty smart, I guess if they're both running on 5V USB then we're good DONE: Explore downclocking Arduino UNO to have same timing as ATtiny85 DONE: Figure out what the 8x fuse they're talking about is and how to program it
; https://forum.arduino.cc/index.php?topic=154843.msg1160871#msg1160871
board_build.f_cpu = 8000000L ; 8MHz
Currently messing with fuses, seeing that we can't set them via board_fuses
as we expected
Exploring why...
Finding upload command is build + this avrdude
invocation (via run --target upload --verbose
)
avrdude -v -p attiny85 -C /home/todd/.platformio/packages/tool-avrdude/avrdude.conf -c usbtiny -e -D -U flash:w:.pio/build/attiny85/firmware.hex:i
https://www.ladyada.net/learn/avr/avrdude.html
It looks like we set fuses via -U
We tried to set -u
via upload_flags
just now to see if that would force it, no luck. Still no -U
for fuses being sent, I guess we can write it by hand. I'm just kind of scared ._.
Found the fix =D
We use platformio run -t fuses
instead of -t upload
https://community.platformio.org/t/how-to-set-fuses-file/9403/8
Our LED did bug out when we set the fuse the first time but it works I guess =D
The fuse is CKDIV8 fwiw, documented on p149 of ATtiny85 datasheet
Resuming on debugging, https://docs.platformio.org/en/latest/plus/debugging.html
- There are IDE debuggers in VS Code, as well as Sublime Text and Atom but VS Code is preferred
- Looks like there's also a debug CLI as well as lots of platforms
Linked Arduino tutorial: Use external device to connect to SWCLK, SWD, GND, RESET, and V_CC then debug in their IDE https://medium.com/@manuel.bl/arduino-in-circuit-debugging-with-platformio-9f699da57ddc
Most other tutorials listed are for wifi/bluetooth driven chips so easier setup/debugging
https://docs.platformio.org/en/latest/plus/debugging.html#boards List of boards says Uno is on board
https://docs.platformio.org/en/latest/boards/atmelavr/uno.html#debugging
Only listing is simavr
but maybe I'm misreading it?
https://community.platformio.org/t/debugger-for-arduino-uno-mega-and-esp8266/5307/7
Nope, as of Oct 2019 (1 year ago), there's no debugging interface without using something external
Yep, set up the IDE. Default tool is simavr
, nothing we can change to that I see (all lists are external tools)
Extra sanity: Lights are still blinking on our board despite breakpoints
Running pio debug --interface gdb
kind of works but doesn't start up program like VS Code
Running pio debug --interface gdb -x .pioinit
as noted does get us to the same point but visually there's a lot less feedback
(e.g. we don't see the program as it's running)
Watching a video on gdb
, https://www.youtube.com/watch?v=bWH-nL7v5F4
layout next
is something we were missing
That was a generally solid
Getting "TUI mode not allowed" now =/
Should prob see if this is specific to simavr
/PlatformIO or for all our C/C++ programs
Huh, using it with a C++ program allows for layout next
So maybe something is misconfigured with samavr
or it's part of the whole PlatformIO set up
Regardless, we can always use the IDE to debug I guess, and it's prob a lot faster than gdb
setup over and over
... Yep it's pretty slick. Delay is a little laggy but that's prob simavr
itself
Testing we've covered before
Can do change up target test filtering with .ini
setting which is handy, so do both embedded as well as CI testing
https://www.thingforward.io/techblog/2017-08-08-embedded-testing-with-platformio-part-2.html
Also works as CLI flag
Linters mentions for static code analysis, nice =D https://docs.platformio.org/en/latest/plus/pio-check.html
Skimming rest of content... remote dev, account, cloud/IDE, CI (run builds and tests as noted before)