Example dimmer project for running SimAVR (with an ATTINY85)

Hi,

Just made a project using PlatformIO that demonstrates a button-controlled dimmer implemented on the ATTINY85, and simulated using SimAVR: https://github.com/RobustoFramework/ATTINY_dimmer/tree/main

It was quite difficult to make it work with the dependencies, got quite misled into creating all kinds of python scripts, and misunderstanding the not overly easy-to-understand documentation, but I think I’ve gotten the hang of it now.

Only tried on MacOS, will make a try on Docker/Linux in august, I think.
BTW, I haven’t gotten simavr to build on windows yet, seems to be pretty difficult, at least to me, certainly not my forte.

I’ve done that some time ago and automated it with Github Actions:

https://github.com/maxgerhardt/simavr/tree/combined_fixes_and_ci
https://github.com/maxgerhardt/simavr/blob/combined_fixes_and_ci/.github/workflows/build.yml

Binaries:

https://github.com/maxgerhardt/simavr/releases/tag/pio-release

Thanks!
For some reason I have totally missed the release page of the project.
Facepalming hard over here, thanks again.

I’ve updated the CI again, the branch with the custom fixes for GDB is sadly broken but the one “verbatim” one compiles (with tiny fix) fine for all OSes:

https://github.com/maxgerhardt/simavr/actions/runs/9536362328

In fact, simavr debugging still works fine with that version.

https://github.com/maxgerhardt/pio-simavr-testing

That’s now also PRed at

1 Like

(i realized that that was your branch, so perhaps I wasn’t that off after all then. :slight_smile: )
I tried with ghd pio-release 2 and that didn’t build, though:

gcc -o .pio\build\client_windows\program.exe .pio\build\client_windows\client\client.o -L.pio\build\client_windows -LC:\Users\Nickl\dev-deps\tool-simavr\lib -Wl,--start-group -lsimavr -lelf -Wl,--end-group
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\client_windows\program.exe] Error 1

Ah but it does compile on the commandline for me on Windows. Used compiler GCC 14.1.0 from here, SDL2 MinGW dev libraries from here, libelf from here and command

gcc -o client.exe -D "FIRMWARE_PATH=\"firmware.elf\""  -I "C:\Users\Max Gerhardt\Downloads\Windows.64-bit\include" -I "C:\Users\Max Gerhardt\Downloads\SDL2-devel-2.30.3-mingw\SDL2-2.30.3\x86_64-w64-mingw32\include" -L "C:\Users\Max Gerhardt\Downloads\SDL2-devel-2.30.3-mingw\SDL2-2.30.3\x86_64-w64-mingw32\lib" -L "C:\Users\Max Gerhardt\Downloads\Windows.64-bit\lib" -L "C:\Users\Max Gerhardt\Downloads\mingw-w64-x86_64-libelf-0.8.13-7-any.pkg.tar\mingw-w64-x86_64-libelf-0.8.13-7-any.pkg\mingw64\lib" client.c -lsimavr -lelf -lmingw32 -lSDL2main -lSDL2 -lws2_32

With 2 tiny source code fixed in client.c

#waning "This is currently only tested on a Mac, dude." --> #warning "This is currently only tested on a Mac, dude."
int main() ---> int main(int argc, char** argv)

Plus copying in the SDL2.dll and the firmware.elf in the same folder as the generated client.exe, it does run.

Not sure what it does, though.

It is a one button dimmer. If you hold down a button, it will fade up and down and if you short-click it will turn on and off (se the README.md)

Hm, the fixes (#waning?) and .dll didn’t help, seems to stop at the linker.
This was what happened when I tried to build the library directly myself (notably with gcc 13.2.0, but that shouldn’t be a problem, also you have some 32bit params):

PS C:\Users\Nickl\Projects\I2C_dimmer> pio run -t exec -e client_windows -vvv
Processing client_windows (platform: native; build_flags: -D FIRMWARE_PATH=\"C:\Users\Nickl\Projects\I2C_dimmer\.pio\build\client_windows\firmware.elf\", -IC:/Users/Nickl/dev-deps/tool-simavr/include, -LC:/Users/Nickl/dev-deps/tool-simavr/lib, -IC:/msys64/mingw64/include/, -LC:/msys64/mingw64/lib/, -lSDL2, -lSDL2main, -lsimavr, -lelf, --verbose; build_src_filter: +<../client/client.*>, -<main.*>, -<../test/*.*>; platform_packages: platformio/tool-simavr, platformio/toolchain-atmelavr; upload_speed: 115200)
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
PACKAGES: 
 - tool-simavr @ 1.10700.210831 (1.7.0)
 - toolchain-atmelavr @ 3.70300.220127 (7.3.0)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 0 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
gcc -o .pio\build\client_windows\client\client.o -c --verbose -DPLATFORMIO=60115 -DFIRMWARE_PATH=\"C:UsersNicklProjectsI2C_dimmer.piobuildclient_windowsfirmware.elf\" -Isrc -IC:\Users\Nickl\dev-deps\tool-simavr\include -IC:\msys64\mingw64\include client\client.c
Using built-in specs.
COLLECT_GCC=gcc
Target: x86_64-w64-mingw32
Configured with: ../gcc-13.2.0/configure --prefix=/ucrt64 --with-local-prefix=/ucrt64/local --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --with-native-system-header-dir=/ucrt64/include --libexecdir=/ucrt64/lib --enable-bootstrap --enable-checking=release --with-arch=nocona --with-tune=generic --enable-languages=c,lto,c++,fortran,ada,objc,obj-c++,jit --enable-shared --enable-static --enable-libatomic --enable-threads=posix --enable-graphite --enable-fully-dynamic-string --enable-libstdcxx-filesystem-ts --enable-libstdcxx-time --disable-libstdcxx-pch --enable-lto --enable-libgomp --disable-libssp --disable-multilib --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-libiconv --with-system-zlib --with-gmp=/ucrt64 --with-mpfr=/ucrt64 --with-mpc=/ucrt64 --with-isl=/ucrt64 --with-pkgversion='Rev6, Built by MSYS2 project' --with-bugurl=https://github.com/msys2/MINGW-packages/issues --with-gnu-as --with-gnu-ld --disable-libstdcxx-debug --enable-plugin --with-boot-ldflags=-static-libstdc++ --with-stage1-ldflags=-static-libstdc++
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 13.2.0 (Rev6, Built by MSYS2 project)
COLLECT_GCC_OPTIONS='-o' '.pio\build\client_windows\client\client.o' '-c' '-v' '-D' 'PLATFORMIO=60115' '-D' 'FIRMWARE_PATH="C:UsersNicklProjectsI2C_dimmer.piobuildclient_windowsfirmware.elf"' '-I' 'src' '-I' 'C:\Users\Nickl\dev-deps\tool-simavr\include' '-I' 'C:\msys64\mingw64\include' '-mtune=generic' '-march=nocona' '-dumpdir' '.pio\build\client_windows\client\'
 C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/cc1.exe -quiet -v -I src -I C:\Users\Nickl\dev-deps\tool-simavr\include -I C:\msys64\mingw64\include -iprefix C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/ -D_REENTRANT -D PLATFORMIO=60115 -D FIRMWARE_PATH="C:UsersNicklProjectsI2C_dimmer.piobuildclient_windowsfirmware.elf" client\client.c -quiet -dumpdir .pio\build\client_windows\client\ -dumpbase client.c -dumpbase-ext .c -mtune=generic -march=nocona -version -o C:\Users\Nickl\AppData\Local\Temp\cc5AZ0oh.s
GNU C17 (Rev6, Built by MSYS2 project) version 13.2.0 (x86_64-w64-mingw32)
        compiled by GNU C version 13.2.0, GMP version 6.3.0, MPFR version 4.2.1, MPC version 1.3.1, isl version isl-0.26-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/include"
ignoring duplicate directory "C:/msys64/ucrt64/lib/gcc/../../lib/gcc/x86_64-w64-mingw32/13.2.0/include"
ignoring nonexistent directory "D:/a/msys64/ucrt64/include"
ignoring nonexistent directory "/ucrt64/include"
ignoring duplicate directory "C:/msys64/ucrt64/lib/gcc/../../lib/gcc/x86_64-w64-mingw32/13.2.0/include-fixed"
ignoring nonexistent directory "C:/msys64/ucrt64/lib/gcc/../../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/include"
ignoring nonexistent directory "D:/a/msys64/ucrt64/include"
#include "..." search starts here:
#include <...> search starts here:
 src
 C:\Users\Nickl\dev-deps\tool-simavr\include
 C:\msys64\mingw64\include
 C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/include
 C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../include
 C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/include-fixed
End of search list.
Compiler executable checksum: 6bc5f38fc21a55e2f492a9e22ec8936c
client\client.c:17:2: warning: #warning "This is currently only tested on a Mac, dude." [-Wcpp]
   17 | #warning "This is currently only tested on a Mac, dude."
      |  ^~~~~~~
COLLECT_GCC_OPTIONS='-o' '.pio\build\client_windows\client\client.o' '-c' '-v' '-D' 'PLATFORMIO=60115' '-D' 'FIRMWARE_PATH="C:UsersNicklProjectsI2C_dimmer.piobuildclient_windowsfirmware.elf"' '-I' 'src' '-I' 'C:\Users\Nickl\dev-deps\tool-simavr\include' '-I' 'C:\msys64\mingw64\include' '-mtune=generic' '-march=nocona' '-dumpdir' '.pio\build\client_windows\client\'
 C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/as.exe -v -I src -I C:\Users\Nickl\dev-deps\tool-simavr\include -I C:\msys64\mingw64\include -o .pio\build\client_windows\client\client.o C:\Users\Nickl\AppData\Local\Temp\cc5AZ0oh.s
COMPILER_PATH=C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/;C:/msys64/ucrt64/bin/../lib/gcc/;C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/
LIBRARY_PATH=C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/;C:/msys64/ucrt64/bin/../lib/gcc/;C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/lib/../lib/;C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../lib/;C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/lib/;C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../
COLLECT_GCC_OPTIONS='-o' '.pio\build\client_windows\client\client.o' '-c' '-v' '-D' 'PLATFORMIO=60115' '-D' 'FIRMWARE_PATH="C:UsersNicklProjectsI2C_dimmer.piobuildclient_windowsfirmware.elf"' '-I' 'src' '-I' 'C:\Users\Nickl\dev-deps\tool-simavr\include' '-I' 'C:\msys64\mingw64\include' '-mtune=generic' '-march=nocona' '-dumpdir' '.pio\build\client_windows\client\client.'   
gcc -o .pio\build\client_windows\program.exe .pio\build\client_windows\client\client.o -L.pio\build\client_windows -LC:\Users\Nickl\dev-deps\tool-simavr\lib -LC:\msys64\mingw64\lib -Wl,--start-group -lSDL2 -lSDL2main -lsimavr -lelf -Wl,--end-group
collect2.exe: error: ld returned 5 exit status
*** [.pio\build\client_windows\program.exe] Error 1

Mhm. There isn’t any actual error message. The linker just exits (or crashes?) with error code 5.

I added the GCC from as referenced winlibs.com, yours seems to be in that msys64/ucrt64 MSys2 environment, I don’t know if you can just call into that compiler from your regular Windows environment instead of from a ucrt64 shell. (And also I would use MinGW64 instead of ucrt64).

Plus you’re missing a few of the linker options

1 Like

The -lws2_32 and -lws2_32 options was the solution!
Thanks for all your help!

(much too fast on my new computer however, added a note on that)