1
\$\begingroup\$

Back with my STM32 adventures(data sheet). This time trying to get UART data through the USB. Essentially I want to be able to print over usb to start printing out variables to further debug code.

I am using the classic NUCLEO-L432KC board and I read somewhere for debug purposes you can print through the USB (ST-LINK) by setting up UART on the PA_2 pin.

What I have tried doing is setting up PA_2 to be a UART_2_TX pin and transmitting a constant decimal number (0x50) then using my mac terminal to 'screen" into the com port of the NUCLEO board. However I am getting this? The UART is working as on the oscilloscope scope I am getting data through. Any idea whats going on?

enter image description here In terminal using: screen /dev/tty.usbmodem1423 9600

The code:

/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file           : main.c
  * @brief          : Main program body
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
  * All rights reserved.</center></h2>
  *
  * This software component is licensed by ST under BSD 3-Clause license,
  * the "License"; You may not use this file except in compliance with the
  * License. You may obtain a copy of the License at:
  *                        opensource.org/licenses/BSD-3-Clause
  *
  ******************************************************************************
  */
/* USER CODE END Header */

/* Includes ------------------------------------------------------------------*/
#include "main.h"


int main(void)
{
    RCC->APB1ENR1 |= (1<<17); // Enable USART2 Clock
    RCC->AHB2ENR = (1<<0); //Enable GPIOA Clock
    RCC->CCIPR = (1<<2); //Use the System Clock for USART2

    GPIOA->MODER &= ~(1<<4); //Enable Alt Function for PA_2
    GPIOA->AFR[0] = ((1<<10) | (1<<9) | (1<<8)); //Enable USART2_Tx for PA_2

    USART2->CR1 = (1<<3); //Enable Transmitter
    USART2->BRR = 0x1A0; //9600 baudrate
    USART2->CR1 |= (1<<0); //Enable USART2

  while (1)
  {
      USART2->TDR = 0x50; //Put data in the Transmitter reg
      while(((USART2->ISR) & (1<<7)) == 0); //Wait till transmitter reg is empty
  }


}
\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

There was a screen process still running in the background that didn't close properly. Force closing the remaining process and restarting screen worked.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.