Author Topic: Stm32F4Discovery port  (Read 47629 times)

norbim1

  • Team member
  • *
  • Posts: 28
    • View Profile
Stm32F4Discovery port
« on: June 26, 2014, 11:10:19 AM »
Hi,

First of all thank you Xavier for this wonderful project and making it open source.

I've started to port the project to the STM32F4Discovery board, which has a nice audio codec on board. I haven't built the control surface yet, but in the current state I'm able to play notes from USB midi. The board have enough free IO pins left to direct connect the CS buttons and enc-s, so I'll try to eliminate the cs s/p converters too.
To use the onboard I2S audio codec I changed the Systic interrupt to DMA int. Currently I'm using 32 samples long DMA buffer, and it works perfectly. In that way the DMA int is fired only at every 16th sample.
I'm wondering if I can use the full 24 bit resolution of the codec. As far as I see the sample block contains 18 bit normalized uint samples, but I couldn't find where it is normalized. I plan to change the timbre summing at the end of the buildNewSampleBlock(), but I'm sure that it has a better place for it.
Would You mind helping me with the place of the "float to 18 bit" normalizing?

Thank's a lot,
Norbert

pld

  • Team member
  • *
  • Posts: 41
    • View Profile
Re: Stm32F4Discovery port
« Reply #1 on: June 26, 2014, 02:32:15 PM »
Cool, I've been meaning to look into the DMA/i2s stuff myself :)

IIRC, the way things are calculated is
- the voice calculations produce float values (-1,1) and these are summed per timbre
- Timbre::fxAfterBlock scales the the timbre output from (-n,n) to (-131072,131072) via ratioTimbres and numberOfVoiceInverse to avoid clipping in the final mix
- during the final mixing of the timbre samples in buildNewSampleBlock, the sum is offset from float (-131072,131072) to int (0,2^18) for the DAC

So I guess you mainly have to replace the 131072.f (2^17) constants with 8388609.f (2^23).

Does the codec accept padded 24bit samples (i.e. 32bit), or how does that work with DMA?

norbim1

  • Team member
  • *
  • Posts: 28
    • View Profile
Re: Stm32F4Discovery port
« Reply #2 on: June 26, 2014, 02:59:22 PM »
Thanks for the info. I found the offset, but didn't found the scale. I'll try it today evening.

Yes, the codec accepts padded 32 bit samples, the 24 bit part has to be justified to the right. Actually the codec accepts 2*16bit words for one stereo side sample, so I need to swap the half words of the 32 bit int when filling the DMA buffer.

norbim1

  • Team member
  • *
  • Posts: 28
    • View Profile
Re: Stm32F4Discovery port
« Reply #3 on: June 27, 2014, 09:50:13 AM »
It works! Thanks again for the info.

Xavier

  • Administrator
  • Hero Member
  • *
  • Posts: 2257
    • View Profile
Re: Stm32F4Discovery port
« Reply #4 on: June 27, 2014, 11:08:25 AM »


Great project  :)
I'm glad to see open source code is usefull to others.
Did you fork the github project ? Don't forget to share your changes  ;)

And thanks Patrick for the very accurate answers....

Xavier

norbim1

  • Team member
  • *
  • Posts: 28
    • View Profile
Re: Stm32F4Discovery port
« Reply #5 on: June 27, 2014, 02:49:50 PM »
Hi Xavier,

I'm just a hobbyist so I  don't have registered yet to Github and I'm quite new with it.
The CS part of my project is still left. As soon as it's ready, i'll fork it.

Thanks, Norbert

norbim1

  • Team member
  • *
  • Posts: 28
    • View Profile
Re: Stm32F4Discovery port
« Reply #6 on: August 12, 2014, 12:24:40 PM »
Hi,

I've managed to fork it and merged with the latest 1.04 fw:

https://github.com/norbim1/preenFM2

- STM32F4Discovery module based PreenFM2
- uses the onboard I2S codec, audio data send through DMA
- the CS buttons and encoders are directly connected to the IO ports of the module
- made some minor changes to the display driver, (I use a cheaper OLED module: Raystar REC002004AYPP5N00000)

I'll post the schematic and some pics of my newly built module soon. It was built on veroboard, so no PCB design has been made for it.

Regards Norbert

pld

  • Team member
  • *
  • Posts: 41
    • View Profile
Re: Stm32F4Discovery port
« Reply #7 on: August 12, 2014, 08:06:17 PM »
Awesome, thanks for sharing. Definitely have to take a look at that...

norbim1

  • Team member
  • *
  • Posts: 28
    • View Profile
Re: Stm32F4Discovery port
« Reply #8 on: August 12, 2014, 09:45:45 PM »
Some pics about the gadget:


norbim1

  • Team member
  • *
  • Posts: 28
    • View Profile
Re: Stm32F4Discovery port
« Reply #9 on: August 12, 2014, 09:47:14 PM »
Schematic and a suggested veroboard wiring:

Xavier

  • Administrator
  • Hero Member
  • *
  • Posts: 2257
    • View Profile
Re: Stm32F4Discovery port
« Reply #10 on: August 13, 2014, 10:49:32 AM »

Great project...  :D
Congrats and thanks for sharing.

norbim1

  • Team member
  • *
  • Posts: 28
    • View Profile
Re: Stm32F4Discovery port
« Reply #11 on: August 13, 2014, 03:20:00 PM »
Thanks a lot, but it's definitely your fantastic project's merit.
I'll try to keep the fork sync with the upstream repository.

yogi

  • Team member
  • *
  • Posts: 1
    • View Profile
Re: Stm32F4Discovery port
« Reply #12 on: November 26, 2014, 07:39:17 PM »
  Norbim1,  Thank You very much for your port project (and your post over @ Midibox.org), I'm so very excited to find this! For along time I have watched the Preen project (had not seen the FM2 ver till now), so very cool; but could not bring myself to spend on 'yet another project' when my wish list is so long. BUT the Disco board is very inexpensive and very complete. So now there is a new build in my future.
 Not to take anything away from the great work of Xavier, but the 'F407 Discovery port opens this up for me :) Again Thank You both, life is good :)
Yogi

elea

  • Team member
  • *
  • Posts: 4
    • View Profile
Re: Stm32F4Discovery port
« Reply #13 on: December 22, 2014, 05:26:08 PM »
norbim1: would it be possible to upload the compiled binaries (regular, overclocked & bootloader)?

I'm running 3 different STM32Fx toolchains right now (Spark Core, MIDIbox NG & Mutable Instruments) and am having trouble installing a fourth one that's compatible with your code :(

norbim1

  • Team member
  • *
  • Posts: 28
    • View Profile
Re: Stm32F4Discovery port
« Reply #14 on: December 22, 2014, 09:29:59 PM »
I'm using Eclips and MidiBox toolchain without any problem.
Anyway here is the binaries. I've made only the overclocked version for Stm32F4Discovery, so bootloader and overclocked only.
« Last Edit: December 22, 2014, 09:33:51 PM by norbim1 »