Forum: ARM programming with GCC/GNU tools USART1 issue with a STM32F030R8 Nucleo Board

von Benoit (Guest)

Attached files:

Rate this post
0 useful
not useful

As the title says, I have an issue programming my Nucleo's USART1. It 
seems I am missing something. I had to configure solder bridges in order 
to connect USART1 to Pin PA_2(Tx) and PA_3(Rx) by hardware. I checked 
the connexions and PA_2 and PA_3 are connected to the MCU. Here is my 
code :

main.c :
#include "main.h"

int main(void)

        USART_SendData(USART1, 0xFF);      
        while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET); 

* Function Name  : Init
* Description    : Initializes USART, GPIOS, Clocks
* Input          : None
* Output         : None
* Return         : None

void Init(void)

    RCC_HSEConfig(RCC_HSE_OFF); // We are using the Internal clock source

    /* Initialize Reset Clock Control */

    RCC_ClocksTypeDef RCC_Clocks;
    SysTick_Config(RCC_Clocks.HCLK_Frequency / 1000);

    RCC_SYSCLKConfig(RCC_SYSCLKSource_HSI); // Specify we are using the  // internal clock source

    RCC_USARTCLKConfig(RCC_USART1CLK_HSI); // I wrote this instruction to  // ensure I am using USART1 with HSI, the apllication wasn't working before neither

    /* Enable GPIO clock */
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);

    /* Enable USART1 Clock */
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);


    USART_InitTypeDef USART_InitStructure;

    /* USART Initialisation for MIDI standard */
    USART_InitStructure.USART_BaudRate = 31250; 
    USART_InitStructure.USART_WordLength = USART_WordLength_8b;
    USART_InitStructure.USART_StopBits = USART_StopBits_1;
    USART_InitStructure.USART_Parity = USART_Parity_No; 
    USART_InitStructure.USART_Mode = USART_Mode_Tx;
    USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
    USART_Init(USART1, &USART_InitStructure);  

* @brief  Configures GPIOS
* @param  None
* @retval None
void GPIO_Config(void)
    GPIO_InitTypeDef GPIO_InitStructure;
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;   
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_Init(GPIOA, &GPIO_InitStructure);
    GPIO_PinAFConfig(GPIOA, GPIO_Pin_2, GPIO_AF_0);

main.h :
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __MAIN_H
#define __MAIN_H

/* Includes ------------------------------------------------------------------*/
#include "stm32f0xx.h"
#include "stm32f0xx_rcc.h"
#include "stm32f0xx_it.h"
#include "stm32f0xx_gpio.h"
#include "stm32f0xx_rtc.h"
#include "stm32f0xx_nucleo.h"
#include "stm32f0xx_conf.h"
#include "stm32f0xx_usart.h"

/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* Exported macro ------------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */

void Init(void);
void GPIO_Config(void);

#endif /* __MAIN_H */

When I am checking the logic level on PA_2, I find 0. When I am forcing 
PA_2 to 1, it does work.
I would be happy if someone could help me, I am desperate with it.
Thank you in advance.

: Edited by Admin
von Franz F. (Guest)

Rate this post
1 useful
not useful

Benoit wrote:
> GPIO_PinAFConfig(GPIOA, GPIO_Pin_2, GPIO_AF_0);

STM32F030R8 hasn't mapped USART1 on PA2, please read the datasheet page 
USART1 is available on STM32F030x6 and STM32F030x4 devices only.

Benoit wrote:
> GPIO_PinAFConfig(GPIOA, GPIO_Pin_2, GPIO_AF_0);

I think you have to write GPIO_PinSource2 instead of GPIO_Pin_2.

hope it works

von Benoit (Guest)

Rate this post
0 useful
not useful
You were right, PA_2 is actually connected to USART2 on STM32F030R8. 
Yet, I have tried either PinSource2 with USART1, PinSource2 with USART2, 
and GPIO_Pin_2 with USART2, and it still doesn't work. Is my clock 
initialization okay ? Thank you for your attention.

von Benoit (Guest)

Rate this post
0 useful
not useful
Okay, I have changed my IDE, and I have found other libraries in C++. I 
used other functions and it works. I may never know my problem though, 
but I will deal with it. Thank you for your answer Franz.


Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]

Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.