Skip to main content
DDurk.1
Associate II
February 24, 2022
Solved

Cannot convert 'std::string' {aka 'std::__cxx11::basic_string'} to 'const char*'

  • February 24, 2022
  • 3 replies
  • 16627 views

Here is my c++ code:

void print_console(std::string msg)

{

const char *p = msg.c_str();

  HAL_UART_Transmit_DMA(CONSOLE, p, strlen(msg));

  while (console_tx_flag == 0); // Wait until the uart transmit is complete

  console_tx_flag = 0;

}

Does anyone know how to fix this? The error is pointing to the HAL_UART_Transmis_DMA()

Thank you!

This topic has been closed for replies.
Best answer by DDurk.1

I figured it out, thanks you: HAL_UART_Transmit_DMA(CONSOLE, (uint8_t *)p, strlen(p));

3 replies

TDK
Super User
February 24, 2022

HAL_UART_Transmit_DMA(CONSOLE, p, strlen(p));

"If you feel a post has answered your question, please click ""Accept as Solution""."
DDurk.1
DDurk.1Author
Associate II
February 24, 2022

361 void print_console(std::string msg)

362 {

363 const char *p = msg.c_str();

364   HAL_UART_Transmit_DMA(CONSOLE, p, strlen(p));

365   while (console_tx_flag == 0); // Wait until the uart transmit is complete

366   console_tx_flag = 0;

367 }

yields the following errors:

Description Resource Path Location Type

invalid conversion from 'const char*' to 'const uint8_t*' {aka 'const unsigned char*'} [-fpermissive] main.cpp /STM32-SPI-Slave/Core/Src line 364 C/C++ Problem

make: *** [Core/Src/subdir.mk:58: Core/Src/main.o] Error 1 STM32-SPI-Slave C/C++ Problem

initializing argument 2 of 'HAL_StatusTypeDef HAL_UART_Transmit_DMA(UART_HandleTypeDef*, const uint8_t*, uint16_t)' stm32g4xx_hal_uart.h /STM32-SPI-Slave/Drivers/STM32G4xx_HAL_Driver/Inc line 1615 C/C++ Problem

DDurk.1
DDurk.1AuthorBest answer
Associate II
February 24, 2022

I figured it out, thanks you: HAL_UART_Transmit_DMA(CONSOLE, (uint8_t *)p, strlen(p));