-
Notifications
You must be signed in to change notification settings - Fork 3
Allow a build with CMake and avr-gcc #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow a build with CMake and avr-gcc #3
Conversation
|
Well done @ian-arkver! I guess the .hex could be generated with AVR's |
|
Yeah, that would be the next step. I just now generated some hex as you suggest...
but I've not added it as a custom command to the cmake file. |
Thanks! Please do add it to the build infrastructure, I'll use your changes, add mine and give that .hex a go next Tuesday ;) |
Include min pagesize workaround for avr-gcc version 12 bug, see here: https://gcc.gnu.org/bugzilla//show_bug.cgi?id=105523
|
I added the other compile flags to match the ones in Debug/Makefile. If you're going to try this on hardware these might be necessary. The F_CPU one is probably critical. These flags included -Wall and avr-gcc version 12 has a bug. |
Not that it seems to make any difference.
|
Thanks Ian! Just getting ready for tomorrow, I'm hitting some snags with this branch: What am I doing wrong? |
|
The min-pagesize workaround is for a bug in gcc 12. You're using 11 which doesn't have the option. You can just remove the "--param=min-pagesize=0" line from the compile options. In theory cmake should be told to add the flag dependent on the compiler version, but again this should really be moved out to a toolchain file instead. Feel free to fix it up. :-) |
|
Thanks for the flag suggestion, I'm no CMake expert (so it'd take a while for me to implement that compiler conditional), but I found more issues after removing that flag... in which OS did you build it, btw?: |
|
Hi Roman, I use the avr-gcc package for the compiler and avr-libc for the runtime. Both these are official packages on my distro, Manjaro, which is an Arch derivative. In particular ctype.h is a standard include from the runtime and in my system is found here: From the error I'd guess you have the compiler but not the runtime library installed, or else the default compiler include path doesn't search wherever the runtime is installed, which would be a bug in your distro's packaging. You can check the paths with: Hope this helps. |
|
Fixed the warnings but again those files had inconsistent line endings, so vscode has unified them causing spurious whitespace diffs. |
Indeed, silly me, for some reason I thought that Now, comparing the resulting objects from Atmel Studio vs yours, there's a few (big) differences: This branch's object sizes: Atmel studio's sizes: So the target .hex delta is around 20KB, so I'll assume that the differences are due to Debug So checking out the function count of the target hexes and comparing: There are indeed 38 functions missing (or at least those that radare2 can detect side by side): I'll check further what you meant by |
|
Hi Roman, I guess function count differences could be due to compiler/libc version too. Maybe the LTO in gcc 12 is better at inlining stuff. Radare2 looks interesting - hadn't come across that before. F_CPU is used in (among other things) software delay loops. If it's wrong (or unset and defaults to something wrong) then those loops will delay for the wrong time. I haven't looked at TinyG code to see if it uses SW delays or what the effects of them being wrong would be. I copied the F_CPU setting from the original Makefile so it should hopefully be ok. I noticed comments on the OpenPnP group recently that flashing the TinyG will scrub any settings you have stored. Just a heads-up. Good Luck! |
It's awesome, been using it for a few years now on and off, totally recommended.
Yeah, I'm aware of that since it bit me in the past and reported it to Mark, he kindly included the recommendation of backing up |
|
Just noticed the edit - so... You flashed the cmake built hex and it worked ok? |
Not yet, next Tuesday is my next window of opportunity, I only go to CCHS on Tuesdays ;) |
|
Ah right, ok. Good luck, bring a backup. :-) |
|
Cool stuff guys, appreciate a lot! |
|
@ian-arkver you're a
|
Forgot the link TinyG/firmware/tinyg/canonical_machine.c Line 853 in a61772d
_Mark |
at Mark's suggestion since settings_openpnp.h is of unknown quality.
|
@markmaker We were focused on getting the ADC to work wit Atmel Studio branch first in #2 , but we hit some problems with the capacitor value in combination and the Mikroe Vacuum Sensor... here's the last checkpoint in our investigation by Anthony: We are getting this nasty 2-4Mhz signal on the scope and the ADC just doesn't work when the TinyG board is fully initialized: funnily enough it works when is still booting and we see the sensor reporting the right vacuum level through the voltage on the oscilloscope. So the recommendation from TheReza on the Liteplacer forum might interfere with our needs with our particular sensor... we'll test more about this soon. We wanted to flash @ian-arkver's @markmaker If you still have a TinyG board, go ahead and flash Ian's .hex? Otherwise you'll have to wait until the next window of opportunity (Tuesdays). |
|
I've reverted the settings_openpnp.h change and fixed up the cmake file so it only uses the gcc 12 fix if the gcc version is greater than 12.0 This might need revisited if/when Gnu fix the bug. I've added an invented FEATURE_TAGS section to the M115 response with a '/' separated list of tags which are currently OPENPNP and CMAKE. I've not cherry-picked the ADC change so I haven't added an ADC feature tag. I also haven't bumped the firmware version since it seems that's what causes the settings to be scrubbed... |
|
@markmaker I don't have a TinyG so I've no idea whether settings_openpnp.h is better or worse so just undid the change as you suggested. And yeah, your build runes look fine. Personally I like to use VSCode with CMakeTools extension so building is a one-click operation, but using cmake from the command line is also easy. |
|
It would be nice if someone who has an Atmel Studio setup and a TinyG can confirm that this series doesn't break that build chain. It shouldn't. In that case I think this could be merged as the other changes are specific to building with CMake. Once merged then perhaps the ADC-enabling branch can be rebased/merged to include this. |
I wish it was! Unfortunately our TinyG board (and xmega) does not seem to have I2C bus, so it'd have to be bit-banged, which is not good IMO. Instead we are using the
The board is fairly well decoupled/tested I reckon and we found the culprit anyway as mentioned on the OpenPnP ML.
I think that the board is built to accommodate different target voltages and target applications, haven't looked deeper into that either.
|
|
Well, finally we managed to tame the ADC situation with our current firmware (sans 100Hz) today and tidied/low-pass-filtered it all up with a custom board. It got pretty late and I was about to test this branch on our PnP... But I forgot to bring my Linux machine (🤦🏻 ) so I only had my mac with me and unfortunately it fails to compile on OSX: I was about to go through the rabbit hole and fix it, but I'm afraid it'll have to be another day next week :_/ |
|
Thanks for the PR merge @ian-arkver! @markmaker I reckon this can be merged, actually? :) |
|
Thank a lot @brainstorm and @ian-arkver ! It has been a long time and I would like to be current with the status of this. Could any of you elaborate a bit? Some stuff is in the Description, but it seems a bit terse.
The intention is to get "Instructions for Use" for posterity. Best revise the Description to reflect the latest state. Thanks again! 💯 🥇 |
|
@markmaker Added some runes. It's far from exhaustive but hopefully enough to get started. This changeset is unrelated to the ADC changes afaik. |
|
Agreed, please ignore the ADC stuff Mark. Those changes were made by my initial motivation with a previous PR but those are closed and the problem with the EEPROM is resolved as well. I haven't tried to compile this on windows, I don't even know how devs would like to work with this on windows: cygwin and WSL2 should work out of the box, though, other than that, no idea. |
|
The description should point out that there's a resulting .hex file, not just .elf as the former is what's actually flashed via avrdude on the TinyG board. |
|
Thanks, @ian-arkver, that's brilliant. I wonder if we should throw out all the AtmelStudio and .xcodeproj stuff, so nobody tries to still use them (I'm assuming those no longer work, or at least we don't want to give the impression they are supported anymore). There were also build artifacts checked in. I think we should at least check-in the .hex as before, so users can directly install it without having to build. But probably not in the Btw. the cmake build is a release build, right? _Mark |
|
Default cmake build is debug I think. I'll add Will look at these this evening hopefully. |
|
Though actually my CMake file is a bit hacky and overrides the default optimisation: |
|
@markmaker I pushed one more commit to make the optimisation flags depend on build mode and added more details to the comment section on that. The custom command to generate the hex was already there, I just changed the comment above to mention that the hex file was also created. It's in the same build dir. ps. Re cleaning out the old build system - that's not really my call, it's yours for your fork of tinyg and synthetos's for upstream. Personally I'd wait a while after merging this for people to migrate and test the flow in windows/mac/other-linuxii and then maybe add a "Old buildsystem deprecated, will be removed" note to the README or something, then maybe a year from now... pull the rug. |
|
I agree about removing the other build systems. But I still think you should check-in the This also helps with future features / PRs and their community testing. |
|
Hi @markmaker . Hex files are explicitly ignored in the .gitignore in the firmware dir. Also tinyg.hex is ignored at the dir level above. Are you sure you want me to remove these so tinyg.hex can be tracked? |
|
yes, you can override gitignore with the -f flag. On 30 Mar 2024, at 17:26, ian-arkver ***@***.***> wrote:
Hi @markmaker .
Hex files are explicitly ignored in the .gitignore in the firmware dir. Also tinyg.hex is ignored at the dir level above. Are you sure you want me to remove these so tinyg.hex can be tracked?
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: ***@***.***>
|
|
@markmaker OK, added with -f as you suggested, pushed. |
|
Great, many thanks! 💯 |
|
Thanks Mark. |
|
btw, as I mentioned earlier in this thread, I don't have a TinyG board, so this is completely untested by me. |
|
All the more thanks for your self-less work! 🥇 I do have a board but I don't think I'll find time to test it anytime soon... but this is is not pressing either. |


This series adds a basic CMakeLists.txt to compile the code using avr-gcc. It fixes some multiply defined symbols due to static variables in header files. It generates the elf output, but has not been tested on real hardware. More work is probably needed to add things like hex file generation.
The compiler and target selection is hard coded into the main CMakeLists file. Ideally this would be a separate toolchain file, but only the specific TinyG SoC is needed.
The line endings in the codebase seem to be mixed within each file. The editors I tried like to unify them, so the second commit has unintentional whitespace changes unfortunately. It might be better to fix these all at once, but that's an upstream task I think.
Usage instructions:
Install a version of GCC for AVR on your development machine.
For example on Manjaro use
sudo pacman -S avr-gccor on a Ubuntu flavour something likesudo apt install gcc-avr avr-libcmight work. For Windows and Mac perhaps look at Microchip's site. Ensure the compiler is on your PATH. Also ensure CMake is installed and a build system like make or Ninja.Clone the TinyG repo and cd into the source
cd TinyG/firmware/tinygMake a work dir to build in, change into it
Make the Makefiles or Ninja files. Build.
One of the following. Change Release to Debug if you want debug symbols in the elf and less optimisation.
Using Ninja:
or using make and assuming an 8 thread CPU:
Result is in tinyg.elf with a hex dump file in tinyg.hex