First question : How Hackaday.io works ?

Our aim : Developing an app. with Eclipse on Linux and transferring it on the dev. board.


Linkit One is made for windows and ArduinoIDE. For consequent project, it is better to use Eclipse. For an other development board from Mediatek with the same main chip (ARM MT2502AV), Mediatek provides a plugin for Eclipse called "Linkit Assist 2502". But everything remains fuzzy and obscur...


If you go on the web, you can find some informations, it was mine:

http://www.instructables.com/id/Using-LinkIt-One-with-Arduino-in-Linux/?ALLSTEPS

http://www.instructables.com/id/Programming-LinkIt-One-in-Linux-no-WiNE/?ALLSTEPS

An own compilation report on my machine, but it doesn't matter, only the process in interesting: http://www.seeedstudio.com/forum/viewtopic.php?f=71&t=6616

http://www.github.com/v-i-s-h/LinkIt-One-Linux-Arduino-Support-

https://github.com/Seeed-Studio/Lua_for_RePhone/tree/master/tools


Summary:

  1. Linkit One and Serial
  2. Compilation process
  3. Eclipse Configuration
  4. Board configuration and transfer

I ] Linkit One and Serial

The dev. board has a boot process. First, it start a serial connection which is used to "flash" a new bootloader for example, with the "firmware updater" tool from Mediatek. We won't use it here, but anyway, for information it sends to linux things. This state is only during two or three seconds. With lsusb, it is recognised as:

$ lsusb
Bus 001 Device 009: ID 0e8d:0003 MediaTek Inc. MT6227 phone

It creates a serial port:

$ ls -lisah /dev/*ttyU*
844532 0 crw-rw---- 1 root dialout 188, 0 avril 18 14:36 /dev/ttyUSB0
And it sends through:
BUF2!F1
or in hex format:
42 55 46 32 21 46 31

Right after, it closes the connection. If the dev. board has its switch set on "UART" (and not on "MS" (mass-storage)), it opens two other serial ports.

On "UART" mode, and with lsusb, the device is recognised as:

$ lsusb
Bus 001 Device 020: ID 0e8d:0023 MediaTek Inc. S103

It creates two serial ports:

$ ls -lisah /dev/*ttyA*
835018 0 crw-rw---- 1 root dialout 166, 0 avril 18 14:32 /dev/ttyACM0
835019 0 crw-rw---- 1 root dialout 166, 1 avril 18 14:32 /dev/ttyACM1
Some time (mostly), we can interact with the first, and the second sends a kind of report with the time. Other time but more rarely, it is the opposite.

So, what are the interactions ?

When the dev. board start, it send on the serial port (often ACM0) what it does. First things we can see are the ATE1 and E0. The board works with AT commands. It we don't do anything, we can read:

ATE1 E0
OK
ERROR
+CGMM: MTK2
OK
OK
OK
OK
OK
+GCAP: +FCLASS, +CGSM
MTK2
MAUI.11CW1418SP5.W15.19
+CGMM: MTK2
OK
I want to note first that the E command is the Echo command. 0 resets and 1 sets it. At the boot-process, it sets and resets the echo. It means, everything we send is not see any more and the boot process don't show the command. If quickly during the boot process we write ate1 again (it isn't case sensitive), (and again because it writes automatically ate0...) it shows the command again. we can see:
AaTE1t Ee01ATE1 E0a
ERROR
OK
AT%IPSYS?AT%IPSYS?
ERROR
AT+CGMM
+CGMM: MTK2
OK
AT+GMM
+CGMM: MTK2
ATE0
OK
OK
ATI
MTK2
MAUI.11CW1418SP5.W15.19
OK
ATE0
OK
ATV1
OK
AT+CMEE=
OK
ATX4
OK
AT&C1ATE0
MTK2
MAUI.11CW1418SP5.W15.19
OK
ATX4AT&C1ATE0
+CGDCONT: (1),"IP",,,(0),(0)
OK
+CFUN: 1
OK
+CME ERROR: 10
I note some command and find no much significations:
AT A ???
B/C don't exist.
D ???
E 0-1 : Set or reset the Echo function.
F/G don't exist.
H 0-1
I no option : show the informations
J/K don't exist
L 0-1-2-3 ???
M 0-1-2 ???
N doesn't exist.
O ???
P no option : ???
Q 0-1 : Disable all returns and echo. I don't recommend. Way-out Z.
R/S/T/U don't exist.
V 0-1 : ???
W 2 : ???
X 0-1-2-3-4 : ???
Y doesn't exist.
Z 0-1 : Disable return code (not recommended). But set the return resetted by ATQ.

There is also extra command, like saw during the boot process (AT+CGMI, AT+CGMM ...). It is certainly possible to send the applications and get the debugger through these AT command. But I don't know how.


II] Compilation process

Like explained on another web site, it is possible to send the App to the dev. board with its Flash memory when it is recognised as a Mass-Storage on Linux. Great! We just have to compile it! Wait, it's not that easy... The application are not "hex", not "elf", not "exe", not com... It is vxp... A kind of axf... Never heard about before! But it's normal, we are young.

The applications on the board are with the VXP extension. The vxp file is a AXF application with extra code from Mediatek. The AXF files are ELF files with extra informations. (http://stackoverflow.com/questions/17761328/what-are-axf-files).

These extra-code are given by seeduino in a python code. (Here) This code add a code part (perhaps only "tags") and the sum of the binary.

If we take a closer look at the compilation report (like here), we can see five steps on windows.

  1. Compilation of Source codes
  2. Linking the objects
  3. modifying the application
  4. modifying the application (adding the "tags"). (just explained)
  5. downloading the application to the board.

There are two "source" codes to cross-compile. The source code we wrote and a certain "gccmain.c". This code contains the main entry of the application as defined in the scat.ld script.

After the compilation, the objects are linked together with the linker. The scat.ld script is given to the linker with the -T option. It links a library of Mediatek too, named percommon.a.

There is now a modification of the binary. The -g option is to remove debug symbols. And the -R to remove sections, here the comments. So the binary is lighter.

There is a second use of the objcopy, this second time is only to keep the debug in a new file. It is useless for us on Linux, we don't have yet any possibilities to act with the debugger. But we will do the same, to be closer than the Windows version.


III] Eclipse Configuration

Things to download :

  1. The Eclipse IDE for C
  2. The Linkit Assist SDK this SDK contains the GCC (Cross compiler) for Windows. We have to get one for Linux.
  3. The CrossCompiler for Linux. We will find it with Mediatek ! On the page for the Linkit One there is a JSON to add for ArduinoIDE (#step 4). This JSON contains in the tools section the link for the Linux cross Compiler (version for Linux 64b) ! (version for 32b here !)
  4. The Python script to transform the AXF binary to VXP.
  5. Optionally Virtualbox... See later in the next chapter.

I take in consideration that all downloads are in: /home/user/tools/ . With /home/user/tools/eclipse/ the root for Eclipse; /home/user/tools/gcc-arm/ the root of the cross-compiler; /home/user/tools/LINKIT_ASSIST_SDK/ the root of the SDK and in this root the python script is placed.

In order to develop project for Linkit One with Eclipse, we need to configure Eclipse quiet a lot.

At the start of Eclipse (or in the file menu) we define to work in a specific workspace, only for Linkit One. In this workspace, we start a new C project. In the properties of this project, we have to set for [All Configurations]:

C/C++ Build: in the Behavior tab, we unset "Stop on first build error" and set "Enable parallel build".
C/C++ Build --> Build Variables: We will add the variable called MyToolsPath, type Path and value /home/user/tools/
C/C++ Build --> Settings --> Tool Settings --> Cross Settings: Prefix "arm-none-eabi-"; Path "/home/user/tools/gcc-arm/bin/"
C/C++ Build --> Settings --> Tool Settings --> Cross GCC Compiler --> Dialect: set the language standatd to ISO C11.
C/C++ Build --> Settings --> Tool Settings --> Cross GCC Compiler --> Preprocessor: add the next symbols in the Defined symbols (-D) section:

C/C++ Build --> Settings --> Tool Settings --> Cross GCC Compiler --> Includes: in the Include paths (-I) section:

C/C++ Build --> Settings --> Tool Settings --> Cross GCC Compiler --> Optimization: The level is set to -O2 for the Arduino IDE. (Source: ArduinoIDE mediatek extension /platform.txt)

C/C++ Build --> Settings --> Tool Settings --> Cross GCC Compiler --> Debugging: Debug Level: Default (-g)
C/C++ Build --> Settings --> Tool Settings --> Cross GCC Compiler --> Miscellaneous: set "Position Independent Code (-fPIC) and in "Other flags":

-mthumb-interwork -c -gdwarf-2 -gstrict-dwarf -mcpu=arm7tdmi-s -fvisibility=hidden -mthumb -mlittle-endian -fno-exceptions -fno-non-call-exceptions

C/C++ Build --> Settings --> Tool Settings --> Cross GCC Linker --> General: Set -nostartfiles -nodefaultlibs and -nostdlib.
C/C++ Build --> Settings --> Tool Settings --> Cross GCC Linker --> Miscellaneous: in the Linker flags, place here:

-T/home/user/tools/LINKIT_ASSIST_SDK/lib/LINKIT10/armgcc_t/scat.ld -Wl,--gc-sections -fpic -pie --specs=nosys.specs -B/home/user/tools/gcc-arm/arm-none-eabi/lib/thumb/

C/C++ Build --> Settings --> Tool Settings --> Cross GCC Linker --> Miscellaneous: in "Other objects" place here:

-T/home/user/tools/LINKIT_ASSIST_SDK/lib/LINKIT10/armgcc/percommon.a

C/C++ Build --> Settings --> Tool Settings --> Cross GCC Assembler --> General: in Assembler flags place here:

-mthumb -mlittle-endian -mcpu=arm7tdmi-s

C/C++ Build --> Settings --> Build Steps --> Pre-build steps --> Command:

rm -rf ./${ProjName}.vxp ./${ProjName}.axf ./${ProjName}.dbg

C/C++ Build --> Settings --> Build Steps --> Post-build steps --> Command:

${MyToolsPath}/gcc-arm/bin/arm-none-eabi-objcopy -g -R .comment ${ProjName}.elf ${ProjName}.elf ; ${MyToolsPath}/gcc-arm/bin/arm-none-eabi-objcopy --only-keep-debug ${ProjName}.elf ${ProjName}.dbg ; python ${MyToolsPath}/LINKIT_ASSIST_SDK/packtag.py ${ProjName}.elf ${ProjName}.vxp

C/C++ Build --> Settings --> Build Artifact --> Artifact name: ${ProjName}

C/C++ Build --> Settings --> Build Artifact --> Artifact extension: elf

C/C++ Build --> Settings --> Binary Parsers --> Binary Parser: Only selected "Elf Parser".

Well ! The configuration are set. But I have other options that are not set for Eclipse. Their are for Arduino, and I don't know if I have to set them for Eclipse too. Their are:

C/C++ Build --> Settings --> Tool Settings --> Cross GCC Compiler --> Miscellaneous --> Other flags:

-MMD-ffunction-sections -fdata-sections -fmessage-length=0

I'm done with the configurations. No I want to note an IMPORTANT thing. We have to copy the file /home/user/tools/LINKIT_ASSIST_SDK/lib/LINKIT10/src/gccmain.c in our project directory. Otherwise, the entry function won't be found.

After the compilation, I can't explain why there are errors shown, and why it compile anyway.


IV] Board configuration and transfer

To transfer the application to the board, the boards switch should be set as "MS" mode (for Mass-Storage). A reset of the board is needed.

In some case, the flash memory is directly recognised as a removable memory on Linux. Other case (and unfortunately mine), I have to make a kind of "reset" on the USB. I do this "reset" by linking the device on a Virtualmachine, and plug it out from this virtualmachine. The Linux will recognises it few second after.

The Flash memory can contain the MRE directory and the Autostart.txt file as described on the other web side. If it don't exist, just create it.

Rename your ${ProjName}.vxp application to app.vxp and place it in /.../flash_memory/MRE/.

Change the content of /.../flash_memory/autostart.txt or create it. It should contain

App=C:\MRE\app.vxp

We can now reset the dev. board on UART mode !


PS: Something is wrong. I just try to build a blinking app. It didn't blink, just light the LED, and after a while, the RX and TX led start to blinking alternately. I read that something is wrong, but I don't know more.

Unfortunately, I can't continue, I give up.

Feel free to : correct my english ! Add a comment, a correction or just continue it!

Have a good day ! ;)