9 years, 3 months ago.

USART trhough ST-Link/V2

Can someone share example and/or point to useful resources to learn USART communication through ST-Link/v2 for ST Nucleo L152RE? I'm trying to learn stm32 basics using only C and Standard Peripheral Library. The sample available on mbed for download works but is not particularity illuminating on the actual things happening behind the scenes.

Thank you!

Here is the most basic thing I have from tutorials for other boards.

include stm32l1xx_usart.h with this snippet

#include "stm32l1xx_usart.h"

void USART2_Configuration(void)
{
  USART_InitTypeDef USART_InitStructure;
 
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
	
  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);
}

int main(void)
{
	
	int time;
	
	USART2_Configuration();
	
	while (1)
	{
		USART_SendData(USART2, 2);
		for(time = 0; time < 100000; time++);
	}
}

Question relating to:

Affordable and flexible platform to ease prototyping using a STM32L152RET6 microcontroller.

1 Answer

9 years, 3 months ago.

You can try to use the STM32CubeMX to initialize the code base.

It can config easily the pin assignment of your development board.

Thanks for the tip. Any directions on how to actually do this?

posted by Janis Mucenieks 30 Dec 2014