Lessons learned compiling a C program


In order to compile C programs, you need to bring up the CHIP SDK. Here’s a list of things the doc didn’t tell me. Much of this info was derived from other posts to this forum. Thanks to all who shared!

  • A Mac will not be able to flash the full CHIP OS (option 3 under http://docs.getchip.com/chip.html#flash-chip-firmware). The image is too large for the normal download, and fastboot doesn’t work with the Mac. Fortunately, I’m happy with the Debian OS (option 2).

  • When following the instructions at http://docs.getchip.com/chip.html#installing-c-h-i-p-sdk everything goes smoothly until the Vagrant VM is brought up for the first time. After using “vagrant ssl” to log into the VM, the files are owned by root instead of the vagrant user. So before doing anything else, enter:

    sudo chown -R vagrant: /home/vagrant

This changes the files to be owned by the vagrant user.

  • The Mac’s “screen” command seems doesn’t like CHIP’s “nmtui” output. But the Vagrant VM’s “screen” command seems to handle CHIP’s “nmtui” output much better, and has some advantages. So use “screen” from the VM. The device name in the VM seems to always be “/dev/ttyACM0”.

  • I’ve seen cases where the Vagrant VM doesn’t recognize the USB connection unless it is connected while the VM is running. If “screen” complains that /dev/ttyACM0 can’t be accessed, try unplugging CHIP and re-plugging it. (Then you’ll have to wait 20 seconds or so for CHIP to boot enough to be recognized.)

  • You need to set up the WIFI. The easy way is to log onto chip and run the “nmtui” command:

    screen /dev/ttyACM0 115200

Hit an extra return to get the login prompt. Log in with chip/chip.

    sudo nmtui

The “sudo” command may prompt you for the chip account password, chip.


Ignore the “lo” section. The second line of the “wlan0” section shows the IP address after “inet addr:”. Take note of that IP address, but also be aware that this address can change. If you need the IP address to stay constant, you’ll have to configure it.

  • To compile a C program, you can’t use the normal C compiler. You need a cross-compiler. But the Vagrant VM doesn’t start out with the cross-compiler available. So after changing file ownership (above), enter:
    cd CHIP-buildroot
    make chip_defconfig
    make nconfig

After building nconfig, it automatically runs it. Just enter F9 to exit. Then enter:

    make toolchain

This takes a few minutes to run, after which the compiler and linker are ready to go.

  • To compile the C program “HelloWorld.c”, you’ll want to create a script:
    /home/vagrant/CHIP-buildroot/output/host/usr/bin/arm-linux-gnueabihf-gcc \
        -I/home/vagrant/CHIP-buildroot/output/host/usr/arm-buildroot-linux-gnueabihf/sysroot/usr/include/uapi \
        -I/home/vagrant/CHIP-buildroot/output/host/usr/arm-buildroot-linux-gnueabihf/sysroot/usr/include \
        -I/home/vagrant/CHIP-buildroot/output/host/usr/arm-buildroot-linux-gnueabihf/sysroot/usr/include/uapi \
        -I/home/vagrant/CHIP-buildroot/output/host/usr/arm-buildroot-linux-gnueabihf/sysroot/usr/include \
        -I. -Os hello.c -o hello
  • Now transfer it to CHIP. If CHIP’s IP address is, enter:
    scp hello chip@

Commands and libraries for manipulating IO and serial port in C

I know this isn’t cross-compiling, but if you install gcc and make, you can build the program natively on the CHIP.

apt-get install gcc make


make hello

Hope this helps.



For small programs, that’s a great approach. As the programs get longer and more complex, a more powerful development platform will be very handy.

I was going to complain about the disk space gcc would consume, but after trying your suggested apt-get just now, I see it only increased my disk usage by 1%. :slightly_smiling:

Oh, and here’s another lesson learned. Before I could successfully do any apt-get installs, I first had to:

    apt-get update


And then do “apt-get upgrade”…

Now that you have your cross-compiling setup finished, there is another possibility. I don’t know about setting up an NFS share on the Mac, but I did that for compiling on the ci20 board. I was able to compile the kernel using the native compiler across NFS to a disk on my linux workstation. It wasn’t fast, but it did compile. It was an interesting experiment. (It didn’t help – native and cross-compiled kernels were nearly equivalent. What I did learn was to properly answer the kconfig questions, you really have to know the hardware.)


To get nmtui working when using screen from a Mac, execute


before running nmtui.


Great write-up. However how do you get access to kernel headers like i2c sysfs etc on the vagrant box?
Seems like a major limitation


I don’t attempt to actually run programs on the Vagrant box. You couldn’t since the cross compiler produces binaries for CHIP’s CPU, not X86. Cross compilation is only intended to build programs.

FYI - I basically don’t use this procedure any more. I build my code right on the CHIP.