cancel
Showing results for 
Search instead for 
Did you mean: 

Need help using USUART2 on STM32F303

Randy Nelson
Associate III
Posted on February 16, 2018 at 22:30

I'm trying to find instruction to code the usuart2 on this STM part. I using cmsis and the StdPeripheral lib. My end goal is to connect this to a virtual com port for debug. I'm using the Keil development environment.

I using the default HSI clock setup running at 8MHZ then -

RCC->AHBENR |= BIT17; //Enable portA clock

RCC->AHBENR |= BIT18; //Enable portB clock

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;

GPIO_Init(GPIOA, &GPIO_InitStructure);

RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);

USART_InitTypeDef USART_InitStructure;

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

//send the data

USART_SendData(USART2, 0xaa);

I realize the baud may be wrong but right now I'm trying to see something on the PA2 pin 

with a scope. Nothing is changing.

I tried to make sure the tx register was empty before writing the data using:

if( ((USART2->ISR) & BIT7)) != 0) {

  USART_SendData(USART2, 0xaa);

}

Still nothing coming out.

Any suggestions. 

Thanks,

Randy

13 REPLIES 13
Posted on February 16, 2018 at 23:43

Clive,

Thanks. I understand that various peripheral could connect to a pin. I’ve been using a another doc that list this information differently. I also realize that the other docs list the registers for this alternate function.

What I can’t find is a doc that ties these together with a good explanation.

I really do appreciate your help.

Randy

Andrew Neil
Evangelist III
Posted on February 17, 2018 at 12:58

I’ve been using a another doc

So tell us what 'doc' that is!

Note that the complete documentation for the part is spread across two documents:

  1. The Datasheet: focuses on specifications - mechanical, electrical, etc.
  2. The User Manual

    : focuses on peripheral operation, registers, etc.

You need both.

Posted on February 20, 2018 at 20:06

Andrew,

I was referencing both the reference manual, RM3016, the programming manual, PM0214,  and the STM32F303x6/x8 doc. I DID miss the RM316 section 11.3.2 dealing with the AF register. Reading this section and using Clives table would have help me resolve my own problem.Thanks for everyone's help.

Randy

Posted on February 20, 2018 at 20:08

Clive,

RM316 section 11.3.2 dealing with the AF register. Reading this section clarifies the table information. Thanks for everyone's help.

Do I need to close this? If yes then how?

Randy