Moving from Atmel SAMD21 (Arduino) to SAML21 - Page 1
Forum section: electronics / general

author: bluespider
author_rank: Contributor
timestamp: December 15, 2016, 01:47:34 pm
content: I have designed a circuit to do some basic data-logging from several i2c connected sensors and write out to an microSD card.Currently it is in the form of an Atmel SAMD21G18A based Arduino board with a custom made board with the sensors and power supply (battery charger etc.)I have used platformio for writing the code using the Arduino framework and libraries, with some custom libraries for the sensors that didn't have their own.I have added all the features that are needed for a Version1.0 and want to get some boards made soonish.The next thing to work on will be reducing power consumption and configuring the low power modes which is something that I have struggled to get working successfully using the Arduino tools.I have also had my eye on the SAML series of MCUs for their low power features.I would like to use the SAML chip on this set of boards to give me more options when I write V2.0 which will include all the power-saving, sleep mode stuff while keeping the same pcbsHowever the SAML series is not currently Arduino supported so I would have to re-write everything from scratch or with ASF which I think is currently beyond my capabilities.As the SAMD21G18 and the SAML21G18 are very similar I was wondering if there was an easy-ish way to transfer my current Arduino based project to use the SAML MCU instead.This way I could get V1.0 up and running soon with only small changes to the current code, and then at a later date rewrite it to wean myself off the Arduino Framework - or just write the non-Arduino supported parts alongside the existing code.If I could get the Wire, Serial, and SdFat libraries working, that would probably suffice for my purposes.is this a sensible approach at all?Is it just a case of copying the ArduinoCore and adding the SAML configurations (probably a lot of the SAMD ones will be the same)?I feel like my biggest hurdle currently is probably setting up an Atmel Studio Project (Solution?) correctly with all the dependencies, as I haven't dealt with AtmelStudio/VisualStudio or had to deal with buildchains/makefiles like this before.Or am I going about this completely wrong?Thanks,

author: ataradov
author_rank: Super Contributor
timestamp: December 15, 2016, 05:47:07 pm
content: I don't know about Arduino a lot, but porting code from D21 to L21 is reasonably easy. Most of the peripherals have the same registers. There are some things that are slightly different, but changes are very local and easy to find.To get a taste of what sort of changes you should expect, have a look at my two bare metal projects and compare them:https://github.com/ataradov/mcu-starter-projects/tree/master/samd21andhttps://github.com/ataradov/mcu-starter-projects/tree/master/saml21bBut remember, to get a real advantage of power savings you need to plan your clocks and system configuration accordingly. You can't just replace the MCU and expect it to be lower power. So you will have to do more changes to get that working.

author: bluespider
author_rank: Contributor
timestamp: December 16, 2016, 10:28:07 am
content: Thanks for your suggestions, I'll have a look through your blank projects.I was thinking the first step should be to get my existing platformio project on the SAMD21 into atmel studio. However I haven't managed to do that so far.My attempt has been to import a basic Arduino sketch into AS, which seems to get performed successfully and creates the two projects (ArduinoCore and my Sketch) but will then fail to build. With several "recipie for target ### failed" errors and an conflicting declaration error which I can't find the source of.I realise that just changing the microcontroller won't magically make my device consume a lot less power but what I'm trying to do is get the hardware correct this time, which would enable me to write more comprehensive power saving software later.

author: ataradov
author_rank: Super Contributor
timestamp: December 16, 2016, 04:20:03 pm
content: I have no idea about AS or Arduino import, I have not used either one, and I have a feeling that they are not fully there for non-trivial cases.

author: bluespider
author_rank: Contributor
timestamp: January 02, 2017, 08:46:52 pm
content: Just to update - I managed to get the Arduino core compiling in Atmel Studio for SAMD21. However I haven't yet managed for the SAML21 - the current problem seems to be that the SAMD21 Arduino Core expects a TC5 but one of the differences is that the SAML21 only TC's up to TC4.

author: Lajon
author_rank: Contributor
timestamp: January 03, 2017, 02:00:32 pm
content: SAMD21G and SAML21G have the same number of TC (3) so that can't be a big problem./Lars