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.
User avatar
dhylands
Posts: 3268
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Atmel SAM D21G18

Post by dhylands » Fri Aug 26, 2016 5:30 pm

tannewt wrote: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
I'm not sure. The datasheet talks about erasing rows and writing pages, but doesn't seem to define what a row actually is. The fact that they're different implies that a row is bigger than a page (and it's very typical that the erase granularity is bigger than the write granularity).

Actually it looks like a row is made up of 4 pages, so that would make the erase granularity be 256 bytes, which seems small enough to host a filesystem. I think that vFAT wants 512 byte sectors, so you could make each sector be 2 rows. This means reserving 512 bytes as a flash buffer, but that seems reasonable.

So if you added a 64K filesystem that still gives you up to 192K of flash space.

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

Re: Atmel SAM D21G18

Post by tannewt » Fri Aug 26, 2016 7:01 pm

Thanks Dave! Would you mind pointing me to the code that FatFS calls out to for the actual reading and writing? I've looked through the other ports but can't figure out how to provide that low level piece. Is it different from the extmod/vfs code?

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

Re: Atmel SAM D21G18

Post by dhylands » Fri Aug 26, 2016 8:05 pm

The stmhal code for interfacing can be found in storage.c
https://github.com/micropython/micropyt ... #L408-L418
And pyb_flash_init_vfs is called here:
https://github.com/micropython/micropyt ... #L171-L175

This is where sdcard support gets hooked in:
https://github.com/micropython/micropyt ... #L443-L453
https://github.com/micropython/micropyt ... #L487-L496

So the basic flow goes something like C code calls f_xxx which winds up calling down to a lower level in fatfs called diskio, which is implemented here:
https://github.com/micropython/micropyt ... t_diskio.c
and that then calls the functions which implement the low-level block API (in sdcard.c or storage.c)

For native support, those functions then call through the appropriate vfs function pointer. For example, disk_read calls readblocks here:
https://github.com/micropython/micropyt ... kio.c#L125

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

Re: Atmel SAM D21G18

Post by tannewt » Sat Aug 27, 2016 8:37 pm

Thanks for the awesome pointers Dave! I've got PWM and DAC support on my list before the file system so it'll be a few days until I get it going.

Post Reply