cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to use USART1_TX PA9 pin because of USB conflict?

jean
Senior
Posted on August 22, 2014 at 17:09

Hello everybody!

It's not my first experience with USART but this time I have an unsolvable problem :)

I try to use USART1 TX with the pin PA9 but I can't send datas. The pin PA9 always outputs 1.1V and never switch. When I configure the pin as a standard GPIO, I can set it to high and low level (0V and 3.3V) without problems.

I think this is maybe due to the fact I use the USB and the pin PA9 can be used as the VUSB input.

This my code for the USART1 config:

void

USART_Config(

void

)

{

RCC_APB1PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);

// USART1 clock

RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);

// GPIOA clock

GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_USART1);

// PIN A9 linked to the USART1

// Tx GPIO init

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 ;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

// alternate function!

GPIO_InitStructure.GPIO_OType = GPIO_OType_OD ;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;

GPIO_Init(GPIOA, &GPIO_InitStructure);

// USART init:

// Vitesse du MIDI = 31250

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_HardwareFlowControl = USART_HardwareFlowControl_None;

USART_InitStructure.USART_Mode = USART_Mode_Tx;

USART_Init(USART1, &USART_InitStructure);

USART_Cmd(USART1, ENABLE);

}

Then to send a data I simply use

USART_SendData(USART1, data_out);

Thanks a lot for your help!

#rtfs

8 REPLIES 8
stm322399
Senior
Posted on August 22, 2014 at 17:56

hi, try to configure the IO as Push-Pull (not Open-drain + pull-up).

jean
Senior
Posted on August 22, 2014 at 18:50

Hi Laurent ! Thanks for this tip. Now the PA9 always outputs 3.3V, no switches...

Posted on August 22, 2014 at 19:36

> RCC_APB1PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);

// USART1 clock
 So, is it APB1 or APB2?
 
 JW
Posted on August 22, 2014 at 19:51

On the STM32F4-DISCO there is a very large bulk capacitor on PA9, you'd have to removed that for it to be usable. Suggest if you must use USART1, pick some alternate pins.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on August 22, 2014 at 19:55

http://www.st.com/st-web-ui/static/active/en/resource/technical/document/user_manual/DM00039084.pdf

.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
jean
Senior
Posted on August 25, 2014 at 11:48

Hello! 

1) Sorry it was a post mistake for 

RCC_APB1PeriphClockCmd

, the true line is

RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);

2) I'm not on STM32 discovery but on my own board, PA9 is a free pin. The alternate pin for USART TX is not free, so I have to find a solution with PA9.

When I don't config the USB (to more precise when I don't call the line

USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &MIDI_cb, &USR_cb); 

my USART PA9 pin works! I can send USART messages...

This is strange because when I check the USB libraries the PA9 pin is not used. Do you have any idea of how to ''disconnect'' PA9 and USB?

Thanks a lot!

jean
Senior
Posted on August 26, 2014 at 11:12

I'm a little disturbed because when I search in my workspace ''GPIO_Pin_9'' or ''GPIO_PinSource9'' I have no results, excepted my declarations for USART PA9. I don't understand where and why the USB configure the PA9 pin...

Otherwise, when I init the USB with USB_OTG_CORE_ID_TypeDef = 

USB_OTG_FS_CORE_ID

The USART PA9 doesn't work, but my USB works fine.

When I init the USB with USB_OTG_CORE_ID_TypeDef = 

USB_OTG_HS_CORE_ID

The USART PA9 works, but my computer doesn't recognize the peripherial.

I Hope it can help!

jean
Senior
Posted on August 27, 2014 at 14:25

Is my problem linked to this note from ST on this AN page 28? http://www.st.com/st-web-ui/static/active/en/resource/technical/document/application_note/CD00167594.pdf

''PA9 excessive power consumption when USB cable is plugged

in bootloader V2.0 

Description

When connecting an USB cable after booting from System-Memory mode, PA9 pin 

(connected to VBUS=5 V) is also shared with USART TX pin which is configured as alternate push-pull and forced to 0 since the USART peripheral is not yet clocked. As a consequence, a current higher than 25 mA is drained by PA9 I/O and may affect the I/O pad reliability. This limitation is fixed in bootloader version 2.1 by configuring PA9 as alternate function push-pull when a correct 0x7F is received on RX pin and the USART is clocked. Otherwise, PA9 is configured as alternate input floating. 

Workaround

None. ''