VS1010D USB Host Driver and MP3 play

Designing hardware and software for systems that use the VS1010 MP3 Audio DSP Microcontroller.
regh
Senior User
Posts: 39
Joined: Thu 2020-11-05 13:50

Re: VS1010D USB Host Driver and MP3 play

Post by regh »

I've been able to replicate this in my project application as well - I need to play something from the sd card first, then load usbhost4, then I can play something from the usb stick. I can work around this in my current application as we want a start up sound but I'm not comfortable with this kind of approach.
No, it's self contained, and thus unfortunately larger than the previous version.
For some reason I thought that this was going to be smaller than the usbhdd library used in the tree player viewtopic.php?f=15&t=2430, but looking back over the thread I see you don't actually state this. If memory serves correct I had worked out through trial and error I needed my application to have less than 2000 Instructions so as not to run out memory so had assumed all of the usb libraries combined came to ~2000 instructions, so after seeing usbhost4 only needed just over 1000 instructions thought I had more head room memory wise.
User avatar
Panu
VSDSP Expert
Posts: 2816
Joined: Tue 2010-06-22 13:43

Re: VS1010D USB Host Driver and MP3 play

Post by Panu »

Ok, just a quick comment since I'm in a hurry.. well, actually two. The crash-if-no-sd-play-first problem and the memory size.

First of all, congratulations for getting it to work!

1) Uhhh... I'm really sorry to hear that you are experiencing hang-up if not playing something from the SD card first. I am a little embarrassed about this, because I thought that problem was long gone. There's an old problem of calling the ROM's InitAudio when USB clock is active - this effectively leads to a code corner that switches off the active clock of the CPU, causing it to halt. I thought I had fixed it, but it seems to have creeped back. I can totally understand that I missed it, because my coding procedure involves booting with an SD card that has MP3 file in the root, that way is the fastest generic way to get into the command line shell. But it means that it always plays MP3 before I run anything. And the FM radio project for which I was developing the driver always played something first, so.... well, that's it basically.

Workaround 1 is to play R:HELLO.MP3 from the romdisk first. This is quick and easy and can be done from CONFIG.TXT but it's not elegant.
Workaround 2 might be to put a ioctl(stdaudioout, IOCTL_RESTART, NULL); to the beginning of your program to get the audio inited before loading USBHOST4. Can you see/test if that would work for you?

2) The memory usage... right, the previous driver was split in two so it uses all the memory in the beginning when it runs USBPROBE.DLX and then throws it away, leaving just the BlockRead part in memory. But this code, since I needed it to be able to quickly recover from USB errors, has it all always loaded, since you need the usbprobe and init code to do that anyway.

So, yeah.. I don't really remember what was the combined memory usage of usbhdd+usbprobe, but it might be that this new usbhost4 might actually be smaller than those two combined. In any case, it's certainly more stable.

It doesn't implement a BlockWrite method, so it's read only. Not sure if the old one did or not.

-Panu

-Panu
regh
Senior User
Posts: 39
Joined: Thu 2020-11-05 13:50

Re: VS1010D USB Host Driver and MP3 play

Post by regh »

Hi Panu

No worries, that's the advantage of the forum - you guys hear about these things quickly and give good support to users.
I've tried with ioctl(stdaudioout, IOCTL_RESTART, NULL); and ioctl(stdaudioout, IOCTL_RESTART, (IOCTL_ARGUMENT)4800); as Hannu suggested but neither options work. As I said, we can work with playing a startup sound as this is part of the product requirements but I assume other people may not want that. I take it it would also be fine playing from SPI Flash aswell (ideally we want to move the code and system sounds from the SD card to flash and play the main audio files from usb)? I haven't had a chance to move that over yet.

For memory usage, using the old library I couldn't add anything else into my code without getting out of memory errors. Using Usbhost4 I've been able to add more things to it which is great!
User avatar
Panu
VSDSP Expert
Posts: 2816
Joined: Tue 2010-06-22 13:43

Re: VS1010D USB Host Driver and MP3 play

Post by Panu »

Thanks for the report and great to see that your project is stabilizing. Strange that the IOCTL_RESTART didn't help, I thought it would for sure. But good that you have the workaround of playing a file in the beginning. It can be a silent file, too, and yes, it can play from SPI flash.

-Panu
regh
Senior User
Posts: 39
Joined: Thu 2020-11-05 13:50

Re: VS1010D USB Host Driver and MP3 play

Post by regh »

Is there a way to check whether there is a connection to a usb stick (storage) with this driver? The example project given with the old usb library has a function checkStatus() that checks whether the vs1010 is connected to a usb stick, a PC, or nothing. The pc detect still works but if the vs1010 is linked to a usb key the function thinks nothing is there (the actual library does still work and you can play audio from the usb stick). I'd like to be able to check that the connection to the usb stick is ok, so that if for any reason the connection breaks I can handle it gracefully. At the moment if the connection breaks, the device outputs E'Read when testing with Tera Term and I lose control until the usb stick is plugged back in again.
User avatar
Panu
VSDSP Expert
Posts: 2816
Joined: Tue 2010-06-22 13:43

Re: VS1010D USB Host Driver and MP3 play

Post by Panu »

Hmm, if you want to do it at the driver level, you probably could set player.auDec.cs.cancel = 1 right before the block read function in scsihost.c file returns S_ERROR, so any currently playing song would stop immediately and control returns to you from the player function. And perhaps also set player.auDec.pauseOn to zero, for completeness..

-Panu

Code: Select all

ioresult DevUsbBlockRead(register __i0 DEVICE *dev, u_int32 lba, u_int16 blocks, u_int16 *data){
	int r;
	memset(data, 0, 256);
	{
		u_int16 lo = (u_int16)lba;
		u_int16 hi = lba>>16;
		scsiCmdRead[8]  = (hi>>8)|(0<<13);
		scsiCmdRead[9]  = ((hi&0xFF)<<8)|(lo>>8);
		scsiCmdRead[10] = ((lo&0xFF)<<8)|0x0000;
	}
	if ((lba <= usbTotalSectors32) && (ScsiCommand(scsiCmdRead) == S_OK)) {
		memcpy(data, pktBuf, 256);
		return S_OK;
	}
	return S_ERROR;
	
}
Post Reply