cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F407 UART problems. PuTTY, FTDI USB to TTL converter

AAnth.1
Senior

EDIT: For crying out loud. Why is half of my code chopped off? 

#if !defined(__SOFT_FP__) && defined(__ARM_FP)
  #warning "FPU is not initialized, but the project is compiling for an FPU. Please initialize the FPU before use."
#endif
 
#include "stm32f4xx.h"
 
//	UART1 is used. Sits on APB2 bus
//	GPIOA sits on AHB1 bus. USART1 is AF7 for PA9 and PA10
//	PA9:	USART1_TX
//	PA10:	USART1_RX
//	Baudrate: 9600
 
void funcGPIOInit();
void funcUARTInit();
void funcUARTSend();
 
int main(void)
{
	funcGPIOInit();
	funcUARTInit();
	funcUARTSend();
	for(;;)
	{
 
	}
}
 
void funcGPIOInit()
{
	// Enable AHB1 bus. Set PA9 and PA10 to AF,
	RCC->AHB1ENR |= (1MODER |= (2MODER |= (2OTYPER &= ~(1OTYPER &= ~(1OSPEEDR &= ~(3OSPEEDR &= ~(3PUPDR &= ~(3PUPDR &= ~(3AFR[1] |= (7AFR[1] |= (7APB2ENR |= (1BRR = 0xD03;
	USART1->CR1 |= (1CR1 &= ~(1CR1 &= ~(1CR1 |= (1CR2 &= ~(3CR1 |= (1DR = 120;
}

6 REPLIES 6
AAnth.1
Senior
#if !defined(__SOFT_FP__) && defined(__ARM_FP)
  #warning "FPU is not initialized, but the project is compiling for an FPU. Please initialize the FPU before use."
#endif
 
#include "stm32f4xx.h"
 
//	UART1 is used. Sits on APB2 bus
//	GPIOA sits on AHB1 bus. USART1 is AF7 for PA9 and PA10
//	PA9:	USART1_TX
//	PA10:	USART1_RX
//	Baudrate: 9600
 
void funcGPIOInit();
void funcUARTInit();
void funcUARTSend();
 
int main(void)
{
	funcGPIOInit();
	funcUARTInit();
	funcUARTSend();
	for(;;)
	{
 
	}
}
 
void funcGPIOInit()
{
	// Enable AHB1 bus. Set PA9 and PA10 to AF,
	RCC->AHB1ENR |= (1MODER |= (2MODER |= (2OTYPER &= ~(1OTYPER &= ~(1OSPEEDR &= ~(3OSPEEDR &= ~(3PUPDR &= ~(3PUPDR &= ~(3AFR[1] |= (7AFR[1] |= (7APB2ENR |= (1BRR = 0xD03;
	USART1->CR1 |= (1CR1 &= ~(1CR1 &= ~(1CR1 |= (1CR2 &= ~(3CR1 |= (1DR = 120;
}

AAnth.1
Senior

I just noticed that the forum software alters my code snipped. LOL guys, seriously? You seem to have a bug in your software.

It is more likely what you're pasting. On a Mac?

Just attach as a buildable .C​ rather than inlining the code.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Hi clive1, I paste my code in from a windows machine. WIN10 as I did before in my other posts as well. I can also see that the software modifies my code. I set every register bit in its own line of code. However, the code shown above collected all register manipulations with an OR.

Anyway, let me attach the main.c file which contains the source code.

Thank you,

0693W000001tJC5QAM.jpg

0693W000001tJBlQAM.png

0693W000001tJBRQA2.png

I'd use 16 over-sampling, USART1->BRR = 0x683;

And loop on TXE before sending

void funcUARTSend()
{
  int i;
  for(i=0; i<10; i++)
  {
     while((USART1->SR & 0x80) == 0); // wait for TXE to assert
     USART1->DR = 0x55;
  }
}

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Hi clive1

I forgot to mention that I am using the discovery board, so you may already have known the issue upfront without going through my code. Sorry for that.

I eventually found the problem. PA9 and PA10 on the discovery board are already used for other hardware purposes, so there is a conflict when using PA9 as a TX for UART. I configured USART1 using PB6 and PB7 which are not used on the discovery board. I get the proper transmission now and everything works as expected.

Thank you,