Atmel SAM D21G18

Discussion and questions about boards that can run MicroPython but don't have a dedicated forum.
Target audience: Everyone interested in running MicroPython on other hardware.
Turbinenreiter
Posts: 288
Joined: Sun May 04, 2014 8:54 am

Atmel SAM D21G18

Post by Turbinenreiter » Wed Apr 06, 2016 5:41 pm

Atmel SAM D21G18 is a Cortex-M0+ with 256KB flash, 32KB of SRAM and 48MHz.

The Adafruit Feather Adalogger M0 uses this chip and I like that board a lot. The BBC micro:bit proves that a chip like that can run MicroPython.

I'm going to try to start a port and wanted to make this post to see if others are interested too. The first step is to get the toolchain running and figuring out the structure of the hardware libraries and this is pretty much all I accomplished today. The next step is taking the minimal port and make that run on the Atmel chip. After that, there is lot's and lot's of hardware libraries to port, but to be honest, let's see if I even get there.

Turbinenreiter
Posts: 288
Joined: Sun May 04, 2014 8:54 am

Re: Atmel SAM D21G18

Post by Turbinenreiter » Wed Apr 06, 2016 6:52 pm

I'm stuck at linking.
It throws lots of 'undefinded reference to '__aeabi_ ... - errors.
uidiv, idiv, idivmod - whatever that is.

Trying again tomorrow. Ideas welcome.

Code: Select all

include ../py/mkenv.mk

# qstr definitions (must come before including py.mk)
QSTR_DEFS = qstrdefsport.h

# include py core make definitions
include ../py/py.mk

CROSS_COMPILE = arm-none-eabi-

INC += -I.
INC += -I..
INC += -I$(BUILD)

CFLAGS_CORTEX_M0p = -mthumb -mcpu=cortex-m0plus
CFLAGS = $(INC) -Wall -Werror -ansi -std=gnu99 -nostdlib $(CFLAGS_CORTEX_M0p) $(COPT)

#Debugging/Optimization
ifeq ($(DEBUG), 1)
CFLAGS += -O0 -ggdb
else
CFLAGS += -Os -DNDEBUG
endif

LDFLAGS = -nostdlib -T samd21g18a_flash.ld -Map=$@.map --cref
LIBS =

SRC_C = \
	main.c \
#	printf.c \
	string0.c \
	malloc0.c \
	gccollect.c \

SRC_S = \
#	startup_stm32f40xx.s \
	gchelper.s \

OBJ = $(PY_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o) $(SRC_S:.s=.o))

all: $(BUILD)/firmware.elf

$(BUILD)/firmware.elf: $(OBJ)
	$(ECHO) "LINK $@"
	$(Q)$(LD) $(LDFLAGS) -o $@ $^ $(LIBS)
	$(Q)$(SIZE) $@

include ../py/mkrules.mk

Code: Select all

LINK build/firmware.elf
build/py/mpprint.o: In function `mp_print_int':
mpprint.c:(.text+0x134): undefined reference to `__aeabi_uidivmod'
mpprint.c:(.text+0x13e): undefined reference to `__aeabi_uidiv'
build/py/scope.o: In function `scope_new':
scope.c:(.text+0x1e): undefined reference to `__gnu_thumb1_case_uqi'
build/py/runtime.o: In function `mp_binary_op':
runtime.c:(.text+0x53e): undefined reference to `__gnu_thumb1_case_uqi'
build/py/map.o: In function `mp_map_lookup':
map.c:(.text+0x13c): undefined reference to `__aeabi_uidivmod'
map.c:(.text+0x16e): undefined reference to `__aeabi_uidivmod'
map.c:(.text+0x252): undefined reference to `__aeabi_uidivmod'
map.c:(.text+0x292): undefined reference to `__aeabi_uidivmod'
build/py/objbool.o: In function `bool_unary_op':
objbool.c:(.text+0x8): undefined reference to `__gnu_thumb1_case_uqi'
build/py/objint.o: In function `mp_obj_int_formatted':
objint.c:(.text+0x11a): undefined reference to `__aeabi_uidiv'
objint.c:(.text+0x12a): undefined reference to `__aeabi_uidiv'
objint.c:(.text+0x1a8): undefined reference to `__aeabi_idivmod'
objint.c:(.text+0x1b2): undefined reference to `__aeabi_idiv'
build/py/objrange.o: In function `range_len':
objrange.c:(.text+0x46): undefined reference to `__aeabi_idiv'
build/py/smallint.o: In function `mp_small_int_mul_overflow':
smallint.c:(.text+0x10): undefined reference to `__aeabi_idiv'
smallint.c:(.text+0x22): undefined reference to `__aeabi_idiv'
smallint.c:(.text+0x36): undefined reference to `__aeabi_idiv'
build/py/smallint.o:smallint.c:(.text+0x50): more undefined references to `__aeabi_idiv' follow
build/py/smallint.o: In function `mp_small_int_modulo':
smallint.c:(.text+0x6c): undefined reference to `__aeabi_idivmod'
build/py/smallint.o: In function `mp_small_int_floor_divide':
smallint.c:(.text+0xa0): undefined reference to `__aeabi_idiv'
build/py/../extmod/modubinascii.o: In function `mod_binascii_b2a_base64':
modubinascii.c:(.text+0x98): undefined reference to `__aeabi_uidiv'
Makefile:45: recipe for target 'build/firmware.elf' failed
make: *** [build/firmware.elf] Error 1

User avatar
danicampora
Posts: 342
Joined: Tue Sep 30, 2014 7:20 am
Contact:

Re: Atmel SAM D21G18

Post by danicampora » Wed Apr 06, 2016 7:39 pm

To me it looks like you are not linking with libm. Try to add -lm to the linker flags.

Cheers,
Daniel

Turbinenreiter
Posts: 288
Joined: Sun May 04, 2014 8:54 am

Re: Atmel SAM D21G18

Post by Turbinenreiter » Wed Apr 06, 2016 8:22 pm

Code: Select all

arm-none-eabi-ld: cannot find -lm
but:

Code: Select all

:$ ls /usr/arm-none-eabi/lib/armv6-m/ | grep libm
libm.a
I added

Code: Select all

–gc-sections'
and now it links. :shrug:

User avatar
danicampora
Posts: 342
Joined: Tue Sep 30, 2014 7:20 am
Contact:

Re: Atmel SAM D21G18

Post by danicampora » Wed Apr 06, 2016 9:39 pm

Ummm that's not a good sign. I bet that math operations relying on the functions that were not found before will crash...

Cheers,
Daniel

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Atmel SAM D21G18

Post by dhylands » Thu Apr 07, 2016 1:55 am

Those functions come from libgcc. They're typically used to support integer/floating point math operations that the CPU doesn't support natively.

When you link with -nostdlibs, then libgcc is not included in the link.

You can use this little bit of gcc "magic" to determine the correct name of the libgcc.a for the particular set of options being used to build (make sure that you pass in the same options that are used when compilng the C files). There can be several variants of libgcc.a for a given MCU (for example with soft-float, hard-float, or other things).
https://github.com/micropython/micropyt ... kefile#L50

I also highly recommend that you link using gcc rather than ld. Sometimes it takes a bit more effort to get the right flags to be passed through to the linker, but linking with ld directly can sometimes cause grief.

For the gory details if you call gcc with the -v flag you can see the options that it passes to collect2 (which is more or less the linker when gcc does the linking).

tannewt
Posts: 51
Joined: Thu Aug 25, 2016 2:43 am

Re: Atmel SAM D21G18

Post by tannewt » Thu Aug 25, 2016 2:56 am

I wanted to bump this thread because I've started porting MicroPython to the SAMD21G18 for Adafruit.

I have the basics, REPL, time, and machine.Pin all working on both the Arduino Zero and Adafruit Feather M0 BLE. The code is available on their micropython repo: https://github.com/adafruit/micropython

Next, I'm looking at getting the ADC going and also the file storage. Any tips there? It looks like each port has its own method for storing files in flash.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Atmel SAM D21G18

Post by dhylands » Thu Aug 25, 2016 8:03 am

I think it really depends on the amount of free flash that you have after loading the firmware.

It also depends on the erase size of the flash.

tannewt
Posts: 51
Joined: Thu Aug 25, 2016 2:43 am

Re: Atmel SAM D21G18

Post by tannewt » Fri Aug 26, 2016 12:23 am

Thanks for the reply! Its 256KB of flash storage and the current code weighs in at ~80KB I think. Looking at some other implementations it seemed that 64KB was pretty common and should fit easily. Page size is 64 bytes. Is that the same as erase size? The datasheet is here: http://www.atmel.com/Images/Atmel-42181 ... asheet.pdf

User avatar
marfis
Posts: 215
Joined: Fri Oct 31, 2014 10:29 am
Location: Zurich / Switzerland

Re: Atmel SAM D21G18

Post by marfis » Fri Aug 26, 2016 8:41 am

great to see that adafruit is increasing the support for micropython!

And personally i like that M0+ devices may be supported in the near future.

that is going to give a boost for uPy in the maker community.

Post Reply