cancel
Showing results for 
Search instead for 
Did you mean: 

Having difficulty getting UART5 to do anything on STM32F407

szbrozek9
Associate II
Posted on March 23, 2012 at 21:07

Having difficulty getting UART5 to do anything on STM32F407

#stm32f407-uart
8 REPLIES 8
Posted on March 23, 2012 at 22:03

(no text)

The forum would appear to have eaten your carefully crafted question, please try again.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
szbrozek9
Associate II
Posted on March 23, 2012 at 22:55

Worst forum software ever indeed. There's FOSS forum software out there that actually works - why not use it?

My problem boils down to not having UART5 do anything. I can send data in and have nothing show up in the receive buffer. I can send data out and see no wiggles on the line. My first assumption is that I've done something dumb in the configuration:

http://pastebin.com/4RvPtnmB

Based on the examples in the STM32F4 standard peripheral library, I don't see any reason why this should not work. I have some, but not great, ability to see the states of registers. I'm using Ride7 but it doesn't have full register decoding yet.
stephen5489
Associate II
Posted on March 24, 2012 at 01:05

I have the same problem, I try to program the STM32, I configure the USART1 but dosen't work, I'm working in uVision Keil and coocox, at next, the main code.

#include ''stm32f10x_gpio.h''

#include ''stm32f10x_i2c.h''

#include ''stm32f10x_rcc.h''

#include ''stm32f10x_usart.h''

#include ''stm32f10x_conf.h''

#include <stdio.h>

USART_InitTypeDef USART_InitTypeDef1={

115200,

USART_WordLength_8b,

USART_StopBits_1,

USART_Parity_No,

(USART_Mode_Rx | USART_Mode_Tx ),

USART_HardwareFlowControl_None

};

void uart_init(){

RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOA |  RCC_APB2Periph_USART1,ENABLE);

GPIO_InitTypeDef GPIO_InitStructure;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;

GPIO_Init(GPIOA, &GPIO_InitStructure);

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;

GPIO_Init(GPIOA, &GPIO_InitStructure);

USART_Init(USART1,&USART_InitTypeDef1);

USART_Cmd(USART1,ENABLE);

}

int main(void)

{

uart_init();

printf(''Welcome!\r\n'');

    while(1)

    {

    }

}

stephen5489
Associate II
Posted on March 24, 2012 at 01:07

any suggestions?

alok472
Associate II
Posted on March 24, 2012 at 03:52

Did you try the standard Periph Lib example for F40x ? Better to start with the standard example..It always works !

Are you probing the UART pins on MCU or through a Level shifter like ST232 ?

Anything else working on MCU ? Toggling of LED/Heartbeat or any GPIO..?

Posted on March 24, 2012 at 05:25

  1.     GPIO_InitStructure.

    GPIO_Pin

    =

    GPIO_PinSource12

    ;

  2.     GPIO_Init

    (

    GPIOC,

    &

    GPIO_InitStructure

    )

    ;

  3.     GPIO_InitStructure.

    GPIO_Pin

    =

    GPIO_PinSource2

    ;

  4.     GPIO_Init

    (

    GPIOD,

    &

    GPIO_InitStructure

    )

    ;

Should be GPIO_Pin_12 and GPIO_Pin_2 respectively

PinSource is an index, Pin is a bit mask. GPIO_Init() permits the initialization of multiple pins on a GPIO bank.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on March 24, 2012 at 05:39

any suggestions?

Please stop hijacking threads with off-topic questions. Open your own threads, and try not to double post the same question, the audience here is finite. STEP ONE : I've suggested before that you call your own print character routine to prove that works. STEP TWO : Once you confirm that, then you'll be in a better position to try retargeting/hosting STDIO functions for your tool chain. For Keil, something like this

/*----------------------------------------------------------------------------
Write character to Serial Port
*----------------------------------------------------------------------------*/
int sendchar (int c) {
if (c == '
') {
while (!(USART1->SR & 0x0080));
USART1->DR = 0x0D;
}
while (!(USART1->SR & 0x0080));
USART1->DR = (c & 0x1FF);
return (c);
}
/*----------------------------------------------------------------------------
Read character from Serial Port (blocking read)
*----------------------------------------------------------------------------*/
int getkey (void) {
while (!(USART1->SR & 0x0020));
return (USART1->DR);
}
#include <
stdio.h
>
#include <
rt_misc.h
>
#pragma import(__use_no_semihosting_swi)
struct __FILE { int handle; /* Add whatever you need here */ };
FILE __stdout;
FILE __stdin;
int fputc(int ch, FILE *f) {
return (sendchar(ch));
}
int fgetc(FILE *f) {
return (getkey());
}
int ferror(FILE *f) {
/* Your implementation of ferror */
return EOF;
}
void _ttywrch(int ch) {
sendchar(ch);
}
void _sys_exit(int return_code) {
label: goto label; /* endless loop */
}

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

Brilliant, sir. That worked perfectly. I would never have spotted that on my own. Thank you very much!