Re: [libopenstm32-devel] usart_set_baudrate(...)
Status: Inactive
Brought to you by:
uh1763
From: Piotr Esden-T. <pi...@es...> - 2011-03-13 19:57:39
|
Hi! On Mar 12, 2011, at 4:52 PM, Gareth McMullin wrote: > On Thu, Mar 10, 2011 at 2:34 AM, Nico von Geyso <Nic...@fu...> wrote: >> I had some problems with the usart_set_baudrate() function and so I took >> a deeper look how it works. >> The baud rade generation for stm32 is described in the section >> "Fractional baud rate generation" in RM0008 Reference manual, Page 747. > > If I read it correctly, all the talk in the manual makes it sound fancy and > complicated, but the simple division calculates the correct value. Yes that is what I figured myself. This sounds like marketting talk to make the divider sound more awesome than it is. :) I updated the rcc code to store the clock speeds of the apb1 and apb2 into variables and use them to calculate the baud divider, using just a simple division. Tested it a little and it seems to work like a charm. just pull from my fork repository and give it a try. :) > >> For the stm-h107 development the current implementation works fine for >> usart 2,3 but not for usart1. >> Usart1 has a different clock source (PCLK2, 72Mhz) and so you have to >> divide the baud parameter (for usart_set_baudrate(...)) by two to get >> the correct values. >> As it is hard to get the current pclk1 or pclk2 values, wouldn't it be >> better if there is a function like the following: >> >> void usart_set_baudrate(u32 clock, u32 usart, u32 baud); //set the >> clock manually > > I think this is the most obvious way to do it. I would swap the clock and usart > parameters though. I think it is better to track the clock speed of the system and have the baud rate still be calculated automatically... Cheers Esden -- Blog: http://www.esden.net Projects: http://open-bldc.org http://paparazziuav.org http://github.org/esden/floss-jtag http://github.org/esden/summon-arm-toolchain |