Go bananas with Banana Pi!

Go bananas with Banana Pi!

444

We went through the names of few NB-IoT modems currently available in the market in our last post. And then we laid our hands on this interesting piece of circuitry called the Banana Pi. If you are into the whole single board computer thing you might think its a raspberry pi knockoff. The initial banana pi is actually a single board computer similar to the raspberry pi and the orange pi (yes <fruit name> +pi is a naming convention for SBCs) with a ARMv7 processor running linux. Now Banana Pi is a popular brand in the industry and many different models with an array of ARM processors can be found. The banana pi we have  is not a single board computer, but a microcontroller board with a powerful STM32 series microcontroller. Turn it around and you will see a BC-95 NB-IoT modem in all its awesomeness.

To add to the excitement you will see that it has a 40 pin header for I/O pins and a battery terminal for directly connecting a 3.7V li-ion cell or couple of AA cells. All these are essential ingredients for a neat IoT device comes in a small 60mm x 30mm package.
In summary the Banana PI Linaro has
  • STM32F103R microcontroller running at 72MHz
  • 128kB program flash memory
  • 20kB SRAM
  • 51 GPIOs
  • UART
  • I2C
  • SPI
  • PWM
  • BC95 NB-IoT Modem
  • 3.7V Li-Ion and 5V power input
  • 5 LEDs + 1 power LED
However the Banana Pi, with its STM32 microcontroller, poses few challenges to the developer unless you are familiar with IDEs like Keil and have access to a STLink programmer. If you are an Arduino fan and is now accustomed to the convenient way that things can get done with an Arduino, trying to learn programming the STM32 with Keil (which is an IDE for ARM based processors) might be intimidating. But the silver lining is that the good guys at Leaf Labs have an Arduino IDE compatible bootloader – Maple and the necessary IDE plugins – libmaple to get you up and running in no time. Let us see how you can setup the Banana Pi Linaro with your favourite Arduino IDE and Maple
Step 1: Install the Arduino board for STM32

In order to use your board with the Arduino IDE, the first step is to install the board definition.
  • Open your Arduino IDE. We tested this on 1.6.10
  • Go to Tools > Board > Board Manager
  • Search for ‘Maple Mini’ as shown below and install the STM32F1xx by stmduino board
When the board is installed, you will be able to see that there are few board definitions that are added as shown below.
Out of the newly installed boards, we are interested in the STM32F103R series, which is the tiny powerhouse we have in our Banana Pi. Like any other Arduino board you will also get the samples for the board under File >Examples >A_STM32_Examples
Step 2: Install Maple bootloader on microcontroller
 
If you are lucky enough to get your hands on a Banana Pi with Maple bootloader, you can skip this step. Else read on..
In order to flash a firmware to a microcontroller, usually you need a dedicated programmer for this task such as a PiCKit for PIC microcontrollers and AVR ISP for Atmel AVR microcontrollers. However an easier option is to use a bootloader. A bootloader is a small piece of code that runs for few seconds when the microcontroller is started to check for new firmware over Serial or USB and writes the new firmware to the program memory if available. Arduino has many different bootloaders available for AtMega 328, AtMega 2560 chips by Atmel such as Uno, nano, Mega, Diecimilia etc. in their boards. This makes it very convenient to program a microcontroller right from the IDE (such as Arduino) since it does not need a programmer hardware. All this time you have played with your Arduino, you have been using Atmel chips with Arduino bootloaders programmed via the Arduino IDE. A programmer is needed only to flash the bootloader, which needs to be done only once.
 
The STM32F103 microcontroller we have in our Banana Pi has its own method of firmware update using a special protocol called DFU. Device Firmware Update (DFU) is a standard protocol used to flash firmware updates to devices over USB. Most middle to high end microcontrollers have in built DFU for conducting firmware updates. The STM microcontroller in our Banana Pi has DFU and in built USB which enables it to flash firmware very easily. This is different to how things are done in an Arduino board with a ATMEL microcontroller where a USB-Serial bridge (FTDI232, PL2303 etc.) connects the host PC USB with the microcontroller USART0. This is because the ATMega 328 or ATMega 2560 microcontrollers in standard Arduino Uno, Nano or Mega boards (except the Leonardo) do not have in built USB ports. Therefore once you plug in the Banana Pi to the PC, it should be detected as a DFU device since DFU device drivers usually comes with any modern Windows OS. We will show how it can be done in Ubuntu in a later post.
If what you read above sounded greek, fear not, as there is a easy way out. The maple bootloader enables you to use the STM just like an Arduino.To make an STM work with Arduino IDE with the board that we installed in the previous step, you should write the Maple bootloader to the STM which is a one time thing. You can find a good resource on how to install the Maple bootloader at Leaf Labs http://docs.leaflabs.com/docs.leaflabs.com/index.html You will need a STLink programmer for this process. Once the bootloader is flashed to the memory the DFU becomes active after a board reset for a short period for firmware update. If the IDE does not initiate a firmware update, the STM goes on to execute the program code. Now, the board will now be visible as a COM port in your PC just like an Arduino.
Step 3: Setup Maple drivers on PC
 
Remember how we said that the board will be recognized as a DFU device by Windows? Most of the time you will need to introduce the drivers to the device in order to be recognized successfully. This is done using a simple tool called ‘wdi-simple’. Refer this video https://www.youtube.com/watch?v=0jdJp3TQuJY for step by step instructions and this great github link https://github.com/rogerclarkmelbourne/Arduino_STM32/wiki/Maple-drivers for more info. Once the drivers are introduced properly, your Banana Pi will be fully functional for firmware update as well as Serial communication just like a our plain old Arduino Uno.

MORE BLOG POSTS

Blockchain fast-tracked!20180502100106
Blockchain firsthand @ Google I/O 2018 with Mobitel20180411101138
Going low power with Banana Pi20180315095633
Intro to low power design20180308093444
Peeling the Banana20180305092739

Peeling the Banana

March 5, 2018

Author – Mobitel Innovation Center – Akalanka De Silva

Comments 0

Add Comment