Limpkin's blog - Tag - ARM<div>An electronics geek blog, dedicated to sharing and open source. Check out my stores: <a href="https://lectronz.com/stores/stephanelec" hreflang="en" title="Lectronz store">EU</a> / <a href="https://www.tindie.com/stores/stephanelec" hreflang="en" title="tindie store">EU & US</a>.</div>2024-03-29T00:41:47+00:00Mathieuurn:md5:51de6a3d917257edeff5a252fe925b02DotclearAtsam3u + SDCard + USB cdc/msd + fat32 with at91lib & Chan's fat codeurn:md5:e7ae1913e881045b866e8cf92b1da4c12012-12-04T13:03:00+00:002024-03-09T10:37:52+00:00limpkinMy ProjectsARMAT91LIBATSAM3UCDCCortex m3FAT32MSDusb<p>Yep, for the first time this will be (mostly) a <strong>code</strong> article :-) .<br>
But if one day you want to make a <strong>Hi-Speed</strong> (480Mbit/s) USB composite device with <strong>CDC</strong> (communication) and <strong>MSD</strong> (mass storage) classes, this is the post you'll want to read.<br><br>
<img src="https://www.limpkin.fr/public/modules_code/.pcb_platform_m.jpg" alt="Platform PCB" class="media-center" title="Platform PCB, déc. 2012"></p> <p>At my current job we're currently working on a complete open software & hardware development platform for physicists,biologists.... <strong>hobbyists</strong>.<br>
This development platform is primarily aimed at facilitating the realization of high speed (several GHz) functions that quantum physicist need for their experiments, as well as providing data collection capabilities.<br>
Without going into many details, it will physically be a 3U rack where users can plug different eurocard modules that perform specific functions.<br></p>
<p>The platform is <strong>open hardware/software</strong> for <strong>Windows and Linux</strong>, which actually made the project's start quite difficult.<br>
Anyway, the chosen microcontroller is a cortex-m3 based ATSAM3U from Atmel, that provides <strong>USB 2.0</strong> connectivity.<br></p>
<p><a href="https://www.limpkin.fr/public/modules_code/module.png" title="Architecture"><img src="https://www.limpkin.fr/public/modules_code/.module_m.jpg" alt="Architecture" class="media-center" title="Architecture, déc. 2012"></a>
Each module put in the 3U rack will be connected by USB to a main computer.<br>
When connected, it will be recognized as a storage device in order to <strong>send to the computer the files required to operate it</strong> (matlab/labview/etc etc) and also be recognized as a communication device for the computer <strong>to send commands to the module</strong>.<br>
For this project, we therefore needed (from the host computer) to:<br>
- read/write data to a micro SDCard connected to the uC<br>
- dialog with the uC<br>
and from the microcontroller:<br>
- read all the files stored on the SDCard<br></p>
<p>The developments tools we then chose are:<br>
- <strong><a href="http://www.kicad-pcb.org/display/KICAD/KiCad+EDA+Software+Suite" hreflang="en" title="Kicad">Kicad</a></strong> for schematics and routing<br>
- <strong><a href="http://www.yagarto.de/" hreflang="en" title="Yagarto">Yagarto</a> and Eclipse</strong> for the hardware code<br></p>
<p>And for debugging, we picked the Segger J-Link JTAG:<br></p>
<p><a href="https://www.limpkin.fr/public/modules_code/segger.jpg" title="Segger J-Link"><img src="https://www.limpkin.fr/public/modules_code/segger.jpg" alt="Segger J-Link" class="media-center" title="Segger J-Link, déc. 2012"></a><br>
As you can guess, developping this kind of code from scratch can be <strong>insanely</strong> time consuming (I mean <strong>weeks</strong> of coding).<br>
Therefore, there was no other choice than to find libraries that provide a USB Stack with CDC/MSD classes, SDCard interfacing, FAT32 reads, while also supporting <strong>DMA transfers</strong>.<br></p>
<p>As you may know, I <strong>hate</strong> using libraries. They are usually not well documented and you have <strong>no clue</strong> on how they internally work.<br>
Well, after having spent a few days browsing through them, this impression was <strong>justified</strong>.<br>
But I finally managed to get things working with:<br>
- the AT91lib from gnumonks<br>
- the fat library from <a href="http://elm-chan.org/fsw/ff/00index_e.html">chan</a><br></p>
<p>As parts of the at91lib don't officially support the ATSAM3U, there were very few tweaks to do (mentionned in the main.c). There was one particular bug that took me 4 days to find (ATSAM3U DPRAM initialization).<br>
Finding all the files & flags to include in the makefile was quite a challenge, so I hope I'll save you the trouble. With one cheap micro SDCard, we managed to get <strong>5.5Mbyte/s writes</strong>. We (yet) haven't tried with other cards.<br></p>
<p>Anyway, here is the Eclipse source code, which is still in <strong>beta</strong> : <a href="https://www.limpkin.fr/public/modules_code/eclipse_template_code.rar">Eclipse template code</a><br>
Please note that this firmware doesn't have fancy options such as card detection (which we didn't need).<br></p>
<p><a href="https://www.limpkin.fr/public/modules_code/platform.png" title="Platform"><img src="https://www.limpkin.fr/public/modules_code/.platform_m.jpg" alt="Platform" class="media-center" title="Platform, déc. 2012"></a><br>
<a href="https://www.limpkin.fr/public/modules_code/pcb_platform.jpg" title="Platform PCB"><img src="https://www.limpkin.fr/public/modules_code/.pcb_platform_m.jpg" alt="Platform PCB" class="media-center" title="Platform PCB, déc. 2012"></a><br>
For those who are curious about the platform, here are the schematics of the two boards (also in beta) : <a href="https://www.limpkin.fr/public/modules_code/schematics_host.pdf" hreflang="en" title="gnumonks at91lib">Schematics host</a> <a href="https://www.limpkin.fr/public/modules_code/schematics_template.pdf" hreflang="en" title="gnumonks at91lib">Template schematics</a> .<br>
The PCB files will soon be released ;-) .<br></p>
<p>Cheers!<br></p>