Skip to main content
Morty Morty
Associate III
September 14, 2017
Question

Bug: pData in HAL_UART_Transmit should be const uint8_t *

  • September 14, 2017
  • 5 replies
  • 1168 views
Posted on September 14, 2017 at 11:08

The title says it all (I hope I don't need to explain why). I'm using: STM32Cube_FW_F3_V1.9.0 And while someone is at it: The other transmit functions need to be fixed, too.

#bug
This topic has been closed for replies.

5 replies

Tilen MAJERLE
ST Employee
September 14, 2017
Posted on September 14, 2017 at 15:24

Hello

moritz.struebe

‌,

this is technically not a bug until function doesn't modify input content.

I agree, it would make sense to replace to const parameter.

Best regards,

Tilen

Morty Morty
Associate III
September 14, 2017

Posted on September 14, 2017 at 15:47

The function does and should not modify the content. Also

HAL_UART_Transmit(&huart2,"Hello", 5, 0xFFF);

Will cause a compile error.

Rob.Riggs
Senior
July 29, 2018

I just ran into the same problem with

HAL_StatusTypeDef HAL_I2C_Mem_Write_DMA(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size);

pData should be "const uint8_t *". This causes me to write way too many const_cast<> in otherwise proper C++ code -- and then pray that the HAL designers are not doing anything funny with my buffer. "const" is a contract that the API makes with its users. Likewise, lack of "const" indicates that one MUST use double buffering if the original must not be modified by the called function, or they must be willing to break important code correctness rules.

ST, please fix this.

Tesla DeLorean
Guru
July 29, 2018

I'd kind of hope the compiler would also complain about strings with single-quotes too

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Morty Morty
Associate III
August 20, 2018

@Community member​  Yes, yes. You're right. My bad. One should c&p working code and not make it up on the fly