> Sford wiki > CHIP lessons
In order to compile C programs, you need to bring up the CHIP SDK. Here's a list of things the CHIP doc didn't tell me. Much of this info was derived from other posts to the CHIP forum. Thanks to all who shared! (An early version of this article is also in the forum, and I've been trying to keep this article up-to-date with good replies that have been posted.)
- When following the instructions at http://docs.getchip.com/#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".
- - One specific reason to use "screen" instead of "cu" is that, by default, both "cu" and "ssl" use tilde (~) as the escape character. So if you want to exit "cu" and hit "~.", it actually exits completely out of the "vagrant ssl"
- 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.
ifconfig
- 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 10.0.0.20, enter:
scp hello chip@10.0.0.20: