Your problem is that you call it with
xTaskCreate(hello_task, “hello_task”, 2048, “1”, 5, NULL, NULL);
As task additional parameter you pass a pointer to a constant string, but a pointer to void is expected, so use
(void*)“1”
Additionally you pass two NULL parameters after the ‘5’ (which is the task prioritoy). Only one is allowed (for optinal task handle).
Additionally, 2048 would mean 8192 bytes of stack for an ARM Cortex-M (32bit).
(and cast the result to void if you are not interested in the error code).
So better write
You could put an explicit cast to get around the problem, but the issue is that the void pointer passed to the task isn’t made a const pointer because some applications want to pass a writeable buffer through it, which they can’t if the pointer was made const.
In C++, string literals are const, so there pointers will not implicitly decay to a non-const pointer.
That case would work in C, (with perhaps a warning) as in C string literals do not have const type (but shouldn’t be changed) due to historial reasons.
This looks like a C question, not a FreeRTOS question directly, it just
happens to be on a FreeRTOS API function.
https://www.freertos.org/a00125.html shows the fourth parameter to
xTaskCreate() is a void , and you are passing “1”, and in C strings
are referenced using a character pointer (char). In this case the
string is a const, so you are passing a const char *. The warning
generated is therefore not what I would expect, as it says:
invalid conversion from ‘const void*’ to ‘void*’
whereas I would expect
invalid conversion from ‘const char*’ to ‘void*’
You may be able to avoid the error by casting the const char * to a void
as ‘( void * ) “1”’ - but that might just generate another warning
about casting away a const - but in any case I doubt that is what you
intended to do anyway. If you want to pass a pointer to the string “1”
it would be best to know where the string was allocated - in your code
it could be allocated anywhere (in RAM, on the stack, in flash as it is
a const, etc.) and its location is likely to change depending on the
compiler optimisation level.
Gentelmen, enormously helpful. Thank you very much. My C is 3 month old and RTOS is a few days. Thank you for taking time to breakdown the basics for me .
Cheers.
Andrew