1

I've been struggling with this issue for a while where this code

uint8_t *PMTK = "$PSIMIPR,W,115200*1C";

gives me the error

pointer targets in initialization differ in signedness [-Wpointer-sign]

Changing it to only char * or unsigned char * does not make a difference, and const char * causes the program to complain further down where PMTK is supposed to be used, in the following code:

if (HAL_UART_Transmit(&huart3, PMTK, 32, 2000) != HAL_TIMEOUT)
          {
              HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_7);
              HAL_Delay(500);
              HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_7);
          }
          else
          { ....

The program is supposed to establish uart communication from STM32F0xx to a GPS receiver (SIM33ELA), using HAL driver.

Kater
  • 63
  • 10
  • For problems with compiler error messages, always include your compiler name and version in your question. – user694733 Feb 22 '18 at 09:43
  • @unwind The 2000 is a timeout counter, not the length of the string. `HAL_StatusTypeDef HAL_UART_Transmit (UART_HandleTypeDef * huart, uint8_t * pData, uint16_t Size, uint32_t Timeout)` @user694733 Sorry, compiler is Atollic TrueSUDIO, version 9.00 – Kater Feb 22 '18 at 09:46

2 Answers2

2

Yeah, that's a really annoying corner of the STM32 Cube libs. Someone should give them a big clue that random read-only buffers are best expressed as const void * in C ... mumble.

So, to fix it: It's convenient to use a string literal since the data is textual. So, make it so and then cast in the call, instead:

const char PMTK[] = "$PSIMIPR,W,115200*1C";

if (HAL_UART_Transmit(&huart3, (uint8_t *) PMTK, strlen(PMTK), 2000) != HAL_TIMEOUT)

Note use of strlen() to get the proper length, hardcoding literal values is never the right choice and was broken here (the string is not 32 characters long). We could use sizeof (it's an array, after all) too but that's bit more error-prone since you must subtract 1 for the terminator. I'm pretty sure compilers will optimize this strlen() call out, anyway.

unwind
  • 391,730
  • 64
  • 469
  • 606
1

c Strings are treated by the compiler as char[]. If you add a cast to (uint8_t *) before the String the warning is quieted.

uint8_t *PMTK = (uint8_t *)"$PSIMIPR,W,115200*1C";
Wolfgang
  • 48
  • 4