cancel
Showing results for 
Search instead for 
Did you mean: 

Hello, i am used stm32F767zi, i want to send & receive data by using uart3 from wir STLINKv2.1 between my computer and a card stm32f767zi. but it doesn't work, Anny one can help me please .

Mouzi
Associate
 
4 REPLIES 4
//****************************************************************************
 
#define USART_RS232 USART3  // PD8/PD9 VCP
#define USART_RS232_IRQn USART3_IRQn
#define USART_RS232_IRQHandler USART3_IRQHandler
 
#ifdef USART_CR1_TXEIE_TXFNFIE // FIFO Support
#define USART_CR1_RXNEIE USART_CR1_RXNEIE_RXFNEIE
#define USART_CR1_TXEIE  USART_CR1_TXEIE_TXFNFIE
#define USART_ISR_RXNE   USART_ISR_RXNE_RXFNE
#define USART_ISR_TXE    USART_ISR_TXE_TXFNF
#endif
 
//****************************************************************************
 
void OutChar(char c)
{
  while((USART_RS232->ISR & USART_ISR_TXE) == 0); // Wait for Empty
  USART_RS232->TDR = c; // Send Char
}
 
//****************************************************************************
 
void USART3_Init(void)
{
  GPIO_InitTypeDef GPIO_InitStruct = { 0 };
  UART_HandleTypeDef UartHandle = { 0 };
 
  __USART3_CLK_ENABLE();
  __GPIOD_CLK_ENABLE();
 
  /* UART RX/TX GPIO pin configuration  */
  GPIO_InitStruct.Pin       = GPIO_PIN_8 | GPIO_PIN_9;
  GPIO_InitStruct.Mode      = GPIO_MODE_AF_PP;
  GPIO_InitStruct.Pull      = GPIO_PULLUP;
  GPIO_InitStruct.Speed     = GPIO_SPEED_HIGH;
  GPIO_InitStruct.Alternate = GPIO_AF7_USART3;
 
  HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
 
  /*## Configure the UART peripheral ######################################*/
  /* Put the USART peripheral in the Asynchronous mode (UART Mode) */
  /* UART1 configured as follow:
      - Word Length = 8 Bits
      - Stop Bit = One Stop bit
      - Parity = NO parity
      - BaudRate = 115200 baud
      - Hardware flow control disabled (RTS and CTS signals) */
  UartHandle.Instance        = USART3;
 
  UartHandle.Init.BaudRate   = 115200;
  UartHandle.Init.WordLength = UART_WORDLENGTH_8B;
  UartHandle.Init.StopBits   = UART_STOPBITS_1;
  UartHandle.Init.Parity     = UART_PARITY_NONE;
  UartHandle.Init.HwFlowCtl  = UART_HWCONTROL_NONE;
  UartHandle.Init.Mode       = UART_MODE_TX_RX;
 
  UartHandle.Init.OverSampling   = UART_OVERSAMPLING_16;
#ifdef UART_ONE_BIT_SAMPLE_DISABLE
  UartHandle.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
#endif
 
  if (HAL_UART_Init(&UartHandle) != HAL_OK)
  {
    /* Initialization Error */
    Error_Handler();
  }
}
 
//****************************************************************************
// Hosting of stdio functionality through USART - Keil
//****************************************************************************
 
/* Implementation of putchar (also used by printf function to output data)    */
int SendChar(int ch)                    /* Write character to Serial Port     */
{
  ITM_SendChar(ch); // From core_cm4.c
  OutChar((char)ch);
 
  return(ch);
}
 
//****************************************************************************
 
#include <rt_misc.h>
 
// Comment these out for v6 compiler
#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 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 */
}
 
//****************************************************************************
 
int main(void)
{
  USART3_Init();
 
  puts("\nNUCLEO-F767ZI Demo");
 
  printf("\n\nCore=%d, %d MHz\n", SystemCoreClock, SystemCoreClock / 1000000);
 
  /* Infinite loop */
  while(1)
  {
  }
}
 
//****************************************************************************

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

Demo as a .HEX file, loadable via ST-LINK Utilities, or STM32 Cube Programmer

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

Hello Clive,

I try the .HEX it's wrok successfully. thank you.

The problem is resolved.

The problem is cubemxIDE really!, in first when i create uart3 cubemxIDE assigned Pins: PB10 to TX and PB11 to RX. that's why it doesn't work.

The solution is to change Pins TX and RX for uart3 : 

Enable pin PD8 and choose USART3_TX 

Enable pin PD9 and choose USART3-RX. ( by default now PB10 and PB11 are disable )

Now i can use STLINK-V2.1 by UART3.

 you can found in the attachment the configuration of UART3 in CubeMxIDE. and console of output message in console sending by UART3. 

Thank you very much.0690X00000DXIxdQAH.png0690X00000DXIxYQAX.png

> The problem is cubemxIDE really!

O, really? Does it has to have an integrated crystal ball to know which pins your project will need? And, by the way, for ST's boards CubeMX has a board selector, which has the respective pins pre-pinned.