cancel
Showing results for 
Search instead for 
Did you mean: 

Bug: pData in HAL_UART_Transmit should be const uint8_t *

Morty Morty
Associate III
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
5 REPLIES 5
Tilen MAJERLE
ST Employee
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

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 III

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.

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
Up vote any posts that you find helpful, it shows what's working..
Morty Morty
Associate III

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