Loading...
 

SW4STM32 and SW4Linux fully supports the STM32MP1 asymmetric multicore Cortex/A7+M4 MPUs

   With System Workbench for Linux, Embedded Linux on the STM32MP1 family of MPUs from ST was never as simple to build and maintain, even for newcomers in the Linux world. And, if you install System Workbench for Linux in System Workbench for STM32 you can seamlessly develop and debug asymmetric applications running partly on Linux, partly on the Cortex-M4.
You can get more information from the ac6-tools website and download (registration required) various documents highlighting:

System Workbench for STM32


Unspecified Bounds Error When an Array is Passed to a Macro

I attempted to use this macro:

#define ARSIZE(AR) (((char *)(&AR+1) - (char *)(&AR))/( (char *)(&AR[1]) - (char *)(&AR[0]) ))

in code such as this:

int array[] = {1,2,3,4,5};
size_t N =  ARSIZE(array);

The compiler outputs the error:

invalid use of array with unspecified bounds

on the attempt to expand the macro in the last line above.

My expectation was the compiler would simply plug in the text “array” where the AR argument is in the macro definition and compile the code. What I find instead is the same error as if the array were attempted to be passed to any function this way.

How can an array be passed to this macro?

I have done some experimenting and I believe I understand what has happened here. The source of the error is this part of the macro:

&AR+1

This would work if the compiler knew the size of the array AR. Although the global arrays passed as AR are static, and their fixed sizes are known at compile time, they are defined in a .c file other than the ones this macro is expanded in. All the compiler has to go by is the declaration in the header which does not now have size information.

For the same reason the sizeof operator gets the same error &AR+1 does. It appears this macro has no advantage over using the sizeof operator this way:

#define ARSIZE(AR) sizeof(AR)/sizeof(*AR)

Earlier I attempted to define the size and initial contents of the array in the header. I got errors. Should it be possible to do this? An example syntax I used in the header is:

extern int arr = { 1, 2, 3, 4, 5 };

The error was these arrays were being defined more than once, in spite of using the typical compiler directive ifndef to assure that everything is declared only once, and the first time the header is included.

I am seeking to ease code maintenance and reduce opportunities for the code to be accidentally broken later should these array size be changed latter. I want the compiler or code execution to determine number of elements in these arrays, and do it with as few variables or macros as possible.