wrong baud rate (yet another thread...)
Dear community,
I try to use the NUCLEO F302R8T6 board which I initialized using a start-up.c – file which was generatedby the STM32F30x_Clock_Configuration_V1.0.0.xls tool. I changed the NUCLEO board configuration accordingly to the UM1724 User manual for STM32 Nucleo boards page 22 5.7.1 -> MCO from STLINK to use the 8 MHZ produced by the on board quartz. The system_stm32f30x.c file (which I renamed into “system_stm32f3xx.c�? to make it compatible with the KEIL CMISS package) contains the following definition:
//Definition
*=============================================================================
* Supported STM32F30x device
*-----------------------------------------------------------------------------
* System Clock source | HSE
*-----------------------------------------------------------------------------
* SYSCLK(Hz) | 8000000
*-----------------------------------------------------------------------------
* HCLK(Hz) | 72000000
*-----------------------------------------------------------------------------
* AHB Prescaler | 1
*-----------------------------------------------------------------------------
* APB2 Prescaler | 1
*-----------------------------------------------------------------------------
* APB1 Prescaler | 2
*-----------------------------------------------------------------------------
* HSE Frequency(Hz) | 8000000
*----------------------------------------------------------------------------
* PLLMUL | 2
*-----------------------------------------------------------------------------
* PREDIV | 2
*-----------------------------------------------------------------------------
* USB Clock | DISABLE
*-----------------------------------------------------------------------------
* Flash Latency(WS) | 2
*-----------------------------------------------------------------------------
* Prefetch Buffer | OFF
*-----------------------------------------------------------------------------
*=============================================================================
I initialized the USART using the following routine:
void COM_USART1_Init() { //COM_TypeDef COM, USART_InitTypeDef* USART_InitStruct)
GPIO_InitTypeDef GPIO_InitStructure1; //GPIO STruct
GPIO_InitTypeDef GPIO_InitStructure2; //GPIO STruct
USART_InitTypeDef USART_InitStructure; //USART Struct
NVIC_InitTypeDef NVIC_InitStructure; //for USART
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); //GPIOA_AHBPeriph_CLOCK
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); //ENABLE USART3 CLK
// Configure the GPIO_struct USART Tx as alternate function push-pull
//PA10 ->RX
//PA9 ->TX
GPIO_InitStructure1.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure1.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure1.GPIO_OType = GPIO_OType_PP; //PushPull (Gegentakt)
GPIO_InitStructure1.GPIO_PuPd = GPIO_PuPd_UP; //NO Pull
GPIO_InitStructure1.GPIO_Speed = GPIO_Speed_50MHz;
// Configure the GPIO_struct USART Rx as alternate function push-pull
GPIO_InitStructure2.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure2.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure2.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure2.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure2.GPIO_Speed = GPIO_Speed_50MHz;
//Init GpioStruct
GPIO_Init(GPIOA, &GPIO_InitStructure1);
GPIO_Init(GPIOA, &GPIO_InitStructure2);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_7); //Connect the PINS and USART BUS
GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_7);
//NVIC for USARR
// Enable the USARTx Interrupt
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; // one level lower than TIm !!
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
// USART 1
// USARTx configured as follow:
// - BaudRate = 115200 baud
// - Word Length = 8 Bits
// - One Stop Bit
// - No parity
// - Hardware flow control disabled (RTS and CTS signals)
// - Receive and transmit enabled
USART_InitStructure.USART_BaudRate = 115200;//9600;//115200; //is just the half of 115200 57600;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
// USART configuration
USART_Init(USART1, &USART_InitStructure);
// Enable USART
USART_Cmd(USART1, ENABLE);
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); // enable the USART1- receive interrupt
}
Accordingly to CLIVE1’s post I set the HSE_VALUE to 8000000
(
/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/wrong%20usart%20baudrate%20after%20change%20of%20crystal&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B¤tviews=89
)
However the baud rate of the USART is twice as fast as defined (to get the desired baud rate I have to initialize the USART using 0.5* desired baudrate).
I would be very happy if someone could point me into the right direction how to set the clock speed of the cpu correctly.
