cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F072 discovery board USART to hyperterminal communication problem

Nickname4855_O
Associate II
Posted on November 11, 2015 at 20:08

Hi,

I don't know why this code doesn't work. I have following simple code to check USART and the code is running on STM32F072 discovery board. But when I check PA2 pin with scope, it shows nothing. I also connect the board to PC serial port and check with hyperterminal and no luck. 

 *******************************************

static void USART_Config(void);

static void GPIO_Config(void);

static void RCC_Config(void);

/* Private functions ---------------------------------------------------------*/

/**

  * @brief  Main program.

  * @param  None

  * @retval None

  */

int main(void)

{

 

 

 /* RCC configuration */

 RCC_Config();

 

 /* GPIO configuration */

 GPIO_Config();

 

  /* USART configuration */

  USART_Config();

 

  while(1)

  {

  while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET); 

  

  USART_SendData(USART2, 10); 

  }

  

}

/**

  * @brief Configure the USART1 Device

  * @param  None

  * @retval None

  */

static void USART_Config(void)

{

  USART_InitTypeDef USART_InitStructure;

   

/* USART1 configured as follow:

  - BaudRate = 9600 baud 

  - Word Length = 8 Bits

  - Two Stop Bit

  - Odd 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(USART2, &USART_InitStructure);

 

  USART_Cmd(USART2, ENABLE);

  

}

/**

  * @brief Configure the GPIO Device

  * @param  None

  * @retval None

  */

static void GPIO_Config(void)

{

 GPIO_InitTypeDef GPIO_InitStructure;

 /* Connect PXx to USART2_Tx */

  GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_1);

  /* Connect PXx to USART2_Rx */

  GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_1);

 

  /* Configure USART2 Tx/Rx as alternate function push-pull */

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

//  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;

  GPIO_Init(GPIOA, &GPIO_InitStructure);

      

}

/**

  * @brief Configure the RCC

  * @param  None

  * @retval None

  */

static void RCC_Config(void)

{

 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);   //enable GPIOA clock

  RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE); //enable USART2 clock

}

#rtfm
14 REPLIES 14
Nickname4855_O
Associate II
Posted on November 13, 2015 at 22:57

You are right, I missed that.

I just change the code to use USART1 so that PA9 can be probed, but I don't see any signal coming out of it.

****************************************

/* Private function prototypes -----------------------------------------------*/

static void USART_Config(void);

static void GPIO_Config(void);

static void RCC_Config(void);

/* Private functions ---------------------------------------------------------*/

/**

  * @brief  Main program.

  * @param  None

  * @retval None

  */

int main(void)

{

 

 

 /* RCC configuration */

 RCC_Config();

 

 /* GPIO configuration */

 GPIO_Config();

 

  /* USART configuration */

  USART_Config();

 

  while(1)

  {

  while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET); 

  

  USART_SendData(USART1, 65);

  }

  

}

/**

  * @brief Configure the USART1 Device

  * @param  None

  * @retval None

  */

static void USART_Config(void)

{

  USART_InitTypeDef USART_InitStructure;

   

/* USART1 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;

  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);

  

}

/**

  * @brief Configure the GPIO Device

  * @param  None

  * @retval None

  */

static void GPIO_Config(void)

{

 GPIO_InitTypeDef GPIO_InitStructure;

 

  /* Configure USART2 Tx/Rx as alternate function push-pull */

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;

  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;

  GPIO_Init(GPIOA, &GPIO_InitStructure);

 

 /* Connect PXx to USART1_Tx */

  GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_0);

  /* Connect PXx to USART1_Rx */

  GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_0);

 

 //

 

}

/**

  * @brief Configure the RCC

  * @param  None

  * @retval None

  */

static void RCC_Config(void)

{

 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);   //enable GPIOA clock

//  RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE); //enable USART2 clock

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); //enable USART1 clock

}

Posted on November 14, 2015 at 00:22

GPIO_AF_1 not 0

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Nickname4855_O
Associate II
Posted on November 14, 2015 at 01:02

change back to GPIO_AF_1 and rerun the code, still no signal out.

Posted on November 14, 2015 at 02:46

This works for me, signal out of PA9

/* Includes ------------------------------------------------------------------*/
#include ''stm32f072b_discovery.h''
/** @addtogroup STM32F0xx_DISCOVERY_Templates
* @{
*/
static void USART_Config(void);
static void GPIO_Config(void);
static void RCC_Config(void);
/**
* @brief Configure the USART1 Device
* @param None
* @retval None
*/
static void USART_Config(void)
{
USART_InitTypeDef USART_InitStructure;
/* USART1 configured as follow:
- BaudRate = 115200 baud
- Word Length = 8 Bits
- Two Stop Bit
- Odd parity
- Hardware flow control disabled (RTS and CTS signals)
- Receive and transmit enabled
*/
USART_InitStructure.USART_BaudRate = 115200;
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);
}
/**
* @brief Configure the GPIO Device
* @param None
* @retval None
*/
static void GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Configure USART1 Tx/Rx as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Connect PXx to USART1_Tx */
GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_1);
/* Connect PXx to USART1_Rx */
GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_1);
}
/**
* @brief Configure the RCC
* @param None
* @retval None
*/
static void RCC_Config(void)
{
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); //enable GPIOA clock
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); //enable USART1 clock
}
/**
* @brief Main program.
* @param None
* @retval None
*/
int main(void)
{
/*!< At this stage the microcontroller clock setting is already configured,
this is done through SystemInit() function which is called from startup
file (startup_stm32f0xx.s) before to branch to application main.
To reconfigure the default setting of SystemInit() function, refer to
system_stm32f0xx.c file
*/
/* Add your application code here */
/* RCC configuration */
RCC_Config();
/* GPIO configuration */
GPIO_Config();
/* USART configuration */
USART_Config();
while(1)
{
while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
USART_SendData(USART1, 65);
}
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t* file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf(''Wrong parameters value: file %s on line %d

'', file, line) */
/* Infinite loop */
while (1)
{
}
}
#endif

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
rbenesh
Associate II
Posted on November 17, 2015 at 23:33

I had a similar problem. The discovery board is set up as if the on-board debugger has virtul com on USART1. It does not. You will need to get out a soldering iron and change some solder bridges on the bottom side. As stated by the others above, this is a board you need to really carefully look at the board manual. Things are not as they seem.