Update on Feb 03 2017:
I asked the question on the RIOT-OS issue tracker (https://github.com/RIOT-OS/RIOT/issues/6535)
Apparently, the problem with Uno and Mega2560 is due to the fact that I used the VM provided (https://github.com/RIOT-OS/RIOT/tree/master/dist/tools/vagrant ). When I retried without the VM, the problem related to UNO/Mega2560 disappeared.
An explanation given by kYcOo is:
I think the problem lies on the fact that you’re using the vagrant VM. It comes with predefined default access to several boards which provide UART connectivity, and usually it works good so far. At the same time, if the resources of the host are not so high, of course it has a consequence on the communication with external hardware.
Recently, I am playing with Arduino boards, and would like to run a real OS on it, rather than a simple “loop” sketch. So I’m thinking about RIOT OS. According to the wiki of RIOT OS (https://github.com/RIOT-OS/RIOT/wiki Jan 1 2017), five kinds of boards are supported by RIOT OS:
- Arduino Due (ARM family)
- Arduino Zero (ARM family)
- Arduino Mega2560 (ATmega family)
- Arduino Uno (ATmega family)
- Arduino Duemilanove (ATmega family)
I tested three of them: Due, Mega2560 and Uno.
Arduino Due
I tried to flash the RioT OS to the board. To do so, I followed the instructions from the link https://github.com/RIOT-OS/RIOT/wiki/Board:-Arduino-Due, which seems to be very straightforward:
Flashing RIOT on the Arduino Due is quite straight forward, just connect your Arduino Due using the programming port to your host computer and type:
make flash
This should take care of everything!
RIOTs Makefile carries out a two step process for flashing the Arduino Due:
the (serial) programming port is programmed to run at 1200bps. This will trigger the on-board ATMega to reset the SAM3X and boot it to the internal serial flash bootloader
we use the open bossac tool to write the new code into the SAM3X’s flash
However, I got error messages like:
/home/vagrant/RIOT/boards/arduino-due/dist/flash.sh
Device found on ttyACM0
Erase flash
Write 9004 bytes to flash
[================ ] 55% (20/36 pages)
SAM-BA operation failed
/home/vagrant/RIOT/Makefile.include:330: recipe for target 'flash' failed
On the other hand, when using the native port, I actually got the correct message:
/home/vagrant/RIOT/boards/arduino-due/dist/flash.sh
Device found on ttyACM0
Erase flash
Write 9004 bytes to flash
[==============================] 100% (36/36 pages)
Verify 9004 bytes of flash
[==============================] 100% (36/36 pages)
Verify successful
Set boot flash true
CPU reset.
However, after the flashing, my laptop (a Mac Book pro) couldn’t find the Arduino in its device list, which makes it hard to tell whether the device is running properly or not.
To show the serial port information, I tried the programming port again, with screen:
screen ttyACM0
which gives me messy code like (probably due to wrong setting of baud rate)
�wФʣ����9�La@�8�D;>8̦�gu6�
�V:�9�E�r�v?̨
�>{#e�ۣ
�V:�9�E�rv?̨
�>{#e�ۣ
�V:�8�E�rv?̨
�>nA#e�ۣ
�V:�8�E�rv?̨+�>nC#%��
�V:�8�E�rv?̨+�>nC#%��
However, if we use the pyterm program provided by Riot OS (by launching make term),
$ BOARD=arduino-due make term
/home/vagrant/RIOT/dist/tools/pyterm/pyterm -p "/dev/ttyACM0" -b "115200"
No handlers could be found for logger "root"
2016-12-16 15:03:46,567 - INFO # Connect to serial port /dev/ttyACM0
Welcome to pyterm!
Type '/exit' to exit.
...
2016-12-16 15:03:47,600 - INFO # This application runs on arduino-due, 17
2016-12-16 15:03:47,601 - INFO # This application runs on arduino-due, 18
2016-12-16 15:03:47,601 - INFO # This application runs on arduino-due, 19
2016-12-16 15:03:47,602 - INFO # This application runs on arduino-due, 20
2016-12-16 15:03:47,602 - INFO # This application runs on arduino-due, 21
2016-12-16 15:03:47,603 - INFO # This application runs on arduino-due, 22
Apparently, this is due to the output code of the Riot OS. Now we can see the device is running as expected with Riot OS.
You might ask: if I couldn’t see my Arduino in the native port after flashing Riot OS, how to flash it again? A stupid, but workable solution is: try to do a flash on the programming port, which will surely give you the same error message shown above — but after this, you will be able to see the device by connecting native port.
Here is an explanation of native port and programming port from https://www.arduino.cc/en/Main/ArduinoBoardDue :
- Native port: directly connected to USB host pins of SAM3X. Able to use DUE as a client USB peripheral or host device. Also can be used as virtual serial port using “SerialUSB” object in the Arduino programming language.
- Programming port: connected to an ATmega16U2, which provides a virtual COM port to software on a connected computer. The 16U2 is also connected to the SAM3X hardware UART. Serial on pins RX0 and TX0 provides Serial-to-USB communication for programming the board through the ATmega16U2 microcontroller.
If you know why exactly there is such strange behaviour with RioT OS (with the normal Arduino IDE, both ports work well with sketchs), please let me know 🙂
Arduino UNO
Very recently, Riot OS has its support to Arduino UNO (https://github.com/RIOT-OS/RIOT/wiki/Board:-Arduino-Uno).
However, I need very good luck to flash the Riot OS to the UNO board, because most of the time, I got error messages like (it might stop at any point):
avrdude -p atmega328p -c arduino -P /dev/ttyACM0 -b 115200 -F -D -U flash:w:bin/arduino-uno/Task01.hex
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.01s
avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: reading input file "bin/arduino-uno/Task01.hex"
avrdude: input file bin/arduino-uno/Task01.hex auto detected as Intel Hex
avrdude: writing flash (5676 bytes):
Writing | ############################### | 62% 0.69s
avrdude: stk500_paged_write(): (a) protocol error, expect=0x14, resp=0x00
Writing | ################################ | 64% 1.84savrdude: stk500_cmd(): programmer is out of sync
avrdude: stk500_cmd(): programmer is out of sync
avrdude: stk500_cmd(): programmer is out of sync
avrdude: stk500_cmd(): programmer is out of sync
If I was in luck (after 20~ retries), I will be able to see:
avrdude -p atmega328p -c arduino -P /dev/ttyACM0 -b 115200 -F -D -U flash:w:bin/arduino-uno/Task01.hex
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.01s
avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: reading input file "bin/arduino-uno/Task01.hex"
avrdude: input file bin/arduino-uno/Task01.hex auto detected as Intel Hex
avrdude: writing flash (5676 bytes):
Writing | ################################################## | 100% 1.11s
avrdude: 5676 bytes of flash written
avrdude: verifying flash memory against bin/arduino-uno/Task01.hex:
avrdude: load data flash data from input file bin/arduino-uno/Task01.hex:
avrdude: input file bin/arduino-uno/Task01.hex auto detected as Intel Hex
avrdude: input file bin/arduino-uno/Task01.hex contains 5676 bytes
avrdude: reading on-chip flash data:
Reading | ################################################## | 100% 0.92s
avrdude: verifying ...
avrdude: 5676 bytes of flash verified
avrdude: safemode: Fuses OK (E:00, H:00, L:00)
avrdude done. Thank you.
Apparently, something is wrong with the avrdude, which is for flashing the UNO board. However, without knowing much about avrdude , I have no idea what’s going wrong.
Arduino Mega2560
With Mega2560, the flashing doesn’t work either:
/home/vagrant/Tutorials/task-01/bin/arduino-mega2560/Task01.elf
avrdude -p m2560 -c stk500v2 -P /dev/ttyACM0 -b 115200 -F -D -U flash:w:bin/arduino-mega2560/Task01.hex
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.01s
avrdude: Device signature = 0x1e9801 (probably m2560)
avrdude: reading input file "bin/arduino-mega2560/Task01.hex"
avrdude: input file bin/arduino-mega2560/Task01.hex auto detected as Intel Hex
avrdude: writing flash (6230 bytes):
Writing | ###################### | 44% 0.48savrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
^C/home/vagrant/RIOT/Makefile.include:330: recipe for target 'flash' failed
make: *** [flash] Interrupt