VS1010D USB Host Driver and MP3 play

Designing hardware and software for systems that use the VS1010 MP3 Audio DSP Microcontroller.
User avatar
Panu
VSDSP Expert
Posts: 2829
Joined: Tue 2010-06-22 13:43

VS1010D USB Host Driver and MP3 play

Post by Panu »

Dear VS1010 users,

Here's a new take on the VS1010 USB Host functionality. The USB host code has been rewritten for VS1010D. Here's a self-contained program that combines USB host functionality with a simple main loop, which repeatedly asks the user to insert a new USB flash memory stick and then plays MP3 files from the root of the flash memory stick.
VS1010>usbplaytest
Please insert USB flash..
VendorID:0781 ProductID:5567
Scan and init filesystem...
Device '15264M USB store' has FAT filesystem, good. Playing *.MP3 from root..

Crockett's Theme 12 inch.mp3

Code: Select all

ioresult main (char *params) {
	int attempts = 0;
	ioresult r;
	PowerSetVoltages((void*)(&regulator));
	VODEV('U') = &usbFlash;
			
	while (lastReceivedCharUart0 != 27) {		
		printf("Please insert USB flash..\n");		
		while (UsbDeviceProbe()) {
			DelayL(10000);
		}

		printf("VendorID:%04X ProductID:%04X\n",Swap16(udp->vid),Swap16(udp->pid));
		printf("Scan and init filesystem...\n");
		
		if (ioctl(&usbFlash, IOCTL_RESTART, NULL) == (IOCTL_RESULT)&FatFileSystem) {
			printf("Device '%s' has FAT filesystem, good. Playing *.MP3 from root..\n", Identify(VODEV('U')));
			shellcmd("play","U:*.MP3");
		} else {
			printf("Init error at ioctl_restart\n");
		}
		
		printf("Done, please remove USB flash..\n");
		
		usbTotalSectors32 = 0;		
		Xvm((void*)resetUsbHostHw); // Set initial state				
		while ((PERIP(USB_UTMIR) & USB_UTMIR_LSTATE) != 0) {
			//Wait for no stick
		}

		printf("USB device disconnected\n");
	}
	VODEV('U') = NULL;
	return S_OK;
}
-Panu
Attachments
usbPlayTest.dlx
Plays MP3 files from USB memory sticks. VS1010 VSOS DLX executable
(8.8 KiB) Downloaded 269 times
arch-usbPlayTest-2021-02-04-10-44-RC1.zip
Source code, VSIDE Solution
(30.9 KiB) Downloaded 278 times
User avatar
Panu
VSDSP Expert
Posts: 2829
Joined: Tue 2010-06-22 13:43

Re: VS1010D USB Host driver

Post by Panu »

Dear All,

Here's the driver proper extracted from the above project. Run this once from the command line or from CONFIG.TXT. It creates an auto-reconfiguring device U: for the USB flash. Uses 1069 words of code memory and 565 words of X data memory.

VS1010>usbhost4
USB: 7377M USB store

VS1010>liblist
0: 0x1000:UsbHost4.dl I[0x80..0x4ad] X[0x1000..0x1249] Y[0x1000..0xfff]
1: 0x124a:LIBLIST.DLX I[0x4ae..0x51f] X[0x124a..0x12cd] Y[0x1000..0xfff]

VS1010>devices
D: SD/SD Card
F: SPI Flash c217
I: STREAM
R: ROMDISK
S: SD/SD Card
U: 7377M USB store

VS1010>dir u:
File list of 7377M USB store u:*
D 1: uc232a_windows_setup_v1.0.084
D 2: vside_cable_driver
3: 01_5AM.MP3
4: 07_Beauty.mp3
5: 10_AndThen.mp3
6: putty-0.72-installer.msi
7: teraterm-4.102.exe
7 file(s) found.

VS1010>
-Panu
Attachments
UsbHost4.dlx
USB Host Driver for VS1010D. Run exactly once from the command line or from config.txt.
(7.65 KiB) Downloaded 265 times
arch-UsbHost4-2021-02-04-12-21-USBHostDriverVS1010.zip
VS1010D USB Host Driver Source Code, VSIDE Solution.
(34.61 KiB) Downloaded 284 times
regh
Senior User
Posts: 43
Joined: Thu 2020-11-05 13:50

Re: VS1010D USB Host Driver and MP3 play

Post by regh »

Hi Panu

This seems like a great upgrade to the usb functionality (I'm currently hitting the limit in terms of memory with my current usb application). Does this have to use the Decoder functions in the example code you've given or can playing files still be done the old way ie

set player.fileSpec to file path you want to play (for usb playing)
player.currentFile = 0; //don't use rom track numbering
PlayerPlayFile(); //play the audio

I'm able to read some files (.txt files with configuration data) and do a count of mp3 files using wildcards with fopen("u:tracks/*.MP3", mode), where mode is a string in form "rb#%d" but if I try to do something more specific like set the fileSpec to "u:tracks/003.mp3" and call PlayerPlayFile() or try to check the file exists with something like fopen("u:tracks/003.mp3", "rb#0") then the player just locks up - I don't get any error messages through tera term but the device just seems to be stuck in these functions and won't come out. When calling PlayerPlayFile() it doesn't seem to go into the callback as it doesn't respond to any button presses.

Any ideas what is happening? Ideally I'd like to leave my code as is but load the new usb driver. However if I need to use the new structure laid out in the new examples then so be it.

Thanks,
Reg
Hannu
VLSI Staff
Posts: 512
Joined: Mon 2016-05-30 11:54
Location: Finland
Contact:

Re: VS1010D USB Host Driver and MP3 play

Post by Hannu »

Hi regh

Just a quick stab in the dark.
Does your player work with files on SD card? As I couldn't see anything which would break the decoders.

If you can use "play U:tracks/*.mp3" and then you player works, then you have some init code missing (or the USB host code overwrites something)

Adding "ioctl(stdaudioout, IOCTL_RESTART, (IOCTL_ARGUMENT)4800); //48k/16b" is sometimes a good idea to make sure the DAC is enabled.
regh
Senior User
Posts: 43
Joined: Thu 2020-11-05 13:50

Re: VS1010D USB Host Driver and MP3 play

Post by regh »

Hi Hannu
Thanks for the quick response.
Yes it is able to play from the sd card - the way the application is set up is that there are some system sounds (power on etc) that are played from the sd card using PlayFromFile(). I've tried using this function to play files from the usb and shellcmd("play","u:tracks\\003.mp3"); and it still just locks up. I've also added ioctl(stdaudioout, IOCTL_RESTART, (IOCTL_ARGUMENT)4800); //48k/16b to my setup code (before the USB library is loaded) and it's still not working.
regh
Senior User
Posts: 43
Joined: Thu 2020-11-05 13:50

Re: VS1010D USB Host Driver and MP3 play

Post by regh »

I've also found that if no usb stick is connected then I get the following messages on TeraTerm

USB: No flash
E'Out of Mem 0!'

Does that give any indication (other than I need to put checks in that usb connection is ok)?
I'm running this on the VS1010 development board v1.4.
User avatar
Panu
VSDSP Expert
Posts: 2829
Joined: Tue 2010-06-22 13:43

Re: VS1010D USB Host Driver and MP3 play

Post by Panu »

Hi!

Have you tried to just load the driver from the command line and play some MP3 file from a USB flash? Does it work properly?

e.g. just give the command usbhost4, then maybe "devices" to see that it's loaded, maybe "dir u:" to get a file list and then "play u:*.mp3" to play some songs?

The "out of memory 0" error doesn't indicate a problem. But it leads me to suspect that you might be loading the driver twice..? You should just run the driver from the CONFIG.TXT if possible. If you run it twice, then it is loaded twice and uses twice the memory. If you want to load it temporarily, then you need to load it using something like void *usb = LoadLibrary("USBHOST4",NULL); and after using it drop it with DropLibrary(usb); although I'm not 100% sure that that works, because of the automatic terminate-stay-resident functionality of the library.

Preferably just load it from CONFIG.TXT at boot.

Code: Select all

I'm running this on the VS1010 development board v1.4.
Note that the data lines in v1.4 developer board might be reversed, so you need an adapter to reverse DP, DN lines.
-Panu
regh
Senior User
Posts: 43
Joined: Thu 2020-11-05 13:50

Re: VS1010D USB Host Driver and MP3 play

Post by regh »

Hi Panu

I've tried both both loading it from the Config.txt file and using RunLib("USBHOST4",NULL) and both give the same results. Using LoadLibrary causes the USB drive to not be detected at all. The out of error message occurred when it was only loaded the once (using RunLib).

I've tried your suggestions with the command line and it still won't play. I'm able to see all of the files on the usb stick but when I play I get the following
VS1010>play u:*.MP3
Relocked (3007)
002.MP3

This has happened on two usb sticks that worked with the old versions of the usb drive.
The new usb library only needs USBHOST4 to work correct? I don't need any of the old usbhdd or probe libraries?

I've got the usb adapter for the board that swaps DP/DM lines and have been able to play audio from a usb key using older usb libraries from VLSI.
User avatar
Panu
VSDSP Expert
Posts: 2829
Joined: Tue 2010-06-22 13:43

Re: VS1010D USB Host Driver and MP3 play

Post by Panu »

I've tried your suggestions with the command line and it still won't play. I'm able to see all of the files on the usb stick but when I play I get the following
VS1010>play u:*.MP3
Relocked (3007)
002.MP3
Ok. And it's not just something silly, like CR+LF instead of CR in the terminal settings? If you terminate the play u:*.MP3 command with a [Tab] instead of [Enter], does it play then?

Does it play the same file from an SD card?

The new usb library only needs USBHOST4 to work correct? I don't need any of the old usbhdd or probe libraries?
No, it's self contained, and thus unfortunately larger than the previous version. Hmm, if you run into a dead end with 0:program memory simply just not being enough, you can take a look at startfm.dlx's source code at viewtopic.php?f=15&t=2764, it gives you 2 extra kilowords by cleverly rearranging the memory.
startfm.dlx - the loader
Starts the application. Extends program memory by combining the normal code area with FC extended code area. Loads USB Host (usb flash stick) driver (usbhost4). Runs each executable as indicated by app.mode. Takes over TIMER2 and scans for POWER button. Long press of power button resets the system to runlevel 17 : fmsetup mode.
-Panu
regh
Senior User
Posts: 43
Joined: Thu 2020-11-05 13:50

Re: VS1010D USB Host Driver and MP3 play

Post by regh »

Hi Panu

I had the terminal set to cr+lf instead of cr, changing to cr I am now able to play but only under certain circumstances.

I can play from the usb stick if I do the following commands after booting in shell mode (runtime 8) (all pressing return to send the commands):

Code: Select all

VS1010>play s:sounds/ac_chapter_up.mp3
ac_chapter_up.mp3

VS1010>usbhost4
USB: 3824M USB store

VS1010>play u:tracks/002.mp3
002.MP3
However, if I don't play from the sd after booting into shell mode the device freezes:

Code: Select all

VS1010>usbhost4
USB: 3824M USB store

VS1010>play u:tracks/002.mp3
Relocked (3007)
002.MP3
The device just freezes (doesn't respond to any typing on the terminal) and I have to reset it
Post Reply