F4 discovery DAC. working. loop speed?

Limited support for STM32F4 Discovery, Nucleo and custom F4 boards
Post Reply
User avatar
mubase
Posts: 30
Joined: Wed Apr 29, 2015 5:10 pm
Contact:

F4 discovery DAC. working. loop speed?

Post by mubase » Thu Apr 30, 2015 11:39 am

Hi. I joined as you suggested on the github issue request. :)
I'm using an STM32F4 discovery board and am very pleased you've got functionality in Arduino IDE for this board.
I can confirm the DAC seems to work. I am attempting rudimentary granular synthesis techniques which was why I was asking about I2S and the audio codec.
I have some simple code running to output an enveloped sine wave through the DAC using the DAC library in libmaple.

Code: Select all

 // put your main code here, to run repeatedly:
 toggleLED();
 r=random(244);
 r++;
 if (r>254) r=0;
 but=digitalRead(0);
 amp=analogRead(1);
 map(amp,0,3300,20,1500);
 accumulatorSteps=amp;
 delayMicroseconds(20);
 
 if (but==HIGH)
 {
   i++;
 if (i==1)
 { 

  d++;  // increment env
  mixer=cosine[d];
  i=0;  // reset env divider
 }
 }
 else {
  
   
   mixer=0;
   d=0;
 }
 if (d>=254)
{
   d=0;
  
  go=false;

// mixer=0;
 
}
 
     accumulator += accumulatorSteps; /* advance accumulator */
      accumulator2 += accumulatorSteps2; /* advance accumulator */
		waveStep =( accumulator>>8);
waveStep2 =( accumulator2>>8);
output=(sine[waveStep]);
output2=(sine[waveStep2]);
    dac_write_channel(DAC, 1, ((output*mixer)>>8));
    //basic fm
   // dac_write_channel(DAC, 2, ((((output+output2)>>1)*mixer)>>8));
    //single wave + fast envelope (halfsine_
    dac_write_channel(DAC, 2, ((((output)*mixer)>>8)));
All this is running inside Loop()!!!

Would you know how fast loop runs?
What is the default clock speed ??

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

Re: F4 discovery DAC. working. loop speed?

Post by victor_pv » Sat May 02, 2015 3:48 am

Mubase, I would think the easiest way to know how fast it runs is to read the micros() before, and after the loop and compare.
About the clock speed, should be list in the specs for that discovery board.
Which one within the STM32F4 series is it?

User avatar
mubase
Posts: 30
Joined: Wed Apr 29, 2015 5:10 pm
Contact:

Re: F4 discovery DAC. working. loop speed?

Post by mubase » Sat May 02, 2015 10:00 am

Hi Victor.
Good idea thanks I'll give it a whirl. :)
For the purposes of correct calculation, I've taken the routine out of loop() and am now running it inside an IRQ of a timer overflow at 44100Hz. So Hardwaretimer() works for this board & chip. :)
The DAC works nicely but as I'm using the F4 discovery board which has an on board codec and headphone out socket. The codec runs on i2c and i2s. I'm trying to get my head around how to get it working but its a bit beyond me at the moment.
In answer to your question, the discovery board uses an stm32f407vgt6.

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

Re: F4 discovery DAC. working. loop speed?

Post by RogerClark » Sat May 02, 2015 8:46 pm

MuBase

Thanks for updating us.

I know a lot of people are interested in the F4

I have a STM Discovery F407GVT a well. It's the 168Mhz version that does NOT have the display

I presume you upload via on board STLink?

Have you connected USB serial for debug messages?
If so how have you done this? Which serial port, and what code ?
serial1.println ?

re:wire

I can't remember if the library was updated with the fix that was applied to the F1 library.

You may want to try the F1 library with the F4. Both are software "bit banged" implementations, so are not ultra fast.

If you need to wire to go faster, look at changing digitalWrite and digitalRead for the internal low level functions, which are called something like gpio_write_.......

(I'm not at my PC now, so I can't easily find the function names)

Re: I2S

I'm not sure any one has done any work on I2S

I don't think any of the Leaflabs Maple board had that ability ( I will check, perhaps the F103RET has this)
I have one f103 board that has I2S, but I have not had time to investigate how to use it

Anyway, keep posting ;-)

User avatar
mubase
Posts: 30
Joined: Wed Apr 29, 2015 5:10 pm
Contact:

Re: F4 discovery DAC. working. loop speed?

Post by mubase » Mon May 04, 2015 5:36 am

Hi Roger. :)
I have a STM Discovery F407GVT a well. It's the 168Mhz version that does NOT have the display
Yep. Same here. No display but LOVELY audio and DSP capabilities.
I presume you upload via on board STLink?
Command line ST LInk has worked without a hitch so far...
Have you connected USB serial for debug messages?
If so how have you done this? Which serial port, and what code ?
serial1.println ?
I've been trying to get USBSerial working. I've tried :

Code: Select all

USBSerial usb1;

[code]void setup() {
                                usb1.begin(9600);
                                usb1.println("TESTING");
                                }
                                
[/code]

and the board shows up as a VCP on port 6 (I have version 1.4.0 of the ST VCP driver) but then 10 seconds later the driver "breaks" and gives me an error code 10 : "this device cannot start" and I'm locked out.
I don't know why...
I've not tried the usual HardwareSerial Serial1 /2 /3 . begin() with a USB to Serial converter yet but I'll give that a go some time today.

and the GPIO ports I've had success using the defs and functions from the leaflabs page:
http://static.leaflabs.com/pub/leaflabs ... /gpio.html

I'm buggered as to whats happening with the USBSerial though...

;)

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

Re: F4 discovery DAC. working. loop speed?

Post by RogerClark » Mon May 04, 2015 12:33 pm

I've not tried USB serial

Strange it packs up after a while.

I'm pretty sure I tried HW serial1 but no luck. It's possible that the UART is not being setup, at all

When I get chance I will take a look at the code, but I'm still trying to finish work on the revised version of the Maple bootloader ( for F103) working on the various Maple boards.

User avatar
mubase
Posts: 30
Joined: Wed Apr 29, 2015 5:10 pm
Contact:

Re: F4 discovery DAC. working. loop speed?

Post by mubase » Mon May 04, 2015 2:03 pm

Hi Roger. :)
Using a USB to serial module on USART2 using pins PA2 & PA3.

This seems to work.

Code: Select all


void setup() {
    Serial2.begin(9600);
}

void echoCharacter() {
    // Check to see if we have received any information.  numUnread
    // will hold the number of bytes we've received, but haven't
    // looked at yet.
    int numUnread = Serial2.available();

    // numUnread > 0 means that there are some unread bytes waiting
    if (numUnread > 0) {
        // Read a single byte out:
        byte b = Serial2.read();
        // And then print it back:
        Serial2.print(b);
    }
}

void loop() {
    echoCharacter();
}
I'm sure I read somewhere something about Serial and Serial1 being out of bounds... but I can't remeber where.

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

Re: F4 discovery DAC. working. loop speed?

Post by RogerClark » Mon May 04, 2015 9:10 pm

Thanks I will try serial 2

It could be serial 1 is connected to something else on the discovery board.

Actually, its a shame the discovery board stlink chip doesn't have Virtual serial like the Nucleo boards do :-(

Post Reply