2

I am using a NUCLEO-L4R5ZI-P board using the SMT32CubeIDE on Ubuntu 22.04. I've been working with a temperature sensor but I haven't figured out how to read the temperature data so currently I've just been trying to figure out if I can see "Hello World". Currently I Create a New STM32 project then select my board and I initialize all the peripherals to their default mode. For sake of brevity I will only post what I have in the main function.

int main(void)
{
  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MCU Configuration--------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* Configure the system clock */
  SystemClock_Config();

/* Configure the peripherals common clocks */
  PeriphCommonClock_Config();

  /* USER CODE BEGIN SysInit */

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_ADC1_Init();
  MX_CAN1_Init();
  MX_COMP1_Init();
  MX_COMP2_Init();
  MX_I2C1_SMBUS_Init();
  MX_I2C2_SMBUS_Init();
  MX_LPUART1_UART_Init();
  MX_USART2_UART_Init();
  MX_USART3_UART_Init();
  MX_SAI1_Init();
  MX_SAI2_Init();
  MX_SDMMC1_SD_Init();
  MX_SPI1_Init();
  MX_SPI3_Init();
  MX_TIM1_Init();
  MX_TIM2_Init();
  MX_TIM3_Init();
  MX_TIM4_Init();
  MX_TIM15_Init();
  MX_USB_OTG_FS_USB_Init();
  /* USER CODE BEGIN 2 */

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  char buf[12] = "Hello World!";
  while (1)
  {
    /* USER CODE END WHILE */
      HAL_UART_Transmit(&huart2, buf, strlen((char*)buf), HAL_MAX_DELAY);
    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

I then run this code in debugging mode and let it continue debugging, then I open up putty and run it on '/dev/ttyATM0' with a baud of 115200. No Message shows up and no matter if I use minicom or screen no message has ever showed up. I'm pretty stuck on this and have been reading many tutorials/questions but none have seemed to solve my issue. Any help would be appreciated.

EDIT

This is the code that includes USART2

static void MX_USART2_UART_Init(void)
{

  /* USER CODE BEGIN USART2_Init 0 */

  /* USER CODE END USART2_Init 0 */

  /* USER CODE BEGIN USART2_Init 1 */

  /* USER CODE END USART2_Init 1 */
  huart2.Instance = USART2;
  huart2.Init.BaudRate = 115200;
  huart2.Init.WordLength = UART_WORDLENGTH_8B;
  huart2.Init.StopBits = UART_STOPBITS_1;
  huart2.Init.Parity = UART_PARITY_NONE;
  huart2.Init.Mode = UART_MODE_TX_RX;
  huart2.Init.HwFlowCtl = UART_HWCONTROL_RTS_CTS;
  huart2.Init.OverSampling = UART_OVERSAMPLING_16;
  huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
  huart2.Init.ClockPrescaler = UART_PRESCALER_DIV1;
  huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
  if (HAL_UART_Init(&huart2) != HAL_OK)
  {
    Error_Handler();
  }
  if (HAL_UARTEx_SetTxFifoThreshold(&huart2, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)
  {
    Error_Handler();
  }
  if (HAL_UARTEx_SetRxFifoThreshold(&huart2, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)
  {
    Error_Handler();
  }
  if (HAL_UARTEx_DisableFifoMode(&huart2) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN USART2_Init 2 */

  /* USER CODE END USART2_Init 2 */

}

Also since pmacfarlane mentioned LPUART1 I will be posting that too here

static void MX_LPUART1_UART_Init(void)
{

  /* USER CODE BEGIN LPUART1_Init 0 */

  /* USER CODE END LPUART1_Init 0 */

  /* USER CODE BEGIN LPUART1_Init 1 */

  /* USER CODE END LPUART1_Init 1 */
  hlpuart1.Instance = LPUART1;
  hlpuart1.Init.BaudRate = 115200;
  hlpuart1.Init.WordLength = UART_WORDLENGTH_8B;
  hlpuart1.Init.StopBits = UART_STOPBITS_1;
  hlpuart1.Init.Parity = UART_PARITY_NONE;
  hlpuart1.Init.Mode = UART_MODE_TX_RX;
  hlpuart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  hlpuart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
  hlpuart1.Init.ClockPrescaler = UART_PRESCALER_DIV1;
  hlpuart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
  hlpuart1.FifoMode = UART_FIFOMODE_DISABLE;
  if (HAL_UART_Init(&hlpuart1) != HAL_OK)
  {
    Error_Handler();
  }
  if (HAL_UARTEx_SetTxFifoThreshold(&hlpuart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)
  {
    Error_Handler();
  }
  if (HAL_UARTEx_SetRxFifoThreshold(&hlpuart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)
  {
    Error_Handler();
  }
  if (HAL_UARTEx_DisableFifoMode(&hlpuart1) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN LPUART1_Init 2 */

  /* USER CODE END LPUART1_Init 2 */

}

  • Can you edit the question to include the code that configures UART2? Remember, it's not just the baud rate that has to match, the number of bits, parity and stop bits has to be the same. The flow control settings also have to be the same on each end. – pmacfarlane Mar 21 '23 at 20:13
  • Also, did you use the debugger to ensure that your main loop actually gets run? Some of the peripherals (notably the SDMMC) can fail to initialise and call the hard fault handler. – pmacfarlane Mar 21 '23 at 20:16
  • From reading the [user manual](https://www.st.com/resource/en/user_manual/um2179-stm32-nucleo144-boards-mb1312-stmicroelectronics.pdf) for the Nucleo-144 boards, it suggests that it is LPUART1 that is connected to the virtual COM port, not UART2. e.g. see section 5.11 of linked document. – pmacfarlane Mar 21 '23 at 20:38
  • Thank you for the response, how I run the program is that I first build the project then debug as (smt32 project) then resume the debugger which from looking at tutorials I believe is the way to run it. Haven't looked into LPUART1 since most of the tutorials used UART2 but I can't recall a tutorial that had done it on linux instead of windows so I'll see what I can do and report back. – PatTheTrickster Mar 21 '23 at 20:53
  • Change the config of LPUART1 to be 115200, 8N1, and change your `HAL_UART_Transmit()` to use `hlpuart1` and it will probably work. – pmacfarlane Mar 21 '23 at 20:54
  • Unfortunately still nothing shows up, do you think it will work with putty running as `putty /dev/ttyACM0 -serial -sercfg 115200,8,n,1,N` ? Or should I be trying to communicate with the serial port in some other way. – PatTheTrickster Mar 21 '23 at 21:02
  • I don't really use putty, but I'd do `minicom -D /dev/ttyACM0` then `^A-p` then select 115200 baud. (From memory.) – pmacfarlane Mar 21 '23 at 21:05
  • Unforunately minicom has also been destructive for me. Running it as you showed it seems like I am not able to bring up any options and the cursor just jumps up and down but no text ever shows up. Even running it as `sudo minicom -b 115200` it will do the same thing and not show any text besides " Welcome to minicom 2.8 OPTIONS: I18n Port /dev/ttyACM0, 16:07:59 Press CTRL-A Z for help on special keys " – PatTheTrickster Mar 21 '23 at 21:09
  • Maybe you should edit your question to show the new config for LPUART1. Just replace the old config function with the new one, no need to add it as an extra EDIT. – pmacfarlane Mar 21 '23 at 21:11
  • Just edited it, Just changed the BaudRate and Wordlength. – PatTheTrickster Mar 21 '23 at 21:14
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/252675/discussion-between-pmacfarlane-and-patthetrickster). – pmacfarlane Mar 21 '23 at 21:16

1 Answers1

2

The first problem is that you are sending data out on UART2, which is not connected to the virtual COM port on the Nucleo board.

Per the user manual for Nucleo-144 boards (section 5.11) it says that it is LPUART1 that is connected to the virtual COM port.

So change this:

HAL_UART_Transmit(&huart2, buf, strlen((char*)buf), HAL_MAX_DELAY);

to this:

HAL_UART_Transmit(&hlpuart1, buf, strlen((char*)buf), HAL_MAX_DELAY);

However, your code is not even getting as far as sending something on a UART. Due to a (in my opinion, terrible) decision by ST, trying to initialise the SDMMC peripheral without having an SD-card present results in Error_handler() being called. This (by default) disables interrupts and enters an infinite loop. So your initialisation does not complete, and your main loop is never reached.

If your board does not have an SD-card installed, the simplest solution is to disable the SDMMC peripheral in CubeIDE.

pmacfarlane
  • 3,057
  • 1
  • 7
  • 24