The Firmware is Yours

A project log for SmartEE the Smart Plug

An Opensource Smart Plug

johnJohn 07/29/2015 at 17:530 Comments

The github repository now has all of the SAM4S source code under the firmware directory. Here's how to build it:

  1. Install the arm gcc toolchain (arm-none-eabi). This can be done easily with your distro's package manager
  2. Download the ASF library into a folder named [asf] inside the repository (on the same level as [inc] and [src]). You can download it here (free account required), and documentation can be found here.
  3. To compile the code simply run make. This should create a [bin] directory with the binary to flash to the SAM4S.
  4. For convenience the additional target [make gdb] can be used if you are using the Black Magic debugger. This automatically downloads the code to the chip and starts a GDB session. Before you run this make sure you authorize the .gdbinit file in the repository (if you don't GDB will complain and give you instructions on how to do this).
  5. By default the SAM4S boots the SAMBA bootloader code. To switch the chip to boot into flash (ie. run your code) set GPNVM bit 1. This can be done easily with the Black Magic probe in GDB:
    Loading section .text, size 0xd564 lma 0x400000
    Loading section .ARM.exidx, size 0x8 lma 0x40d564
    Loading section .relocate, size 0xa7c lma 0x40d56c
    Start address 0x407970, load size 57320
    Transfer rate: 39 KB/sec, 939 bytes/write.
    (gdb) mon gpnvm_set 1 1
    GPNVM: 0x00000002
  6. Please let me know if you have any questions! Happy smart plugging!