Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 7742

General • Function pointers in struct: RP2350B fails to start

$
0
0
So, again, there must be some noob mistake but I can't figure out what is going on, what to check..

I have a fairly large project, everything must be compiled into RAM ("copy_to_ram") because of the speed constaints. There are about 22kB RAM left.
I've defined and I'm using a 256 element array having function pointers inside:

Code:

typedef uint8_t (*tvc_function_t)(uint8_t* bufferStart);// . . .tvc_function_t tvc256k_function_array[256] = {    clear_text_screen,              // 00    clear_bitmap_screen,// . . .};
I can use this, it works well. In the .map file it looks like this:

Code:

.data.tvc256k_function_array                0x20025d38      0x400 CMakeFiles/TVC-IO.dir/tvc-routines.c.obj                0x20025d38                tvc256k_function_array
and everything works as expected.

But when I'm creating another array, containing structs (and adding one more integer per each function), then the things get strange. Here's the code:

Code:

typedef struct  {    tvc_function_t func;    uint8_t param_size;} tvc_function_struct_t;// . . .tvc_function_struct_t tvc256k_funct_struct_array[256] = {    {clear_text_screen,             0},    {clear_bitmap_screen,           0},// . . .};
I create a reference in the source (way after main() entry) making sure it is compiled and linked:

Code:

tvc256k_funct_struct_array[d].param_size = 5;
where d is an uint8_t, then in the .map file it is visible that the array is defined properly:

Code:

 .data.tvc256k_function_array                0x20025ad0      0x400 CMakeFiles/TVC-IO.dir/tvc-routines.c.obj                0x20025ad0                tvc256k_function_array .data.tvc256k_funct_struct_array                0x20025ed0      0x800 CMakeFiles/TVC-IO.dir/tvc-routines.c.obj                0x20025ed0                tvc256k_funct_struct_array
The strange behaviour: programming the flash is successful, the LED will be blinking twice at the beginining of the main() function (the code starts properly).
But. If I reset the board with the reset button, then silence. If I power on the board, then silence.. I don't get it... What is going on? What did I do wrong?
AI is talking about garbage. I defined the int as uint32_t, didn't help. I casted the function pointers to uint32_t* and the copied to an uninitialized array -> same freeze.
Any ideas?


ps:
I have these in my CMakeFiles.txt

Code:

target_compile_options(TVC-IO PRIVATE -fno-builtin-memcpy)target_compile_options(TVC-IO PRIVATE -fno-builtin-strcpy)
which I don't remember now why I put them there. Commenting them out results even the simple array solution to fail.. So I think I have put them for a good reason.

Statistics: Posted by dikdom — Sun Jun 28, 2026 4:53 pm



Viewing all articles
Browse latest Browse all 7742

Latest Images

Trending Articles



Latest Images