Program the Daughter Board

From Wiki for Dragino Project
Jump to: navigation, search

Introduction

The Dragino MS14 provides SPI and UART interface which can be used to connected to the daugther board. we can use them to program the daugther board. Different type of MCUs may have different methods. below are some examples:

Upload Sketch to AVRs via Arduino IDE

User can edit code and upload sketch to the AVRs in Arduino IDE. The software/firmware required for these are:

  • MS14: Require Yun Firmware or Dragino Firmware (version RC1.1 or later)
  • Computer: Arduino IDE v1.5.4 or later



Detect MS14 in Arduino IDE

Once the MS14 is configured and get IP address from WiFi router. It will send broadcast data in the network and if you run the latest Arduino IDE. It will auto detect Yun service and show in the port menu .

Arduino Detect Yun in the same network



Configure Board Type

Default Board Type

If the avr you use is mega32u4 and it connects to the MS14 with below pins:

Dragino MS14 mega32u4 Logic Level
GPIO20 /RESET invert
GPIO18 SCK same
GPIO21 MOSI same
GPIO22 MISO same

Then you can use the Arduino Yun Board Type to upload sketch to avr without modification. Example for these boards is M32, M32W. Upload method is as below:

Choose the correct board type Arduino Yun for the AVR module.

Default board type is Arduino Yun



Customized Board Type

If user don't have the default board type, then we have modified the Arduino IDE and the MS14 to support the remote upload feature. Below is an example for how to modify the Arduino IDE to support mrfm12b which has a mega168 mcu.

Customized Board Type in Arduino IDE

To add customized board type, we have to modify the board.txt info of Arduino IDE. In a Windows 7 machine, the boards.txt file is in C:Program Files\Arduino\hardware\arduino\avr. Open this file and copy the Yun definition and append it below Yun definition with a new name. below is definition for mrfm12b as an example.

##############################################################
 
MRFM12B.name=Dragino MRFM12B
MRFM12B.upload.via_ssh=true
MRFM12B.vid.0=0x2341
MRFM12B.pid.0=0x0041
MRFM12B.vid.1=0x2341
MRFM12B.pid.1=0x8041
MRFM12B.upload.tool=avrdude
MRFM12B.upload.protocol=avr109
MRFM12B.upload.maximum_size=14336
MRFM12B.upload.maximum_data_size=1024
MRFM12B.upload.speed=57600
MRFM12B.upload.disable_flushing=true
MRFM12B.upload.use_1200bps_touch=true
MRFM12B.upload.wait_for_upload_port=true
 
MRFM12B.bootloader.tool=avrdude
MRFM12B.bootloader.low_fuses='''0xff'''
MRFM12B.bootloader.high_fuses=0xdd
MRFM12B.bootloader.extended_fuses=0x00
MRFM12B.bootloader.file=atmega/ATmegaBOOT_168_diecimila.hex
MRFM12B.bootloader.unlock_bits=0x3F
MRFM12B.bootloader.lock_bits=0x2F
 
MRFM12B.build.mcu=atmega168
MRFM12B.build.f_cpu=16000000L
MRFM12B.build.vid=0x2341
MRFM12B.build.pid=0x8041
MRFM12B.build.usb_product="Arduino Yun"
MRFM12B.build.board=AVR_YUN
MRFM12B.build.core=arduino
MRFM12B.build.variant=standard
##MRFM12B.build.extra_flags={build.usb_flags}


After above change, restart the Arduino IDE and the DRAGINO MRFM12B board type will be shown under tools --> board menu.

Add a New Board Type in Arduino IDE



The Yun GUI support different kind of Arduino boards now. User can check them in the GUI--> Sensor page

Select the correct boardtype

Arduino Board Type: Define the bootloarder/mcu type/ fuse setting during Sketch upload.

Compile and Upload via Arduino IDE

After we have correctly configure board info. We can use the Arduino IDE to compile and upload the firmware to the avr module.

During upload, Arduino IDE will ask for a password. This is the password we configure in the Web GUI

Compile and Upload sketch in Arduino IDE





Upload hex file to AVRs

If user has their hex file and they can upload the hex file to the AVR without using Arduino IDE. They should:

Check SPI connection

modify /etc/avrdude.conf, to match how the ar9331 gpio pin connects to the avr. Below example shows

Dragino MS14 AVRs Logic Level
GPIO20 /RESET invert
GPIO18 SCK same
GPIO21 MOSI same
GPIO22 MISO same
#To check if your avrdude build has support for the linuxgpio programmer compiled in,
#use -c?type on the command line and look for linuxgpio in the list. If it's not available
#you need pass the --enable-linuxgpio=yes option to configure and recompile avrdude.
#
programmer
  id    = "linuxgpio";
  desc  = "Use the Linux sysfs interface to bitbang GPIO lines";
  type  = "linuxgpio";
# for DS1 board
#  reset = ~18;
# for DS2 board
#  reset = ~7;
# for DS2_B board
  reset = ~20;     
  sck   = 18;
# mosi  = 6;
  mosi = 21;
  miso  = 22;
;



Run Avrdude to program the avr



Example

Here use mrfm12b module as example:

1. Put module into Dragino ms12/ms14 and power on the device

dragino with mrfm12b

2. access the MS14 via SSH and modify the /etc/avrdude.conf , make sure that the GPIOs are set to the connect logic. for mrfm12b, the setting is as below:

ms14 avrdude setting for mrfm12b:
programmer
 id    = "gpio";
 desc  = "Use gpio_dev to bitbang GPIO lines";
 type  = gpio;
 reset = ~20;       
 sck   = 18;      
 mosi  = 21;
 miso  = 22;

3. Check if the mrfm12b is detected. run

root@dragino-01ef80:~# avrdude -p atmega168 -c gpio
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.02s
avrdude: Device signature = 0x1e9406
avrdude: safemode: Fuses OK
avrdude done.  Thank you.

note: mrfm12b use atmega168 as avr, the avr part number maybe different for other boards.


4. Upload the .hex file to MS14.


5. run avrdude command to upgrade, as below

root@dragino:~# avrdude -p atmega168 -c linuxgpio -U flash:w:pingPong.cpp.hex -U efuse:w:0x00:m -U hfuse:w:0xdd:m -U lfuse:w:0xff:m

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0x1e9406
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed
        To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "pingPong.cpp.hex"
avrdude: input file pingPong.cpp.hex auto detected as Intel Hex
avrdude: writing flash (5336 bytes):

Writing | ################################################## | 100% 4.94s

avrdude: 5336 bytes of flash written
avrdude: verifying flash memory against pingPong.cpp.hex:
avrdude: load data flash data from input file pingPong.cpp.hex:
avrdude: input file pingPong.cpp.hex auto detected as Intel Hex
avrdude: input file pingPong.cpp.hex contains 5336 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 4.20s

avrdude: verifying ...
avrdude: 5336 bytes of flash verified
avrdude: reading input file "0x00"
avrdude: writing efuse (1 bytes):

Writing | ################################################## | 100% 0.00s

avrdude: 1 bytes of efuse written
avrdude: verifying efuse memory against 0x00:
avrdude: load data efuse data from input file 0x00:
avrdude: input file 0x00 contains 1 bytes
avrdude: reading on-chip efuse data:

Reading | ################################################## | 100% 0.00s

avrdude: verifying ...
avrdude: 1 bytes of efuse verified
avrdude: reading input file "0xdd"
avrdude: writing hfuse (1 bytes):

Writing | ################################################## | 100% 0.01s

avrdude: 1 bytes of hfuse written
avrdude: verifying hfuse memory against 0xdd:
avrdude: load data hfuse data from input file 0xdd:
avrdude: input file 0xdd contains 1 bytes
avrdude: reading on-chip hfuse data:

Reading | ################################################## | 100% 0.00s

avrdude: verifying ...
avrdude: 1 bytes of hfuse verified
avrdude: reading input file "0xff"
avrdude: writing lfuse (1 bytes):

Writing | ################################################## | 100% 0.00s

avrdude: 1 bytes of lfuse written
avrdude: verifying lfuse memory against 0xff:
avrdude: load data lfuse data from input file 0xff:
avrdude: input file 0xff contains 1 bytes
avrdude: reading on-chip lfuse data:

Reading | ################################################## | 100% 0.00s

avrdude: verifying ...
avrdude: 1 bytes of lfuse verified

avrdude: safemode: Fuses OK

avrdude done.  Thank you.

note: different module may have different avrdude.conf.