In trying to solve this problem, I've been copying the example given in this question How do you make an array of structs in C? So now my code looks like this:
#define NUM_TRACES 6
typedef struct
{
uint32_t upstream_pin;
uint32_t dnstream_pin;
uint32_t led_pin;
}trace;
struct trace traces[NUM_TRACES];
traces[0] = {GPIO_Pin_3, GPIO_Pin_7 , GPIO_Pin_0};
traces[1] = {GPIO_Pin_4, GPIO_Pin_6 , GPIO_Pin_1};
But I get the following errors
src/hal.c:17:14: error: array type has incomplete element type
struct trace traces[NUM_TRACES];
^
src/hal.c:19:1: warning: data definition has no type or storage class
traces[0] = {GPIO_Pin_3, GPIO_Pin_7 , GPIO_Pin_0};
I can sort of fix the first error by making the array be an array of pointers to trace structs which I think makes sense
struct trace* traces[NUM_TRACES];
but then these lines give an error
src/hal.c:19:1: warning: data definition has no type or storage class
traces[0] = {GPIO_Pin_3, GPIO_Pin_7 , GPIO_Pin_0};
^
src/hal.c:19:1: warning: type defaults to 'int' in declaration of 'traces'
src/hal.c:19:1: error: conflicting types for 'traces'
src/hal.c:17:15: note: previous declaration of 'traces' was here
struct trace* traces[NUM_TRACES];
^
src/hal.c:19:1: warning: excess elements in array initializer
traces[0] = {GPIO_Pin_3, GPIO_Pin_7 , GPIO_Pin_0};
^
Which I think is caused by trace[0] actually being a place to store the address of the data, not a place to store the data? But I don't know how to correct this and place the data where I want it in array.