[U-Boot-Users] at91rm9200 serial frequency fix 2

Ulf Samuelsson ulf at atmel.com
Sun Aug 19 22:45:33 CEST 2007


sön 2007-08-19 klockan 18:43 +0200 skrev michael trimarchi:
> Fix CD calculation on serial device
> 
> Signed-off-by: Trimarchi Michael <trimarchimichael at yahoo.it>
> ---
> 
> --- cpu/arm920t/at91rm9200/serial.c.orig	2007-08-19 19:26:23.000000000 +0200
> +++ cpu/arm920t/at91rm9200/serial.c	2007-08-19 19:43:27.000000000 +0200
> @@ -50,14 +50,18 @@ AT91PS_USART us = (AT91PS_USART) AT91C_B
>  AT91PS_USART us = (AT91PS_USART) AT91C_BASE_US1;
>  #endif
>  
> +#define BAUDRATE(mck, baud) \
> +	((((mck) * 10) % ((baud) * 16)) >= 5) ? \
> +	(mck / (baud * 16) + 1) : ((mck) / (baud * 16))

Your calculation seems wrong


SHould you not use

assume:
	MCK = 100 MHz = 100,000,000
	BAUDRATE = 115200

then:
	BAUD*16 = 1,843,200


	MCK/(BAUD*16) = 54,2534

	The correct BAUD divisor is 54.


	(MCK*10)/(BAUD * 16) = 542,534

	(MCK*10)%(BAUD * 16) = 0,534 * (BAUD * 16) = 985600.

	
	



> +
>  void serial_setbrg (void)
>  {
>  	int baudrate;
>  
>  	if ((baudrate = gd->baudrate) <= 0)
>  		baudrate = CONFIG_BAUDRATE;
> -	/* MASTER_CLOCK/(16 * baudrate) */
> -	us->US_BRGR = (AT91C_MASTER_CLOCK >> 4) / (unsigned)baudrate;
> +
> +	us->US_BRGR = BAUDRATE(AT91C_MASTER_CLOCK, (unsigned)baudrate);
>  }
>  
>  int serial_init (void)
> 
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc.
> Still grepping through log files to find problems?  Stop.
> Now Search log events and configuration files using AJAX and a browser.
> Download your FREE copy of Splunk now >>  http://get.splunk.com/
> _______________________________________________
> U-Boot-Users mailing list
> U-Boot-Users at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/u-boot-users





More information about the U-Boot mailing list