Combining the BBB with an ATmega328p

Lastly, the CryptoCape contains an independent microcontroller. This microcontroller is the ATmega328p, which is the same microcontroller on the Arduino UNO. However, because the supply voltage is 3.3V and not 5V like the Arduino UNO, the processor runs at a clock speed of 8MHz versus 16Mhz. In this sense, it is more like the 3.3V Arduino Pro Mini. Shipped from SparkFun, the CryptoCape contains the 3.3V Arduino Pro Mini bootloader. Like any other Arduino-based board, you can reflash the bootloader by attaching an In-System Programming (ISP) programmer to the ISP headers next to the ATmega328p. SparkFun's pocket programmer is an inexpensive tool to perform this task. Just be sure to set the switch to no power target since the CryptoCape is powered from the BBB.

While you can use an ISP programmer, you can also use the BBB as a programmer. The BBB contains both serial UART and SPI; however, only the serial UART, UART 4, is connected to the onboard ATmega328p. Like the Arduino UNO, if the microprocessor is reset, it will accept uploaded programs over the serial line.

A simple script that toggles the BBB GPIO connected to ATmega's reset line, which is GPIO 49 for the CryptoCape, and then uploads the hex file using avrdude will do the trick. The script is part of a GitHub repository which can be cloned with the command:

git clone https://github.com/jbdatko/BBB_ATmega328P_flasher.git

In this repository, there is an upload.sh script, the main logic of which contains the following code snippet:

(echo 0 > /sys/class/gpio/gpio49/value 
    && sleep $tts 
    && echo 1 > 
    /sys/class/gpio/gpio49/value) &

avrdude -c arduino -p m328p -b 57600 -v 
    -P /dev/ttyO4 -U flash:w:$1

The first part toggles the ATmega reset line low and sleeps for $tts, which is currently defined to be .9 seconds. Then the script sets the reset line back to high to let the ATmega run. The next line is the avrdude command to upload your hex file. You'll need to install avrdude with the following command:

sudo apt-get install avrdude

Then, to run the script, perform the following:

sudo ./upload Blink.cpp.hex

Prior to flashing an Arduino sketch, you must have a sketch to flash. Depending on your development preference, there are several options. You can build your AVR program on the BBB with a makefile and gcc-avr. Or you can build your program with Atmel's free AVR Studio or the Arduino IDE. Whichever way you choose, you need to find the compiled hex file and download it to the BBB using sftp or a similar tool.

Before you upload sketches to the CryptoCape's ATmega, you'll need to perform one very important step: you need to attach jumpers to the two Program Jumper pins. Without the jumpers, the ATmega is not electrically connected to the BBB serial lines. This is a security feature. Using the Arduino bootloader, it is possible to upload hex files using serial UART. Thus, with the jumpers installed, the sketch on the CryptoCape's ATmega can always be modified. Now imagine if the BBB was inflicted with malware, but had the jumpers removed. This malware can't change the software on the ATmega. It can still do lots of other nasty things including resetting the ATmega, but it can't upload new firmware unless the jumpers are attached.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.244.250