Configure SAM4S (xplained pro) for USB Host Mass Storage

Go To Last Post
9 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Has any configured their SAM4S xplained pro USB for access the file system (Mass Storage)? Following this guide:

http://asf.atmel.com/docs/3.34.1/sam4s/html/udi_msc_quickstart.html

renders a ton of compiler errors.

I am looking for some guidance on how to configure USB mass storage.

Thx

 

"When all else fails, read the directions"

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

** BUMP **

"When all else fails, read the directions"

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What errors are you getting? And are you trying to configure a device or host USB application?

Is there a built-in ASF example? If so you should try that one first

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

rfoo wrote:
What errors are you getting

 

I am trying to use FatFs to read from the USB Host Mass Storage and I get the following error:

 

Output


SAM4S USB Example

USB Mounted!

[FAIL] res 3
(3) The physical drive cannot work

I am able to mount the USB, but can not read from it. ASF for the SAM4S has only 1 USB module (library) available:

 

 

Here is my code:

#include <asf.h>
#include "conf_usart.h"
#include <string.h>

#define VIRTUAL_MEMORY_ENABLE
#define USB_MASS_STORAGE_ENABLE



/* FATFS variables */
static FATFS fs;
static FIL file_object;
char buff[256];
const char firmware_filename[] = {"Sam4S_Test.txt"};
char *search_var;

void task(void);
void print_fs_result(FRESULT res);
void read_usb(void);
FRESULT scan_files (char* path);

int main (void)
{
	sysclk_init();
	irq_initialize_vectors();
	cpu_irq_enable();
	board_init();
	configure_uart(115200);
	udc_start();
	printf("SAM4S USB Example\n\r");
	read_usb();

	while (1) {
	}
}

void read_usb(){

	volatile uint8_t lun = LUN_ID_USB;
	/* Mount drive */
	memset(&fs, 0, sizeof(FATFS));
	FRESULT res = f_mount(lun, &fs);
	if (FR_INVALID_DRIVE == res) {
		printf("Mount Failed!\n\r");
		return;
	}else{
		printf("USB Mounted!\n\r");
	}
	strcpy(buff, "/");
	res = scan_files(buff);
	if(res != FR_OK){
		printf("[FAIL] res %d\r\n", res);
		print_fs_result(res);
		return;

	}
	f_close(&file_object);

}

FRESULT scan_files (char* path)
{
	FRESULT res;
	DIR dir;
	UINT i;
	static FILINFO fno;

	res = f_opendir(&dir, path);                       /* Open the directory */
	if (res == FR_OK) {
		for (;;) {
			res = f_readdir(&dir, &fno);                   /* Read a directory item */
			if (res != FR_OK || fno.fname[0] == 0) {

				break;  /* Break on error or end of dir */
			}
			if (fno.fattrib & AM_DIR) {                    /* It is a directory */
				i = strlen(path);
				sprintf(&path[i], "/%s", fno.fname);
				res = scan_files(path);                    /* Enter the directory */
				if (res != FR_OK) break;
				path[i] = 0;
			} else {

				printf("%s/%s - %lu bytes kb\n\r", path, fno.fname, fno.fsize);

			}
		}

	}

	return res;
}
void print_fs_result(FRESULT res){

	switch(res){
		case FR_OK:			/* (0) Succeeded */
		printf("(0) Succeeded");
		break;
		case FR_DISK_ERR:
		printf("(1) A hard error occurred in the low level disk I/O layer");
		break;
		case FR_INT_ERR:
		printf("(2) Assertion failed");
		break;
		case FR_NOT_READY:
		printf("(3) The physical drive cannot work");
		break;
		case FR_NO_FILE:
		printf("(4) Could not find the file");
		break;
		case FR_NO_PATH:
		printf("(5) Could not find the path");
		break;
		case FR_INVALID_NAME:		/*  */
		printf("(6) The path name format is invalid");
		break;
		case FR_DENIED:
		printf("(7) Access denied due to prohibited access or directory full");
		break;
		case FR_EXIST:
		printf("(8) Access denied due to prohibited access");
		break;
		case FR_INVALID_OBJECT:
		printf("(9) The file/directory object is invalid");
		break;
		case FR_WRITE_PROTECTED:
		printf("(10) The physical drive is write protected");
		break;
		case FR_INVALID_DRIVE:
		printf("(11) The logical drive number is invalid");
		break;
		case FR_NOT_ENABLED:
		printf("(12) The volume has no work area ");
		break;
		case FR_NO_FILESYSTEM:
		printf("(13) There is no valid FAT volume");
		break;
		case FR_MKFS_ABORTED:
		printf("(14) The f_mkfs() aborted due to any parameter error");
		break;
		case FR_TIMEOUT:
		printf("(15) Could not get a grant to access the volume within defined period");
		break;
		case FR_LOCKED:
		printf("(16) The operation is rejected according to the file sharing policy");
		break;
		case FR_NOT_ENOUGH_CORE:
		printf("(17) LFN working buffer could not be allocated");
		break;
		case FR_TOO_MANY_OPEN_FILES:
		printf("(18) Number of open files > _FS_SHARE");
		break;
		case FR_INVALID_PARAMETER:
		printf("(19) Given parameter is invalid");
		break;
		default:
		printf("Unknown Error Code %d", res);
		break;
	}
	printf("\n\r");
}

Any ideas?

"When all else fails, read the directions"

Last Edited: Thu. Jun 15, 2017 - 10:27 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Does this need an external flash for this to work? I'm not super familiar with the MSC classes but it seems that it cannot read the external storage / it doesn't exist.

 

You also said you were getting a ton of compiler errors but your output shows that it did compile and run? Could you clarify that please? Thanks!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

rfoo wrote:
You also said you were getting a ton of compiler errors but your output shows that it did compile and run? Could you clarify that please? Thanks!

Hi thanks for helping.

 

No, there are no compile errors. The message I posted was an error code returned by the FatFS library. The FatFS library can't open the directory. Further investigation, the FatFS library fails on disk initialization (FR_NOT_READY). Clearly I am not configuring the library correctly.

"When all else fails, read the directions"

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Does the SAM4S really support USB Host? From a quick look at the Peripherals list in the data sheet it does not. Another hint, the SAM devices that do support host (e.g., SAM4L, SAMD21) seem to have ASF examples (including mass storage).

/Lars

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Lajon wrote:
Does the SAM4S really support USB Host?

Good question. For example, the SAMD21 datasheet states 

One full-speed (12Mbps) Universal Serial Bus (USB) 2.0 interface
 - Embedded host and device function

Where as the SAM4S data sheet states

The peripheral set includes a full-speed USB Device port with embedded transceiver,

However the SAM4S does make reference the "USB HOST"... for example:

When the USB block is in suspend mode, the application may power down the USB logic. In this case, any USB HOST resume 
request that is made must be taken into account and, thus, the reset value of the RXRSM bit of the register UDP_IMR is enabled.

I know little to nothing about the USB protocol. I assume you are correct because after digging through the ASF library, there is no way to enable LUB_USB for the SAM4S which I believe is used to communicate with the HOST USB. If the macro LUN_USB is enabled, the compiler looks for header files that simply do not exists. Perhaps I have been chasing a white rabbit...

 

Thanks for the help.

 

"When all else fails, read the directions"

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yea I looked it up as well and I don't think SAM4S supports USB host. You might have to switch for a different ARM! :(