Posts

Programming an Arduino UNO with the Atmel ICE from macOS command line (or S4A IDE)

Hardware always makes it into the Swift for Arduino IDE by going through a trial on the macOS command line first. I have various test rigs that I use to get hardware and systems working there first. I found it pretty hard to find documentation on how to program using macOS / open source software (not using the AVR Studio IDE or MPLab). I've just bought a shiny, new ATATMEL-ICE programmer/debugger with cables for $100 and I'm itching to get it working. First task, make a simple blink program and upload it. Lots of obstacles! I'm putting some of the things I've found in here, if for no other reason than to save people several hours of googling. First, which program do we run to connect to the Atmel-ICE? It seems like for AVR, good old avrdude is OK. As is often the case, the cool community at Platform.IO have some discussion on it... https://community.platformio.org/t/upload-and-debug-for-atmega328p-with-atmel-ice/18796/2 Next problem, which cable?? OK, this page from Atm

Using C and C++ in projects

See a video demo here: https://youtu.be/OTcDzEyJw8Y A demo project is here: https://github.com/swiftforarduino/community/tree/master/contributed%20examples/Using%20C%20functions.swift4a From Swift for Arduino 4.3 onward, you can add C and C++ files into the build. Either import existing files, drag them into the file list or add new tabs with filenames ending .c or .cpp. You can also include header files for the .c and .cpp files to use. Each file is compiled by AVR GCC. standard avr-gcc for files ending .c and avr-g++ for files ending .cpp. Headers are not automatically imported to swift. To make definitions visible, add a file called main.h (or use the menu option to add a clang import header). This will be used as an import header and definitions will be visible to swift using the clang importer submodule of swift, with the usual restrictions. WORDS OF WARNING: We held back on adding this feature for a long time. It is not a good idea to just drag C or especially C++ files in here t

Dear Goodness

 I removed Xcode, but it has left its "command line tools" behind like a stain. I can't even delete them as root. This is ridiculous. This is how Apple gets a bad name for making your own machine not your own... rm: /usr/bin/make: Operation not permitted sh-3.2# cd /usr/bin sh-3.2# ls -l swift make -rwxr-xr-x  1 root  wheel  18288  4 May  2019 make -rwxr-xr-x  1 root  wheel  18288  4 May  2019 swift sh-3.2# open . sh-3.2# rm -r swift override rwxr-xr-x  root/wheel restricted,compressed for swift? y rm: swift: Operation not permitted sh-3.2# rm -rf swift rm: swift: Operation not permitted sh-3.2# ls -lO swift -rwxr-xr-x  1 root  wheel  restricted,compressed 18288  4 May  2019 swift sh-3.2# chflags -hv norestricted swift chflags: swift: Operation not permitted sh-3.2# whoami root sh-3.2# I mean... what do I do?!

Making C++ wrapper libraries for Swift for Arduino - part 1

I have just started adding a library to use the Adafruit Bluefruit LE, which is a great little shield made by Adafruit. Problem is, as ever, their software they give away is to make the shield work with Arduino/C++. What to do? Since version 2.9 of Swift for Arduino, it has been possible to use a special category of library files in addition to the usual ones from the community github site. Just like the usual library files, these are of the form XXX.swift, are all kept in the github community site for general use (https://github.com/swiftforarduino/community see the community libraries). This new type are named unsafeXXX.swift to be clear that they contain a core of unsafe C++ (usually legacy) code. In nearly every case, the code could be ported to pure swift at some point but it can be a lot of work, so in order to make it possible to get up and running faster and to leverage existing legacy code, it can be wrapped in Swift. The basic way this works is this: 1) make a new p

My opinions of code signing, notarising and the hardened runtime

 I had a long rant/chat on Slack about what I've figured out about code signing and notarisation after many late nights. Someone pointed out I should make a blog post about my opinions for posterity, even if it's not 100% accurate (I'm sure it's not), it will be helpful for some tidbits, hopefully. ... The way the bundle is structured, it has a standard structure, Contents containing the actual executable in MacOS, resources in Resources and helper service applications in XPCServices. The two services are the simduino plugin, which is basically a wrapper around simavr and the build engine. The main app is codesigned in the standard way, code signing is a slight misnomer. Carl  12:28 PM “Code signing” is essentially the same process as signing a document or file using PGP or GNUPG, the cryptographic program has a certificate and private key pair, which are equivalent to a public/private key pair in RSA signing, it takes the document, makes a cryptographically secure hash

Where do all my bytes go? ... an analysis of program size in an S4A 4.0 series application

You heard it here first, but coming this year, we are finally releasing the version 2 compiler, as part of Swift for Arduino release 4.0. This is a very exciting new development, with our own patched swift frontend and (most importantly) a custom built standard library, fine tuned for the atmega328p and the arduino uno.  There is most definitely nothing else like this anywhere in the world. Another first! As part of this launch, I'm going to try to do some more blog posts about day to day findings and experiences with making AVR/Arduino programs using our new compiler. As an example, I just compiled this program... import AVR SetupSerial() print("newer API") public let dummyArray = [1,5,9,112,0,1,4] print(dummyArray.count) while true {} This is a super simple program demonstrating some of the powerful new features of version 4.0, namely our custom made strings and our customised arrays. Both are super efficient on a microcontroller and we have removed some

Sipping power... sleep modes and Swift for Arduino

Image
One feature I have been meaning to add to S4A for a while now is sleep. It might not sound like an important feature but it could radically change the way projects are made. A critical distinguishing feature of S4A is that it creates true native programs for the atmega328p microcontroller, meaning you don't need to have an Arduino UNO, plugged into your laptop or desktop via USB for these programs (although of course you can). This sets it aside from many other attempts to simplify Arduino programming in the past, that effectively run programs on a full PC/Mac then send serial commands to the board to activate it. The next step... how do you make a project that lives on batteries? Well, right out of the box you can do that, at least for a while. See my Hallowe'en project from last year on this blog that I made for my daughter. But that lasted a couple of days on batteries before it faded. Anything with lots of lights and motors is going to need a lot of battery, of co