STM32 WebRadio player

What are you developing?
User avatar
Vassilis
Posts: 295
Joined: Thu May 21, 2015 6:42 am
Location: Thessaloniki, Greece
Contact:

STM32 WebRadio player

Post by Vassilis » Sun May 31, 2015 5:51 pm

I successfully managed to combine the VS1053B MP3 decoder and ENC28J60 ethernet module and played web radio stations!
For those who doesn't know what looks like my new STM32 project, please visit my web site to see the same project I built a few months ago by using an Arduino pro mini

http://www.serasidis.gr/circuits/Arduin ... player.htm

Stay tuned for source code !

User avatar
ahull
Posts: 1544
Joined: Mon Apr 27, 2015 11:04 pm
Location: Sunny Scotland
Contact:

Re: STM32 WebRadio player

Post by ahull » Sun May 31, 2015 9:11 pm

Can the STM32F103 manage 128Kbit audio?
- Andy Hull -

User avatar
mrburnette
Posts: 1794
Joined: Mon Apr 27, 2015 12:50 pm
Location: Greater Atlanta
Contact:

Re: STM32 WebRadio player

Post by mrburnette » Sun May 31, 2015 10:33 pm

ahull wrote:Can the STM32F103 manage 128Kbit audio?
Op's Pro Mini test resulted in:
WebRadio player successfully managed to play 320 kbps mp3 audio streams that are stored on my local network!

Ray

victor_pv
Posts: 1472
Joined: Mon Apr 27, 2015 12:12 pm

Re: STM32 WebRadio player

Post by victor_pv » Mon Jun 01, 2015 2:33 am

Vassilis, I was having a look at the 1003 library, and I see it some times sends blocks of data to the device.
The STM32F1 has a DMA controller that can be configured to send a block of data from memory to the SPI peripheral.
If you think your applications can benefit from it, I can give you some information on how it works. Libmaple includes a number of low level functions to configure the DMA transfers, and on top we have included some functions in the STM SPI library. Although those may be moved to a separate library, but the use would stay pretty much the same.
Right now the DMA transfer functions in the SPI library are blocking, because most applications do not expect an SPI transfer to return before it is finished, and would toggle the CS line right away. But using the low level DMA in your code, if you know there is something else unrelated to the SPI that you want to do (like usart transfers, or IO with a different interface, etc), you can write a DMA SPI function that is non blocking so it fires the transfer to the 1003 and releases the CPU to do something else.

Also, no sure if an RTOS may be of any benefit for your application, but I have tested FreeRTOS and CoOS, and they work pretty well. That may help in scheduling other stuff in the CPU while the DMA controller uses SPI peripheral a block transfer, like updating a screen or getting data from the network.

EDIT: Looks like the ENC28j60 also uses SPI. Not sure if you knew already but the STM32F1 has 2 spi ports, so you could use the second port for one peripheral if you are going to use both at the same time. That way it's easier to keep them at different speeds, and you can use both at the same time, while one is reading to a buffer then other can be writing from a different buffer.

User avatar
Vassilis
Posts: 295
Joined: Thu May 21, 2015 6:42 am
Location: Thessaloniki, Greece
Contact:

Re: STM32 WebRadio player

Post by Vassilis » Mon Jun 01, 2015 7:55 am

Victor, Thanks for helping me!
The problem that has the Arduino web Radio player is that the RAM buffer is too small to cover any network delay (the data transfer time from the Icecast server to the webRadio player).
The result is to get some random short cracks in sound. The F103 has 20 kB of RAM and the DMA feature. With these two features I think I can overcome that problem (I hope).

I thing the RAM_buffer must be used as a FiFo stack (First in, First out).

I know about the second SPI. I will study previous libraries that use DMA.

I think I have a lot of things to write on that sketch before I publish it...

victor_pv
Posts: 1472
Joined: Mon Apr 27, 2015 12:12 pm

Re: STM32 WebRadio player

Post by victor_pv » Mon Jun 01, 2015 2:31 pm

Sounds like a good idea, you could do Fifo with DMA and both SPI ports, as you can independently set the start address and length.
I think there was one example form leaflabs showing a FIFO DMA buffer with a peripheral, but I don't remember the link.

The latest SPI library is a good example on how to use DMA with the SPI peripheral. You can pretty much copy the dma functions over, and the ISR that triggers when the DMA transfer is finished, and then modify them to fit your exact needs with the FIFO buffers.

User avatar
RogerClark
Posts: 6381
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: STM32 WebRadio player

Post by RogerClark » Mon Jun 01, 2015 9:23 pm

Dma has a circular buffer mode.

This sounds the most applicable to what you are doing. Though I'm not sure how you control the speed.

Use of 2 different SPI channels would probably also help, but you will probably need to modify the Ethernet lib to use SPI 2, as its probably hard coded. Well, its better to do a version where you pass in the SPI class ( pointer).

victor_pv
Posts: 1472
Joined: Mon Apr 27, 2015 12:12 pm

Re: STM32 WebRadio player

Post by victor_pv » Thu Jun 04, 2015 2:06 pm

Vassilis, I wonder if there is a good free mp3 decoding library out there, and you could use an STM with 2 DACs and the ethernet module.
I just reading earlier about an STM library, but not free, they say it uses about 20 MIPS for decoding. Once decoded output to the DACs with DMA is almost CPU free. As Roger said the DMA has a circular buffer. For SPI that may be complicated cause it circular mode it doesn't stop when it reaches the end of the buffer, you need to monitor that and stop it manually, but for DAC output you can use a timer to feed the DAC at 22Khz, 44Khz... whatever the rate needed is, set it in circular, and refill half the buffer while the other half is still being written (you can set the DMA controller to give an interrupt at half full, and full, so you know exactly when it's crossing the middle of the buffer).

User avatar
Vassilis
Posts: 295
Joined: Thu May 21, 2015 6:42 am
Location: Thessaloniki, Greece
Contact:

Re: STM32 WebRadio player

Post by Vassilis » Thu Jun 04, 2015 4:10 pm

There are two problems:
1. There is no free MP3 decoder library
2. the STM32s that have DAC are too expensive (at least in eBay) in comparison with the combination STM32F103C8T + VS1053B

I will try to connect the ENC28J60 and VS1053B to separate SPI ports and use the DMA function.
I hope it will work ...

victor_pv
Posts: 1472
Joined: Mon Apr 27, 2015 12:12 pm

Re: STM32 WebRadio player

Post by victor_pv » Thu Jun 04, 2015 6:16 pm

I see in another thread that you got SPI2 working already.

SPI2 uses 2 different DMA channels than SPI1, so you should be able to transfer with DMA to both at the same time.
Right now the DMA functions in the SPI library are hard coded for the channels used by SPI1, but you can use them as a base to your own functions for SPI2 and just change the code.

Besides the function setting up the DMA, in the SPI library you can find the DMA ISR function, that triggers once the DMA is complete. You would also need a second one of that for the second port.

The dma settings in libmaple are explained to some degree in the leaglabs documents if you do a google search, but to fully understand it read the section in the datasheet. I think the DMA is the part I like the most is this little MCUs.

Do you think that for mono output and perhaps wave files there is any small free library? I have a project for which I want to have some sounds, but is just for short sounds, and mono output is also ok.

EDIT: Just checked and looks like STM32F103RC/D/E devices have 2 DACs. Ahull posted recently on a cheap RCT board in ebay. There and in aliexpress you have some options for about $10 if you ever want to get one of those.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests