mattairtech / SAMD-MSD-Bootloader

USB MSD (Mass Storage Device) bootloader for Atmel SAMD chips
Other
36 stars 10 forks source link

Compatibility with SAM D21 xplained pro board from Atmel #2

Open pozzugno opened 8 years ago

pozzugno commented 8 years ago

I would like to use your project as a starting point for a bootloader compatible with Xplained Pro board from Atmel. I'm going to use Atmel Studio (Windows OS) as IDE.

Any suggestions. I understood your project was compiled in Linux OS. However the gcc toolchain should be the same.

In Windows, I couldn't find the source code files of ASF. They are automatically imported in your project during ASF wizard. I understood, in Linux ASF installs source code directly.

pozzugno commented 8 years ago

Finally I compiled the project successfully under Atmel Studio 6.2 running in Windows 7 OS for SAM D21 Xplained Pro board. It works, great! The only problem, I have to delete the original FLASH.bin, before dragging the new firmware (but this is well written in README).

What I didn't understand is the virtual_flash_mem folder. It seems ASF already provides FAT (FatFS) service and Virtual Memory in RAM component. Why do you use your source code? Is it different from the original supplied by ASF?

mattairtech commented 8 years ago

Sorry about the late reply. Yes, Windows 7 (and later?) requires deleting the original file first. I don't think XP required this. It would really be nice to not have to do this, but I have not thought of a way.

First, this is an MSC device (MSD), which merely transfers 512 byte blocks of data between the host and the flash memory. MSC devices to not need any filesystem implementation. It is the host that needs to understand the filesystem. Some devices (cellphones) do implement FAT, but must unmount the filesystem from the phone OS before mounting to the computer OS using USB MSC (because it is simply a block device to the computer). Second, the flash memory must not actually contain any FAT structures (like the file allocation tables themselves). It can only contain the binary file that is transferred.

With these two things in mind, a minimal FAT implementation was needed, with FAT structures stored in the bootloader itself rather than anywhere in the rest of the flash. That's where the Virtual Memory folder comes in. This code basically can tell the difference between the FAT structures and the user binary, and it inserts/removes the FAT portions from the 512 byte blocks. This piece of code is the core of this bootloader, and it was written by Dean Camera of LUFA (www.lufa-lib.org) for an MSC bootloader for AVR 8-bit devices. Brilliant!

Note that ASF includes examples for an MSC based bootloader (sam0/applications/usb_msc_bootloader). However, this bootloader uses USB host mode to transfer data from a connected USB flash memory stick. I basically combined this ASF bootloader with the LUFA virtual memory code and some parts of another ASF example (USB MSC related).

rutvikna commented 7 years ago

Hey, Thank you for the detailed information about the samd21 bootloader. I tried to compile the project in Atmel Studio (Windows 10) but ran into a lot of build errors. Can you please elaborate on how you got it working in Windows.

Also, I am trying to implement USB MSC Device stack on my samd21 + uSD board. My code works fine but it takes around 3 mins to load a 2gb SD Card and reads a file 12KiB/s. Do you have any input on that?

Thanks in advance!

mattairtech commented 6 years ago

This is not setup to compile on Windows. However, it looks like https://github.com/watterott/SAM-BAR (both CDC and MSD) has Atmel Studio project files, so you might want to try that. My knowledge on Atmel ASF source code is limited, so I afraid that I can't help out on the second question.

rutvikna commented 6 years ago

Will look into that project. Thank you!