cancel
Showing results for 
Search instead for 
Did you mean: 

USART (or Serial) trhough ST-Link/V2 for Nucleo STM32L152RE

mucenieks
Associate II
Posted on December 23, 2014 at 14:18

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.org 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''
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++);
}
}

5 REPLIES 5
Posted on December 23, 2014 at 14:53

[DEAD LINK /public/STe2ecommunities/mcu/Lists/STM32Discovery/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/STM32Discovery/USART%20Problem%20with%20nucleo%20L152&FolderCTID=0x01200200770978C69A1141439FE559EB459D75800084C20D8867EAD444A5987D47BE638E0F&currentviews=65]https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Discovery/Flat.aspx?RootFolder=%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2FSTM32Discovery%2FUSART%20Problem%20with%20nucleo%20L152&FolderCTID=0x01200200770978C69A1141439FE559EB459D75800084C20D8867EAD444A5987D47BE638E0F¤tviews=65

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
mucenieks
Associate II
Posted on December 30, 2014 at 11:11

Thanks for the link! I did read this post before and it does not work through onboard ST-link. As You stated this one needs CMOS serial adapter. Or what am I missing?

Posted on December 30, 2014 at 15:11

Or what am I missing?

Apparently the difference between USART1 and USART2 connectivity on the board?

Doesn't USART2 via PA2/PA3 connect to the ST-LINK's VCP (COM)?
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
mucenieks
Associate II
Posted on December 30, 2014 at 15:36

Huge thanks for the patience!

It's holiday magic :). Tried it again and I have it working (sort of).

Returns strange characters if I use baud rate as set in code. It works if the terminal is set to baud rate half the speed (code = 9600, terminal = 4800).

Any ideas what to look for?

Posted on December 30, 2014 at 18:10

Any ideas what to look for?

I guess you'd want to look carefully at what the clock and PLL settings are in system_stm32l1xx.c and the definition of HSE_VALUE.

The Nucleo boards don't have an external crystal, and the 8 MHz source from the ST-LINK must be made through the MCO (SB16 and SB50), which are normally not soldered.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..