Baud rate issue

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
avrhack
Posts: 140
Joined: Tue Dec 24, 2013 1:42 pm
Has thanked: 17 times
Been thanked: 3 times

Baud rate issue

Post by avrhack »

I'm sure this is NOT a bug in ChiBIOS as it used to work perfectly, but I can't for the life of me see what the problem is.

I have an STM32F303 with an 8MHz crystal, 9x PLL and 1.5/ USB pre-scaling. USB works perfectly which confirms the clock is indeed 8Mhz * 9 = 72MHz / 1.5 = 48MHz, otherwise USB wouldn't be active.

However when I use USART1 the baud rate is exactly 1.5 times SLOWER than it should be. I've looked through all the code - mine and the HAL, and I've even got to the point where I've put a fixed value of 313 in serial_lld.c in the usart_init function when setting u->BRR, that value being 72Mhz clock / AHB2 pre-scaler = 36Mhz / 115200 baud rate. This is exactly the calculation that ChiBIOS would do and indeed I've confirmed that using #pragma message to show the value of the pclk being passed into the routine.

In terms of how I know the baud rate is wrong, again I have used two methods - firstly an FTDI UART set to 115200 and secondly a logic analyser set to auto-baud which also confirmed the baud rate is 1.5x slower than it should be.

So to recap:

1) I'm sure the HSE is running at the right frequency
2) I'm sure the baud rate calculations done by ChiBIOS are correct
3) I've forced those calculations manually as a cross-check
4) The baud rate is still wrong!

What am I missing here? Sure it's a stupid mistake, but I'm b***ered if I can figure out what it is..... :)
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Baud rate issue

Post by Giovanni »

Hi,

Very strange, all demos use the default 38400 setting and the baud rate appears to be correct or the terminal software would show only garbage.

Does the small demo exhibit the same problem? could it be a measurement problem? does your FTDI device work at 115200?

Giovanni
avrhack
Posts: 140
Joined: Tue Dec 24, 2013 1:42 pm
Has thanked: 17 times
Been thanked: 3 times

Re: Baud rate issue

Post by avrhack »

Haven't tried the small demo and away for a couple of days so will do that when I get back - good suggestion Giovani thanks. However I doubt it's the FTDI as I also put a logic analyser on there as well and it confirmed the baud rate was wrong. I guess the only common factor now is the particular STM32. Realise it's a long shot, but when all else has been eliminated, what remains must be the answer, no matter how strange it it!

On Friday I'll put the same code into another STM32 and see if that works. At least it will prove the hardware although given the USB is working I can't believe it's the crystal/PLL running at the wrong frequency :(
avrhack
Posts: 140
Joined: Tue Dec 24, 2013 1:42 pm
Has thanked: 17 times
Been thanked: 3 times

Re: Baud rate issue

Post by avrhack »

The only thing I could think of that fitted the bill was a hardware issue, so I moved the exact same code to another of my boards and sure enough it works perfectly and at the correct baud rate.

So there's clearly some strange hardware issue on the board I was initially using - either a defect in the STM32 itself or some strangeness with the oscillator being at the wrong frequency - but then how would the USB still work?

Further investigation needed, but confirmation of my original thought which is I couldn't see how it could be an issue with ChiBIOS. Nice to have it confirmed though :)
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Baud rate issue

Post by Giovanni »

Very strange problem anyway... You could try changing just the device.


Giovanni
avrhack
Posts: 140
Joined: Tue Dec 24, 2013 1:42 pm
Has thanked: 17 times
Been thanked: 3 times

Re: Baud rate issue

Post by avrhack »

Can't easily change the device without a bit of hot air and I'm too lazy at the moment - there's actually very little on the board apart from the device, a crystal and some decoupling caps.

I've tried a couple of the other UARTS with the same result. I've also set up a PWM output and it's spot on, so as unlikely as it seems, the UART baud generator or peripheral clock appears to have a hardware fault in this particular device......
Post Reply