cancel
Showing results for 
Search instead for 
Did you mean: 

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

DDurk.1
Associate II

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!

1 ACCEPTED SOLUTION

Accepted Solutions
DDurk.1
Associate II

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

View solution in original post

3 REPLIES 3
TDK
Guru

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

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

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
Associate II

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