Port for Arduino Due?

Posted on
Page
of 2
/ 2
Next
  • The Arduino Due Board has a Cortex M3 Processor and more flash and Ram than the original Espruino Board. You can get a clone for around 20$, original about 40$.

    It should not be that hard to port Espruino, has anyone tried it yet?
    Anyone interested?

    Here are the specs, it has some nice stuff built in like CAN: https://store.arduino.cc/usa/arduino-due

    Thomas

  • Maybe this Thread should be moved to "Porting to new devices", sorry!

  • No problem! Just moved!

    I saw someone was looking at porting to the Adafruit M0 boards, which are Atmel SAMD based as well (albeit with a different ARM core): https://twitter.com/todbot/status/902991546089226240

    As far as I know nobody has tried it, but you're right - it should be pretty straightforward. Since there's software I2C, SPI and PWM now you could get something pretty usable just by implementing UART, timer and GPIO support.

  • Hi Gordon,

    thanks for the hint. I think I'll give it a try.
    My plan is:

    1. Compile the Espruino Source on Linux 64 Bit.
    2. Compile the Espruino Source for a Pico Board and get it to run. (I have a few Espruino Picos and Wifis at hand).
    3. Flash the already ported (from some other guy) micropython on the Arduino Due and get that to run.
    4. Build an Arduino Due Blink-Prog from Scratch (on the Command Line with arm-gcc) and let that run on the Due.
    5. Modify the Espruino Source for the Due and let it run on the Due. I think the first "point of attack" would be modifying the Boards-File according to the Due Specs. I think the next big step is to change from the stm lib to the sam lib...

    I've already done 1-3, so I'm moving forward now.

    If you would like to give me any tipps, or want me to post a tutorial afterwards, just tell me.

    Thomas

    PS: Became a patreon member today. I think your work is amazing. And keeping such a close (and friendly!!!) look on the forums is also amazing. Even when you consider that the guys porting espruino to other devices kind of stealing your money because you sell less from your own boards...

    PPS: I also have Making Things Smart on my kindle. Easy read with some new ideas! Good work!

  • Nice, thanks!

    It might be worth looking at something like the EFM32 port - that's a very basic port of Espruino so there shouldn't be too much confusing in there... But basically you'll want:

    • main.c and jshardware.c in targets/samd
    • some more files in the make directory that handle any Atmel-specific files
    • Probably your own linker file in targetlibs/samd (as well as Atmel API files - if these are big you could load them in via provision.sh)

    And that's it I think - probably the most important thing is to get your blink-prog working with the serial (or USB?) port... Once you can have access to the REPL on Espruino debugging will be a lot easier!

  • Okay, I've managed to gather all the required files for a build from the Arduino IDE and put them here: https://tclinux.de/due.tar.gz
    Thats 100 MB :-(
    -> Including the GCC Toolchain, which can be omitted.

    A simple Testprogram looks like that:

    [#include](https://forum.espruino.com/search/?q=%23include) "../include/due_sam3x.init.h"
    
    /**
    * Simply blink the amber LED on the DUE with 2Hz:
    */
    int main(void)
    {
     /* The general init (clock, libc, watchdog ...) */
     init_controller();
    
     /* Board pin 13 == PB27 */
     PIO_Configure(PIOB, PIO_OUTPUT_1, PIO_PB27, PIO_DEFAULT);
    
     /* Main loop */
     while(1) {
       Sleep(250);
       if(PIOB->PIO_ODSR & PIO_PB27) {
         /* Set clear register */
         PIOB->PIO_CODR = PIO_PB27;
       } else {
         /* Set set register */
         PIOB->PIO_SODR = PIO_PB27;
       }
     }
     return 0;
    }
    

    You can compile it with:

    ../tools/g++_arm_none_eabi/bin/arm-none-eabi-gcc -c -Wall --param max-inline-insns-single=500 -mcpu=cortex-m3 -mthumb -mlong-calls -ffunction-sections -fdata-sections -nostdlib -std=c99 -Os -I../include -I../sam -I../sam/libsam -I../sam/CMSIS/CMSIS/Include -I../sam/CMSIS/Device/ATMEL main.c -o main.o
    ../tools/g++_arm_none_eabi/bin/arm-none-eabi-ar rcs firmware.a main.o
    ../tools/g++_arm_none_eabi/bin/arm-none-eabi-nm firmware.a > firmware.a.txt
    ../tools/g++_arm_none_eabi/bin/arm-none-eabi-g++ -Os -Wl,--gc-sections -mcpu=cortex-m3 "-T../sam/linker_scripts/gcc/flash.ld" "-Wl,-Map,./firmware.map" -o firmware.elf "-L" -lm -lgcc -mthumb -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--entry=Reset_Handler -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align -Wl,--warn-unresolved-symbols -Wl,--start-group firmware.a ../lib/libsam_sam3x8e_gcc_rel.a -Wl,--end-group
    ../tools/g++_arm_none_eabi/bin/arm-none-eabi-objcopy -O binary firmware.elf firmware.bin
    

    So step 4 is done. Now I'm trying to modify Espruino to compile for the Arduino Due. If anyone wants to help, feel free to do so.
    This might take some time!

    Thomas

    Credits: Arduino IDE
    Tutorial from: http://www.atwillys.de/content/cc/using-custom-ide-and-system-library-on-arduino-due-sam3x8e/?lang=en
    -> But the Tutorial is outdated and has some errors. I needed to correct them.

  • Test program testing what?

  • Simply blinking a LED on the Due.
    I see that the forum has a problem with the first line, it should read:

    #include "../include/due_sam3x.init.h"

    You can transfer the file firmware.bin with the included program (under tools) 'bossac':

    ./bossac -p ttyACM0 -e -w -v -b /home/tc/firmware.bin
    
  • Ic; with that test program you validate your tool chain setup... and now comes the hard work to enable Espruino coding... ;-)

  • Okay, I don't fear the hard work, so heres my plan.

    1. I create a file 'board/ARDUINODUE.py' and insert all Arduino Due Data.
    2. I create a file (referenced in 1.) 'boards/pins/arduinodue.csv' and insert a few Pins. The LED, the first UART and maybe some minor more for the start.
    3. I copy my complete toolchain (without gcc of course) to '/targetlibs/samd'.
    4. I create 'targets/samd/main.c' which is a 1on1 copy from the correspondending EFM32 Port File, nothing hardware dependent in here.
    5. I create 'targets/samd/jshardware.js' (copy the file from the EFM32 Port!) and modify all of it so that it does compile on an Arduino Due.
    6. I need to change the build process so that my build commandos are jused. I'm not quite sure how to do that.
    7. I try to make Espruino with BOARD=ARDUINODUE and hope for the best.


    Is this the right way to go? The one thing which is hard work seems to be 'jshardware.js' because to me it looks that this is the hardware dependent interface. Am I correct?

    Thomas

    PS: Yes, a long way to go.. :-)
    PPS: @Gordon: How do I get the Patreon Batch in the Forums?

  • Sounds like a good plan... Yes, you're right - once it's compiling pretty much all your work will be in jshardware.c.

    Just some ideas:

    1. I'd skip the CSV for now. Take a look at boards/NRF52832DK.py - and others - for how to create the pins in the py file itself. It'll be far easier - for now, just use LINUX.py as an example for how to create some pins with no functions attached.

    2. Please try not to commit example code though :)

    3. Many of the functions can be empty or can return values for not implemented. Realistically for now you can just hard-code serial initialisation and handle the serial transmit/receive stuff (it's intended to be interrupt driven).

    4. It should be easier now than before. The relevant build commands for each platform are stored in the make directory - you just need to make one for SAMD, and hopefully the ARM bits of the Makefile will still work for you to do what you want.

    Ahh - sorry about the badge. It's still a slightly manual process (I have to get a list of Patreons and a list of emails of forums users and use that when I build the site). I'll do it again today though.

  • Hello Gordon,

    okay. I think that helps me a lot. I'll try to go on and will cry for help if I'm really stuck :-)

    Nevermind the badge, it's not important!

  • If anyone wants to follow my silly attempts to get the Arduino Due to fly, here you go: https://github.com/ThomasChr/Espruino/tree/duedev

    Brach: duedev

  • We have a blinking LED!
    That was really hard work for me, but I've added a working makefile and a working toolchain to Espruino. Now comes the part where we really code something!
    @Gordon: Can you tell me which Functions I need to implement into jshardware.c to get a REPL going?

  • Wow, that's great!

    I reckon you want:

    • For now, hard-code UART initialisation into jshInit
    • Add jshUSARTKick - this should start off UART transmission if it isn't already started, but the transmission should then have an interrupt handler that keeps transmission going all by itself (calling jshGetCharToTransmit to get new characters).
    • At that point you should be able to boot and see the Espruino logo appear
    • Then implement the Interrupt handler for UART receive - when you get a character call jshPushIOCharEvent to push it into Espruino
    • And you should now have a working REPL
    • If you haven't already, add jshPinSetValue and jshPinSetState to allow you to turn outputs on and off. Initially jshPinSetState would only have to deal with JSHPINSTATE_GPIO_IN and JSHPINSTATE_GPIO_OUT.
    • Then you could look at adding jshGetSystemTime which would just get the current time from the RTC (that's easiest for now) - then you can start using setInterval/etc.

    Hope that helps! Once you have the UART going it becomes quite fun, since you can debug and test using the REPL

  • Hi Gordon,

    thanks!
    I've a working UART now and maybe next week I implement the REPL. But it's enough for today :-)

  • I've got a REPL, I've got Pin Functions (Config, Get, Set) for the first Pin (the onboard LED). I think we can call it Alpha Status :-)

    Next would be to get the setTimeout running by implementing jshGetSystemTime with the build-in RTC. Then I need to enter all possible pins (all 54!) and make the Pin Functions for them.

    Thats a lot of work, but not very complicated anymore.

  • Good progress!

  • We now have access to all pins (I counted 63 Pins - impressive) and the SystemTimer for setInterval() and setTimeout() is working - kind of. Not very accuracte. I'm on it.

    If someone wants to have a go, here are the Bin-Files: https://www.thomaschristlieb.de/wp-content/uploads/2017/09/espruinoduebin.tar.gz

    I think after getting a real accurate Time (better than one Second!) I'm trying to get save() to Work...

  • So... 'save()' is working now. It's not super reliable though. I think I need to make some debugging.
    Systemtime does now work down to the millisecond and has no overflow after 40 days any more...

  • That's absolutely awesome news - thanks!

    Looks really exciting - do you think it's in a state where you could give me a PR and we could get it into the main Espruino repo?

  • Hi Gordon!

    I think the code is kind of ready - setWatch is missing, also PWM, ADC and more UARTs - so a few things are left to do.

    But the included library is large (and also does include some manuals), so I think first I need to tidy up a little bit.

    Thomas

  • @ThomasChr - amazing work. I guess now comes the 20% accounting for 500% of the effort...

    Large lib(s)...

    What are the ramification for that for applications?

  • I've made a PR to discuss my code: https://github.com/espruino/Espruino/pull/1255

    The large lib is not a problem of code size on the due. It's ~250 MBs of Code in the Espruino Repo.

  • Thanks!

    But wow - 2000 files! I might see about skinning that down before merging - there seem to be quite a few docs/examples/libraries/etc in the Atmel libraries.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Port for Arduino Due?

Posted by Avatar for ThomasChr @ThomasChr

Actions