AnsweredAssumed Answered

USART on STM32F4 discovey Board

Question asked by sood.maharaj_shree_k on Aug 11, 2015
Latest reply on Aug 14, 2015 by sood.maharaj_shree_k
Hi all...,,
I have an stm32f429zi based discovery board with me and newly woking on ST series. Actually I want to run USART/UART on my board to enable serial communication with other devices..but I am facing a trouble in it.
I am configuring USART3 with TX and RX pins on PB10 and PB11. I want to send some data on tx pin so that I can connet oscilloscope on the PB10 pin and verify that some data is coming out. Similarly, I want to receive on interrupt basis from other device. I am using new HAL drivers to test USART.

#define buff_sz 255

char rcv_buff[buff_sz+1];
char tx_buff[buff_sz];
static uint8_t DataReceivedCounter = 0;
volatile uint32_t msTicks;                      /* counts 1ms timeTicks       */

GPIO_InitTypeDef GPIO_Struct;
USART_InitTypeDef USART_Struct;
USART_HandleTypeDef Usart_handle;
USART_TypeDef usart_reg;

void SysTick_Handler(void)

// delays number of tick Systicks (1 ms delay)

void Delay_ms (uint32_t dlyTicks)
     uint32_t curTicks;
     curTicks = msTicks;
     while ((msTicks - curTicks) < dlyTicks);

void usart_set(long baud)
     //GPIO_InitTypeDef GPIO_Struct;
     //USART_InitTypeDef USART_Struct;


     //enable the clocks for the GPIOB and the USART

     //Initialize pins GPIOB 10 and GPIOB 11 PORTB
     GPIO_Struct.Pin = GPIO_PIN_10|GPIO_PIN_11;
     GPIO_Struct.Mode = GPIO_MODE_AF_PP ;     //setting the pin as alternative function
     GPIO_Struct.Alternate = GPIO_AF7_USART3;
     GPIO_Struct.Pull = GPIO_NOPULL;
     HAL_GPIO_Init(GPIOB, &GPIO_Struct);

     GPIO_Struct.Pin = GPIO_PIN_13|GPIO_PIN_14;
     GPIO_Struct.Mode = GPIO_MODE_OUTPUT_PP;
     GPIO_Struct.Pull =  GPIO_PULLUP;
     GPIO_Struct.Speed = GPIO_SPEED_FAST;
     HAL_GPIO_Init(GPIOG, &GPIO_Struct);

     //configure USART
     USART_Struct.BaudRate = baud;
     USART_Struct.WordLength = USART_WORDLENGTH_8B;
     USART_Struct.StopBits = USART_STOPBITS_1;
     USART_Struct.Parity = USART_PARITY_NONE;
     USART_Struct.Mode = USART_MODE_TX_RX; //enable send and receive (Tx and Rx)

     Usart_handle.Init = USART_Struct;
     Usart_handle.Instance = USART3;
     Usart_handle.RxXferCount = rcv_buff;
     Usart_handle.RxXferSize = sizeof(rcv_buff);
     Usart_handle.TxXferCount = tx_buff;
     Usart_handle.TxXferSize = sizeof(tx_buff);

     //Enable the interrupt

void send_data(USART_HandleTypeDef *husart, char *s)
     char chk = "";
     chk = HAL_USART_Transmit(&husart,(uint8_t*)s,strlen(s),100);
     while ((chk != HAL_OK)||(*s))

void recv_data(USART_HandleTypeDef *husart)
     char stat = "";
     stat  = HAL_UART_Receive_IT(husart, &rcv_buff, sizeof(rcv_buff));
          HAL_UART_Receive_IT(husart, &rcv_buff, sizeof(rcv_buff));
          char *rc_data = "";
          rc_data = rcv_buff;

void USART3_IRQHandler(void)

int main(void)
     if (SysTick_Config(SystemCoreClock / 1000))
     { /* SysTick 1 msec interrupts  */


          send_data(&Usart_handle,"Hello ho");
I will be thankful to yo guys if some body shed light on it.