Topic : baudrate issue when using printf

Forum : Ride IDE

Original Post
Post Information Post
February 1, 2009 - 2:57pm
Guest

Hi

I'm want to use the printf function , so I did an include in my main.c

It works , but the problem is that whatever baudrate I put into the usart_brr register I always have an 9600Baud.
Im working on a cortexm3 processor btw

Any idea what could be wrong here
Below is some startup code :

#include
#include "iostm32f10xxE.h"

void init_cpu (void);
void oled_init (void);
void write_oled_command (unsigned char comm);
void write_oled_data (unsigned char geg);
void delay_ms (unsigned short int);
void write_oled (unsigned char comm, unsigned char dat);
void write_char (unsigned char chr, unsigned char col, unsigned char row);
const unsigned char font8x8[1024];

#define oled_rs (1<<8)
#define oled_cs (1<<9)
#define oled_rd (1<<10)
#define oled_wr (1<<11)
#define oled_res (1<<12)
#define dcdc_shdn (1<<13)

#define mx1 0x17
#define mx2 0x18
#define my1 0x19
#define my2 0x1a
#define mac 0x20
#define mar 0x21

#define charwidth 0x08
#define charheigth 0x08

/*
* NOTES: PLLPRE can be 1 or 2, PLLMUL can be 2..16.
*/
#define LSECLK 32768
#define HSECLK 8000000
#define HSICLK 8000000
#define PLLPRE 1
#define PLLMUL 9
#define PLLCLK ((HSECLK / PLLPRE) * PLLMUL)
#define SYSCLK PLLCLK
#define APB1CLK (SYSCLK / 2)
#define APB2CLK (SYSCLK / 2)
#define AHB1CLK (SYSCLK / 1)

/*
* Values derived from the clock settings.
*/
#define PLLPREBITS ((PLLPRE - 1) << 17)
#define PLLMULBITS ((PLLMUL - 2) << 18)
#define USBPREBITS USBPRE_DIV1P5_BITS
#define FLASHBITS 0x00000012

/*
Definitions for RCC_CR register.
*/
#define CR_HSION_MASK (0x1 << 0)
#define CR_HSIRDY_MASK (0x1 << 1)
#define CR_HSITRIM_MASK (0x1F << 3)
#define HSITRIM_RESET_BITS (0x10 << 3)
#define CR_HSICAL_MASK (0xFF << 8)
#define CR_HSEON_MASK (0x1 << 16)
#define CR_HSERDY_MASK (0x1 << 17)
#define CR_HSEBYP_MASK (0x1 << 18)
#define CR_CSSON_MASK (0x1 << 19)
#define CR_PLLON_MASK (0x1 << 24)
#define CR_PLLRDY_MASK (0x1 << 25)

/*
* Definitions for RCC_CFGR register.
*/
#define CFGR_SW_MASK (0x3 << 0)
#define SW_HSI_BITS (0 << 0)
#define SW_HSE_BITS (1 << 0)
#define SW_PLL_BITS (2 << 0)
#define CFGR_SWS_MASK (0x3 << 2)
#define SWS_HSI_BITS (0 << 2)
#define SWS_HSE_BITS (1 << 2)
#define SWS_PLL_BITS (2 << 2)
#define CFGR_HPRE_MASK (0xF << 4)
#define HPRE_DIV1_BITS (0 << 4)
#define CFGR_PPRE1_MASK (0x7 << 8)
#define PPRE1_DIV1_BITS (0 << 8)
#define PPRE1_DIV2_BITS (4 << 8)
#define CFGR_PPRE2_MASK (0x7 << 11)
#define PPRE2_DIV1_BITS (0 << 11)
#define PPRE2_DIV2_BITS (4 << 11)
#define CFGR_ADCPRE_MASK (0x3 << 14)
#define ADCPRE_DIV2_BITS (0 << 14)
#define ADCPRE_DIV4_BITS (1 << 14)
#define ADCPRE_DIV6_BITS (2 << 14)
#define ADCPRE_DIV8_BITS (3 << 14)
#define CFGR_PLLSRC_MASK (0x1 << 16)
#define PLLSRC_HSI_BITS (0 << 16)
#define PLLSRC_HSE_BITS (1 << 16)
#define CFGR_PLLXTPRE_MASK (0x1 << 17)
#define CFGR_PLLMUL_MASK (0xF << 18)
#define CFGR_USBPRE_MASK (0x1 << 22)
#define USBPRE_DIV1P5_BITS (0 << 22)
#define USBPRE_DIV1_BITS (1 << 22)
#define CFGR_MCO_MASK (0x7 << 24)
#define MCO_DISABLED_BITS (0 << 24)

int main (void)

{

init_cpu();

while(1)
{
printf("Hello World\n\r");
printf("%08X %08X ",RCC_CR,RCC_CFGR);
delay_ms(100);
}

oled_init();
write_char('R',0,0);

while(1);

return(0);

}

void init_cpu (void)

{


/*
* Clocks and PLL initialization.
*/
// HSI setup.
//RCC_CR = HSITRIM_RESET_BITS | CR_HSION_MASK;
//while (!(RCC_CR & CR_HSIRDY_MASK))
; // Waits until HSI stable, it should already be.
// HSE setup.
RCC_CR |= CR_HSEON_MASK;
while (!(RCC_CR & CR_HSERDY_MASK))
; // Waits until HSE stable.
// PLL setup.
RCC_CFGR = PLLSRC_HSE_BITS | PLLPREBITS | PLLMULBITS;
RCC_CR |= CR_PLLON_MASK;
while (!(RCC_CR & CR_PLLRDY_MASK))
; // Waits until PLL stable.
// Clock sources.
RCC_CFGR |= HPRE_DIV1_BITS | PPRE1_DIV2_BITS | PPRE2_DIV2_BITS |
ADCPRE_DIV8_BITS | USBPREBITS | MCO_DISABLED_BITS;
/*
* Flash setup and final clock selection.
*/
FLASH_ACR = FLASHBITS; // Flash wait states depending on clock.
RCC_CFGR |= SW_PLL_BITS; // Switches on the PLL clock.
while ((RCC_CFGR & CFGR_SWS_MASK) != SWS_PLL_BITS)
; //wait for switch done




//set the 32kHz oscillator and enable it
RCC_APB1ENR=0x18000000;
PWR_CR=0x0000100;

// use this code only for the first time after assembling a pcb
//RCC_BDCR=0x00010000;

//RCC_BDCR=0x00008100;
//RCC_BDCR=0x00008101;

// enable needed clocks
RCC_APB2ENR=0x000040a4;

// init usart1 for 115200,n,8,1
GPIOA_CRH=0x000000b0;
USART1_CR1=0x0000200c;
USART1_CR2=0x00000000;
USART1_BRR=0x00000271;

Replies
Post Information Post
+1
0
-1
February 2, 2009 - 10:39am
Guest

Hi

May I ask you if in linker options of your project, "ST library" is set to "Yes",
If it is the case Baud rate might set in one file from the library.

Regards