2025-07-28 4:49 PM
When I call the tx_event_flags_create() function, the code returns an error at the following line:
else if (event_control_block_size != (sizeof(TX_EVENT_FLAGS_GROUP)))
{
/* Event flags group pointer is invalid, return appropriate error code. */
status = TX_GROUP_ERROR;
}
I'm not sure why this would be a problem since I only have one TX_EVENT_FLAGS_GROUP defined in my program as far as I can see and the size of the struct passed in should match. Is there anything I could possibly be missing here?
2025-07-28 10:25 PM - edited 2025-07-28 10:32 PM
Add the code where you declare global
TX_EVENT_FLAGS_GROUP event_control_block
add code where you compute
event_control_block_size
and code tx_event_flags_create() ... and i will show you where is the problem !
Or double check:
you need to have a global variable with the structure TX_EVENT_FLAGS_GROUP
+ pass the address of this variable (not the variable) to tx_event_flags_create()
+ tx_event_flags_create() returns a success code, TX_SUCCESS if everithing is ok or an error code !
2025-07-29 6:30 AM
So the event flag variable is declared here at the top of my app_usbx_device.c:
TX_EVENT_FLAGS_GROUP EventFlag;
And then inside MX_USBX_Device_Init, the flag is created and throws the error:
if (tx_event_flags_create(&EventFlag, "Event Flag" != TX_SUCCESS) {
return TX_GROUP_ERROR
}
The event_control_block_size is computed in the tx_api.h file here:
#define tx_event_flags_create(g,n) _txe_event_flags_create((g),(n),(sizeof(TX_EVENT_FLAGS_GROUP)))
Both TX_EVENT_FLAGS_GROUP declarations seem to link to the same struct in tx_api.c hence why I was confused since the size should be the same here. Can you catch anything I might be overlooking?
2025-07-29 7:15 AM
But how do you compute your variable
event_control_block_size
??
2025-07-29 7:19 AM
That's the third argument passed into _txe_event_flags_create. Here's the function prototype:
UINT _txe_event_flags_create(TX_EVENT_FLAGS_GROUP *group_ptr, CHAR *name_ptr, UINT event_control_block_size);
2025-07-29 7:33 AM
But this variable is valid only inside that function, it is not global !
Use debugger and display in real time the value of this variable, eventually stepping through the code.
2025-07-29 7:38 AM - edited 2025-07-29 7:40 AM
Yes, but the following check is also inside that function.
else if (event_control_block_size != (sizeof(TX_EVENT_FLAGS_GROUP)))
{
/* Event flags group pointer is invalid, return appropriate error code. */
status = TX_GROUP_ERROR;
}
However, event_control_block_size is 36 while the sizeof(TX_EVENT_FLAGS_GROUP) is 40 even though they should be equal since the control block size is evaluated from the same expression if that makes sense.
2025-07-29 10:54 PM - edited 2025-07-29 11:07 PM
I guess I understood the problem.
You have a problem with a ThreadX function
UINT _txe_event_flags_create(TX_EVENT_FLAGS_GROUP *group_ptr, CHAR *name_ptr, UINT event_control_block_size)
{
TX_INTERRUPT_SAVE_AREA
UINT status;
ULONG i;
TX_EVENT_FLAGS_GROUP *next_group;
#ifndef TX_TIMER_PROCESS_IN_ISR
TX_THREAD *thread_ptr;
#endif
/* Default status to success. */
status = TX_SUCCESS;
/* Check for an invalid event flags group pointer. */
if (group_ptr == TX_NULL)
{
/* Event flags group pointer is invalid, return appropriate error code. */
status = TX_GROUP_ERROR;
}
/* Now check for proper control block size. */
else if (event_control_block_size != (sizeof(TX_EVENT_FLAGS_GROUP)))
{
/* Event flags group pointer is invalid, return appropriate error code. */
status = TX_GROUP_ERROR;
}
else
{
/* Disable interrupts. */
TX_DISABLE
.......
where TX_EVENT_FLAGS_GROUP is defined as below
/* Define the event flags group structure utilized by the application. */
typedef struct TX_EVENT_FLAGS_GROUP_STRUCT
{
/* Define the event flags group ID used for error checking. */
ULONG tx_event_flags_group_id;
/* Define the event flags group's name. */
CHAR *tx_event_flags_group_name;
/* Define the actual current event flags in this group. A zero in a
particular bit indicates the event flag is not set. */
ULONG tx_event_flags_group_current;
/* Define the reset search flag that is set when an ISR sets flags during
the search of the suspended threads list. */
UINT tx_event_flags_group_reset_search;
/* Define the event flags group suspension list head along with a count of
how many threads are suspended. */
struct TX_THREAD_STRUCT
*tx_event_flags_group_suspension_list;
UINT tx_event_flags_group_suspended_count;
/* Define the created list next and previous pointers. */
struct TX_EVENT_FLAGS_GROUP_STRUCT
*tx_event_flags_group_created_next,
*tx_event_flags_group_created_previous;
/* Define the delayed clearing event flags. */
ULONG tx_event_flags_group_delayed_clear;
#ifdef TX_EVENT_FLAGS_ENABLE_PERFORMANCE_INFO
/* Define the number of event flag sets. */
ULONG tx_event_flags_group_performance_set_count;
/* Define the number of event flag gets. */
ULONG tx_event_flags_group__performance_get_count;
/* Define the number of event flag suspensions. */
ULONG tx_event_flags_group___performance_suspension_count;
/* Define the number of event flag timeouts. */
ULONG tx_event_flags_group____performance_timeout_count;
#endif
#ifndef TX_DISABLE_NOTIFY_CALLBACKS
/* Define the application callback routine used to notify the application when
an event flag is set. */
VOID (*tx_event_flags_group_set_notify)(struct TX_EVENT_FLAGS_GROUP_STRUCT *group_ptr);
#endif
/* Define the port extension in the event flags group control block. This
is typically defined to whitespace in tx_port.h. */
TX_EVENT_FLAGS_GROUP_EXTENSION
} TX_EVENT_FLAGS_GROUP;
Now it seems that in some functions sizeof(TX_EVENT_FLAGS_GROUP) evaluate to 40 and some time to 36.
This can arise:
Post the whole project
or try yourself to debug with Include browser, after re-indexing and rebuilding after cleaning all compiled, including static libraries.
mike
P.S.: do not forget to mark as solved, if my suggestions are correct.