cancel
Showing results for 
Search instead for 
Did you mean: 

RESOLVED: UART in STM32F4_Discovery_FW_V1.1.0

selmesal
Associate II
Posted on October 12, 2016 at 14:46

Hello, 

I was working off of TIM_PWM_Output (Peripheral_Examples from FW_V1.1.0) and would like to add UART connection to it.

How do I initialize UART if using FW_V1.1.0?

Thanks,

Sel 
3 REPLIES 3
slimen
Senior
Posted on October 12, 2016 at 15:47

Hello Sel,

You can use

http://www.st.com/content/st_com/en/products/development-tools/software-development-tools/stm32-software-development-tools/stm32-configurators-and-code-generators/stm32cubemx.html

tool with the peripherals that you want which help you to develop the basic configuration of your application and generate an initialization code.

Moreover, you can have a look to any UART example in STM32CubeF4 to learn UART use and initialisation: STM32Cube_FW_F4_V1.13.0\Projects\STM32F4-Discovery\Examples\UART\UART_Printf

The reference-Manual and datasheet related to your device will be your support for more details.

You are using an old firmware version and should update the last one v1.13.0 through this

http://www.st.com/content/st_com/en/products/embedded-software/mcus-embedded-software/stm32-embedded-software/stm32cube-embedded-software/stm32cubef4.html

, as there is always enhancement and bug fixes in the new release.

Regards

selmesal
Associate II
Posted on October 12, 2016 at 19:13

Hi, 

Thanks. 

The only example I found for PWM_Output was based on FW_V1.1.0. 

That is why I ended up working with this level. 

I would like to eventually migrate to the latest. 

But, for now, I wanted to add USART functionality into the existing example code. 

Is there a migration tool that I might not be aware of?

Thanks,

Sel

Posted on October 12, 2016 at 19:44

// STM32 USART1 (Tx PB.6, Rx PB.7) STM32F4 Discovery - sourcer32@gmail.com
#include ''stm32f4_discovery.h''
/**************************************************************************************/
void RCC_Configuration(void)
{
/* --------------------------- System Clocks Configuration -----------------*/
/* USART1 clock enable */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
/* GPIOB clock enable */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
}
/**************************************************************************************/
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/*-------------------------- GPIO Configuration ----------------------------*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* Connect USART pins to AF */
GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_USART1); // USART1_TX
GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_USART1); // USART1_RX
}
/**************************************************************************************/
void USART1_Configuration(void)
{
USART_InitTypeDef USART_InitStructure;
/* USARTx configuration ------------------------------------------------------*/
/* USARTx configured as follow:
- BaudRate = 9600 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 = 9600;
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_Init(USART1, &USART_InitStructure);
USART_Cmd(USART1, ENABLE);
}
/**************************************************************************************/
int main(void)
{
RCC_Configuration();
GPIO_Configuration();
USART1_Configuration();
while(1)
{
while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET); // Wait for Empty
USART_SendData(USART1, 0x49); // Send 'I'
}
while(1); // Don't want to exit
}

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..