2020-08-20 03:32 AM
Hello,
I'm using STM32 with STM32CubeIDE
This is my code:
#define SOME_DATA 0x01
HAL_UART_Transmit ( & huart6 , SOME_DATA , 1 , 1000 ) ;
The compiler issues the following warning :
passing argument 2 of 'HAL_UART_Transmit' makes pointer from integer without a cast [-Wint-conversion]
What should I do to fix it ?
2020-08-20 06:23 AM
The value needs to exist in memory in order for you to pass a pointer to it.
const uint8_t SOME_DATA = 0x01;
HAL_UART_Transmit ( & huart6 , &SOME_DATA , 1 , 1000 ) ;
2020-08-20 04:27 PM
Where does it exist when we use:
#define SOME_DATA 0x01
Isn't "memory" the only option ?
2020-08-20 04:49 PM
And I tried what you suggested...what I get now is this message :
passing argument 2 of 'HAL_UART_Transmit' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
2020-08-20 04:59 PM
2020-08-20 05:00 PM
2020-08-21 04:02 PM
> Isn't "memory" the only option ?
Options are many. Try this :
#define SOME_DATA 0x01
HAL_UART_Transmit ( & huart6 , (uint8_t[]){ SOME_DATA } , 1 , 1000 ) ;
2020-08-21 05:21 PM
Write a wrapper subroutine that takes a byte constant instead of a pointer.
2020-08-22 04:53 AM
I don't see any hell with const types generally. Mostly they safeguard the developer from unintended or unwanted writes. And in those few exceptions casting just ensures that the developer has checked the code logic. The problem here is only present because ST's brainless code monkeys define a data pointers for transmit functions as uint8_t *, while all sane libraries define such pointers as const void *.
Just another HAL stupidity...
2023-11-13 10:09 AM - edited 2023-11-17 10:35 AM
the solution to your issue is as simple as using a pointer like this:
uint8_t c = 'a';
uint8_t* pd = &c;
uint8_t SOME_DATA = 0x01;
uint8_t* pData = &SOME_DATA ;
HAL_UART_Transmit ( & huart6 , pData, 1 , 1000 ) ;
you should be just fine this way :)