cancel
Showing results for 
Search instead for 
Did you mean: 

stm32 discovery, usart not working at all ?

michaelmccartyeng
Associate II
Posted on August 06, 2012 at 04:27

I had tried to move a working application to my stm32 discovery 'b'. I defined it as STM32F10X_LD_VL and am using the latest libraries from the stdperiph. 

The usart does not work at all (no high/low on scope). I had a fairly convoluted usart2 that did int on rx and dma on tx so I enabled usart3 and got the same result which is this. 

When I enable printf my code sits in this while loop forever 

while (USART_GetFlagStatus(USART2, USART_FLAG_TC) == RESET)

When I use USART_SendData(), I never see anything on the pins, even with a scope. It's always low. I send data to the usart and there is nothing ever in the buffer, so I'm pretty sure its either way. 

Its almost like its off. Moving the code back to my other board usart2 and 3 are working fine. 

here is the code i use to configure my usarts

void USART2_Config(void)

{

USART_InitTypeDef  USART_InitStructure;

NVIC_InitTypeDef  NVIC_InitStructure;

//Usart2_GPIO();

GPIO_InitTypeDef GPIO_InitStructure;

#ifndef STM32F10X_LD_VL

GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE);

#endif

RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA, ENABLE);

RCC_APB1PeriphClockCmd( RCC_APB1Periph_USART2, ENABLE); 

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;          

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;  

GPIO_Init(GPIOA, &GPIO_InitStructure);    

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;         

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;   

GPIO_Init(GPIOA, &GPIO_InitStructure);

USART_Cmd(USART2, DISABLE);

/* Enable the USARTz Interrupt */

NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

NVIC_Init(&NVIC_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);

// enable this int to trigger dma ?

USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);

//USART_ITConfig(USART2, USART_IT_TXE, ENABLE);

// setup dma for usart

USART_DMACmd(USART2, USART_DMAReq_Tx | USART_DMAReq_Rx, ENABLE);

// hold onto your butts

USART_Cmd(USART2, ENABLE);

}

void USART3_Config(void)

{

USART_InitTypeDef  USART_InitStructure;

//Usart2_GPIO();

GPIO_InitTypeDef GPIO_InitStructure;

RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB, ENABLE);

RCC_APB1PeriphClockCmd( RCC_APB1Periph_USART3, ENABLE); 

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;          

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;  

GPIO_Init(GPIOB, &GPIO_InitStructure);    

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;         

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;   

GPIO_Init(GPIOB, &GPIO_InitStructure);

USART_Cmd(USART3, DISABLE);

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

// hold onto your butts

USART_Cmd(USART3, ENABLE);

}

 If I never get responses to this post I would at least like to say thanks to Clive, even though this is my first post you have helped me several times already. 

5 REPLIES 5
Posted on August 06, 2012 at 16:46

Thanks.

The code here doesn't look to be unreasonable.

I probably wouldn't be using USART_DMACmd() until after I'd set up the individual DMA transfers. And would widen my scope to looking at the DMA and IRQ code.

I've just used the USART1 (PA9, PA10) on the VL-Discovery board.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
michaelmccartyeng
Associate II
Posted on August 06, 2012 at 19:35

I'll give usart1 a try and see if I get anything different. I'll try and rebuild the whole project with just Usart1 and nothing else to see if i get the same results. Its almost like its just ''off'' like I didnt turn the clock on, but with the same code works great on my other board. I'll let you know how it goes.

Guess this does not happen often or someone would have heard about it. 

thanks

Posted on August 06, 2012 at 21:48

You could double check the chip model/versions on the boards.  The STM32F100RBT6 is only rated for 24 MHz operation, no flash buffering or wait states. Other F1 code might assume 72 MHz operation.

You can read-back the RCC registers to confirm clocks are enabled.

If it gets stuck in the interrupt context, due to bad a bad handler, or drops into the Hard Fault routine, it might appear the device is not running any code. I'd start with polling mode, and output a continuous stream of characters or strings.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
michaelmccartyeng
Associate II
Posted on August 07, 2012 at 01:24

It is getting into the 24mhz. I tried usart1 and it works just fine. I thought for some reason I could not use usart1 because it was used for programming at some point. I will investigate the other two usarts using rcc to see if they are actually getting enabled as you suggest. 

All I wanted the stlink for was to test my protocol and I only need one usart for that so this should be plenty for me to debug it. 

These STchips are so awesome, so powerful and so inexpensive. Thanks Clive, good suggestions. I'll be around these boards more often.

Andrew Neil
Evangelist
Posted on August 10, 2012 at 01:23

''I had tried to move a working application to my stm32 discovery 'b' ... The usart does not work at all (no high/low on scope)''

 

Are you sure that the pin mappings are correct?