Page 1 of 1
STM32F427 USART1 @ 31250 8N1
Posted: Sun Sep 28, 2014 8:54 am
by Rick Burnett
I'm not really sure what I am doing wrong, all I can think is there is a calculations wrong somewhere for this processor? (Given that it can run faster than the other Fxx processors).
I have setup to run serial and specified this first:
Code: Select all
SerialConfig midiCfg;
//midiCfg.speed=31250;
midiCfg.speed=38400;
midiCfg.cr1 = 0;
midiCfg.cr2 = USART_CR2_STOP1_BITS;
//midiCfg.cr3 = 0;
palSetPadMode(GPIOA, 9, PAL_MODE_ALTERNATE(7));
sdStart(&SD1, &midiCfg);
I hook up a serial to USB cable to the output of the MIDI TX port and set my term program to 38400 8N1 and I can see whatever I send out. I set to 31250 and hook up to a MIDI device and nothing. In doing a lot of reading, I guess it's possible that I have some combination of frequency values that is causing me to not be at 31.25k bps? Not sure what to look at next.
Re: STM32F427 USART1 @ 31250 8N1
Posted: Sun Sep 28, 2014 9:00 am
by Giovanni
Hi,
You should verify if the value is obtainable using the input frequency and the USART prescaler, it is possible there is too much error.
Giovanni
Re: STM32F427 USART1 @ 31250 8N1
Posted: Sun Sep 28, 2014 9:07 am
by Rick Burnett
I will dig through the user guide. I get confused with the clock stuff since it's SO programmable. Do I go take a look at what your code is doing with the frequency I am setting then check what is going in the baud rate register and compare it with fclk settings?
Re: STM32F427 USART1 @ 31250 8N1
Posted: Sun Sep 28, 2014 9:43 am
by Rick Burnett
Just curious,
Why am I not able to look at SD1.clock in my main function. Yet, when I pass it into sdStart, eventually it gets looked at from sdp->clock . I wanted to check what the value was at.
Re: STM32F427 USART1 @ 31250 8N1
Posted: Sun Sep 28, 2014 10:17 am
by Giovanni
No sure, debuggers behave funny at times.
Giovanni
Re: STM32F427 USART1 @ 31250 8N1
Posted: Sun Sep 28, 2014 10:18 am
by Rick Burnett
I ended up finding this value:
STM32_PCLK2
Which is that the documentation says USART1 and USART6 are based off of.
What I am unclear of is what you do with the oversampling in the code. It appears I can get other values with that as well. I will dive into more tomorrow. I am okay with running at a different freq if necessary to get better timing at that baud rate. I tried incrementing the multiplier from 336 around a bit to see if it made a difference but no change. Did try the core out at 180Mhz though

Unless I am not understanding the docs.
Re: STM32F427 USART1 @ 31250 8N1
Posted: Sun Sep 28, 2014 10:21 am
by Rick Burnett
I should also say, I see where you are making the calculation:
Code: Select all
u->BRR = (uint16_t)(SD1->clock / midiCfg.speed);
But I am not seeing any modification to the oversampling settings (again, unless I missed it). Does this fill in the fractional part as well?
Re: STM32F427 USART1 @ 31250 8N1
Posted: Sun Sep 28, 2014 11:19 am
by Giovanni
Yes, the lower 4 bits are the fractional part.
Giovanni
Re: STM32F427 USART1 @ 31250 8N1
Posted: Sun Sep 28, 2014 8:05 pm
by Rick Burnett
After spending a long time determining that your code works perfectly and that 31250 has zero error (we don't even need a fractional part, it divides perfectly), I discovered 2 things:
1) It appears the FTDI chip on the serial->usb board I have does not do 31250. So when I was setting 'Screen' to 31250 it was actually dropping to 9600. I figured this out by setting ChibiOS to configure USART1 as 9600 and then my data appeared! Talk about a random find.
2) It would help if I had hooked up my MIDI properly on my board. I accidentally put +5 through a 220R to Pin 1, but it should have been Pin 4. Removed the jack, rewired with some jumpers, 31250 is working fantastic and ChibiOS is driving my synth now through MIDI

I wanted to put the resolution here in case anyone else gets stuck like I did.