Sparkfun SAMD21G18 target

mbed_os

(Malachi Burke) #1

Hi all,

I am attempting to program a Sparkfun SAMD mini board (https://www.sparkfun.com/products/13664) with mbed OS.

My first presumption is that mbed OS plays nice with SAM-BA / BOSSAC USB bootloader.

My second presumption is that though this is not the official mbed OS supported SAMD Xplained target board (http://www.atmel.com/tools/ATSAMD21-XPRO.aspx) that it's close enough to not be a problem.

The LED is on digital pin 13 aka PA17. However, my modified blink code is unresponsive:

#include "mbed-drivers/mbed.h"

#if SAM
#define MAL_LED PA17
#else
#define MAL_LED LED1
#endif

static void blinky(void) {
    static DigitalOut led(MAL_LED);
    led = !led;
    printf("LED = %d \r\n",led.read());
}

void app_start(int, char**) {
    minar::Scheduler::postCallback(blinky).period(minar::milliseconds(500));
}

My third, but hopefully unimportant, presumption is that the printf won't work properly unless I explicitly set up a SERCOM/USB for it.

Please advise; if any or all of my presumptions are wrong or flawed, please say so!


(Malachi Burke) #2

OK, how about this. Has anyone here used mbed OS on an Atmel SAM chip?


(Schnyder Franz) #3

Hi

I just managed to get my Adafruit Feather M0 Basic Proto blinking with mbed OS.
With the first attempts I had the same issue that my board was unresponsive after the upload.

To actually make it blink I had to change the linker script (yotta_targets/atmel-samd21g18a-gcc/ld/samd21g18a.ld) that comes with the atmel-samd21g18a-gcc target since the bootloader on the Adafruit Feather M0 and probably also on your Sparkfun SAMD mini board also needs some space.

So I change Memory Spaces Definitions in the linker script from

/* Memory Spaces Definitions */
MEMORY
{
  rom (rx)  : ORIGIN = 0x000000000, LENGTH = 0x00040000
  ram (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00008000
}

to

/* Memory Spaces Definitions */
MEMORY
{
  rom (rx)  : ORIGIN = 0x000000000+0x2000, LENGTH = 0x00040000-0x2000 /* First 8KB used by bootloader */
  ram (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00008000
}

And the board happily blinks :grinning: with this code

#include "mbed-drivers/mbed.h"

static void blinky(void) {
    static DigitalOut led(PA17);
    led = !led;
    //printf("LED = %d \r\n",led.read());
}

void app_start(int, char**) {
    minar::Scheduler::postCallback(blinky).period(minar::milliseconds(250));
}

I took the Memory Spaces Definitions from the Arduino Linker Script

It now works locally with a patched atmel-samd21g18a-gcc target.


(Malachi Burke) #4

Wow @bittailor - nice! I will try this ASAP
I was resolved to having to use ATMEL-ICE or similar... (and still will for some scenarios). Have you used one? I am curious if you or anyone has had success doing a "yotta debug" with it.

When I start down that path, this happens:

error: Target atmel-samd21g18a-gcc 1.0.1 at /mnt/c/Projects/playground.mbed/src/OS/blinky/yotta_targets/atmel-samd21g18a-gcc does not specify debug commands


(Justin Jordan) #5

Why is it necessary o offset for the Arduino bootloader?

Shouldn't the new .bin start at 0x0 and you just wouldn't be able to use the Arduino IDE for programming any longer, you would have to use whatever interface you are using to write the binary; i.e. Segger or something else.

I am having a similar problem and haven't tried your solution, however I don't understand the reason 'necessity' to save the Arduino bootloader.

Thanks,


(Schnyder Franz) #6

Hi Justin

I uploaded my code via the Arduino Bootloader since I have no Segger or another programmer. Therefore I needed the bootlaoder and the offset of the bootloader. If you upload your code via a programmer and override the bootloader there is no need for an offset, as Malachi mentioned in his response.

Regards
Franz


(Malachi Burke) #7

Hi friends. mbed OS 5 new blinky sample won't compile for this target - seems to be missing the mbed_rtx.h file. Has anyone else experienced this?


(Schnyder Franz) #8

I experienced the same. Then I checked the boards list and checked the mbed OS 5 filter. With this the Atmel ATSAMD21-XPRO disappears from the list, so it looks like the SAMD21 target is not or not yet supported for mbed OS 5. I then I stopped trying further,

Would be really nice to know if it is planned to add support of Atmel ATSAMD21-XPRO for mbed OS 5 and if yes if there is already a rough date for it.


(Malachi Burke) #9

For real; I invested a couple hundred bucks in the SAMD stuff specifically to use it with mbed (mbed os 3 at the time)

EDIT: mbed OS 5 compatibility issue opened on official github page: https://github.com/ARMmbed/mbed-os/issues/3370


(Sergey Solodunov) #10

Hi guys,

Has anyone managed to compile for samd/saml targets with mbed OS?


(Jan Jongboom) #11

@malachi @bittailor @sergoserg, the main problem seems to be in RTX not supported on this chipset. Here I posted a trick to remove RTX from your mbed OS 5 application, which should allow you to build for this target again...

After that you can use mbed-events (similar to MINAR in mbed OS 3) or roll your own state machine.


(Malachi Burke) #12

Thank you very much for this. I'm kinda curious, how come no RTX for this target? I presume it's a size constraint thing?


(Sergey Solodunov) #13

Hi @janjongboom. Thanks for the tips and link.
I reckon if RTOS features are disabled, the networking stacks, such as 6lowpan and Thread, won't work. Is it possible to get them working without RTOS?


(Malachi Burke) #14

Using your custom linker patch I was able to BOSSAC up a firmware to my sparkfun. I'm now using mbed_events & get a blinking light. Progress.

It seems like mbed os now auto excludes RTOS from the SAMD target.

The particular environment I'm using, somehow semihosting doesn't activate.


(Malachi Burke) #15

How might I get USB Serial device to work here?

Specifically, semihosting doesn't seem to be present but if I can push things out over regular Serial that would be enough for me. However, host PC doesn't see this USB device at all when it's running mbed-programmed firmware.