Bird
Raised Fist0
FreeRTOSprogramming~20 mins

xEventGroupCreate() function in FreeRTOS - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Event Group Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
What is the output of this FreeRTOS code snippet using xEventGroupCreate()?

Consider the following FreeRTOS code snippet:

EventGroupHandle_t xEventGroup;
xEventGroup = xEventGroupCreate();
if (xEventGroup == NULL) {
    printf("Failed to create event group\n");
} else {
    printf("Event group created successfully\n");
}

What will be printed when this code runs on a properly configured FreeRTOS system?

FreeRTOS
EventGroupHandle_t xEventGroup;
xEventGroup = xEventGroupCreate();
if (xEventGroup == NULL) {
    printf("Failed to create event group\n");
} else {
    printf("Event group created successfully\n");
}
AEvent group created successfully
BFailed to create event group
CCompilation error due to missing header
DRuntime crash due to NULL pointer dereference
Attempts:
2 left
💡 Hint

Think about what xEventGroupCreate() returns when successful.

❓ Predict Output
intermediate
2:00remaining
What is the value of the event group handle after creation?

Given this code snippet:

EventGroupHandle_t xEventGroup = xEventGroupCreate();
printf("Handle value: %p\n", (void *)xEventGroup);

Which statement about the printed handle value is true?

FreeRTOS
EventGroupHandle_t xEventGroup = xEventGroupCreate();
printf("Handle value: %p\n", (void *)xEventGroup);
AIt causes a compilation error because of incorrect printf format
BIt prints NULL (0x0) because the event group is not created
CIt prints an integer zero because handles are integers
DIt prints a non-NULL pointer value representing the event group handle
Attempts:
2 left
💡 Hint

Remember what type EventGroupHandle_t is and how it is printed.

🔧 Debug
advanced
2:00remaining
Why does this code cause a runtime error after calling xEventGroupCreate()?

Examine this code snippet:

EventGroupHandle_t xEventGroup;
xEventGroupCreate();
xEventGroupSetBits(xEventGroup, BIT_0);

What is the cause of the runtime error?

FreeRTOS
EventGroupHandle_t xEventGroup;
xEventGroupCreate();
xEventGroupSetBits(xEventGroup, BIT_0);
AxEventGroupCreate() returns void, so no handle is created
BxEventGroup is not assigned the return value of xEventGroupCreate(), so it is uninitialized
CxEventGroupSetBits requires a NULL handle to work properly
DBIT_0 is not defined, causing a compile-time error
Attempts:
2 left
💡 Hint

Check if the event group handle is properly initialized before use.

🧠 Conceptual
advanced
2:00remaining
What happens if xEventGroupCreate() fails due to insufficient memory?

In FreeRTOS, if xEventGroupCreate() fails because there is not enough heap memory, what is the expected behavior?

AIt returns a handle with value zero (0) but valid internally
BIt triggers a system reset automatically
CIt returns NULL, indicating failure to create the event group
DIt blocks the calling task until memory is available
Attempts:
2 left
💡 Hint

Consider what the function returns on failure.

❓ Predict Output
expert
2:00remaining
How many bits are set after this sequence using an event group?

Given this code snippet:

EventGroupHandle_t xEventGroup = xEventGroupCreate();
xEventGroupSetBits(xEventGroup, (1 << 0) | (1 << 2));
EventBits_t uxBits = xEventGroupGetBits(xEventGroup);
printf("Bits set: %u\n", uxBits);

What is the printed output?

FreeRTOS
EventGroupHandle_t xEventGroup = xEventGroupCreate();
xEventGroupSetBits(xEventGroup, (1 << 0) | (1 << 2));
EventBits_t uxBits = xEventGroupGetBits(xEventGroup);
printf("Bits set: %u\n", uxBits);
ABits set: 5
BBits set: 3
CBits set: 6
DBits set: 0
Attempts:
2 left
💡 Hint

Calculate the bitwise OR of (1 << 0) and (1 << 2).

Practice

(1/5)
1. What does the xEventGroupCreate() function do in FreeRTOS?
easy
A. Creates a new event group and returns its handle
B. Deletes an existing event group
C. Sends an event to a task
D. Creates a new task

Solution

  1. Step 1: Understand the purpose of xEventGroupCreate()

    This function is designed to create a new event group in FreeRTOS, which is used for task communication.
  2. Step 2: Identify the return value

    The function returns a handle to the newly created event group, which is used to interact with it later.
  3. Final Answer:

    Creates a new event group and returns its handle -> Option A
  4. Quick Check:

    xEventGroupCreate() creates event group = A [OK]
Hint: Remember: create means new event group and get handle [OK]
Common Mistakes:
  • Confusing creation with deletion
  • Thinking it sends events instead of creating groups
  • Assuming it creates tasks
2. Which of the following is the correct way to declare and create an event group using xEventGroupCreate()?
easy
A. xEventGroupHandle_t xEventGroup = xEventGroupCreate();
B. EventGroupHandle_t xEventGroup = CreateEventGroup();
C. EventGroupHandle_t xEventGroup = xCreateEventGroup();
D. EventGroupHandle_t xEventGroup = xEventGroupCreate();

Solution

  1. Step 1: Check the correct type name

    The correct type for event group handles is EventGroupHandle_t.
  2. Step 2: Verify the function name

    The function to create an event group is exactly xEventGroupCreate().
  3. Final Answer:

    EventGroupHandle_t xEventGroup = xEventGroupCreate(); -> Option D
  4. Quick Check:

    Correct type and function name = C [OK]
Hint: Match exact type and function name spelling [OK]
Common Mistakes:
  • Using wrong type name like xEventGroupHandle_t
  • Using incorrect function names
  • Missing the semicolon
3. What will be the output of the following code snippet?
EventGroupHandle_t xGroup;
xGroup = xEventGroupCreate();
if (xGroup == NULL) {
    printf("Failed to create event group\n");
} else {
    printf("Event group created successfully\n");
}
medium
A. Event group created successfully
B. No output
C. Compilation error
D. Failed to create event group

Solution

  1. Step 1: Understand xEventGroupCreate() return value

    This function returns a valid handle if creation succeeds, otherwise NULL.
  2. Step 2: Analyze the if condition

    The code checks if the handle is NULL. If not NULL, it prints success message.
  3. Final Answer:

    Event group created successfully -> Option A
  4. Quick Check:

    Handle != NULL means success = D [OK]
Hint: Check if handle is NULL to confirm creation success [OK]
Common Mistakes:
  • Assuming NULL means success
  • Confusing printf output strings
  • Ignoring the if condition logic
4. Identify the error in the following code snippet that uses xEventGroupCreate():
EventGroupHandle_t xGroup;
xGroup = xEventGroupCreate;
if (xGroup == NULL) {
    // handle error
}
medium
A. Incorrect variable type for xGroup
B. Missing parentheses when calling xEventGroupCreate
C. No check for NULL handle
D. Using wrong function name

Solution

  1. Step 1: Check function call syntax

    The code assigns xEventGroupCreate without parentheses, so it assigns the function pointer, not the result.
  2. Step 2: Understand correct usage

    To call the function and get the handle, parentheses are required: xEventGroupCreate().
  3. Final Answer:

    Missing parentheses when calling xEventGroupCreate -> Option B
  4. Quick Check:

    Function call needs () = B [OK]
Hint: Always use () to call functions, not just name [OK]
Common Mistakes:
  • Forgetting parentheses on function calls
  • Confusing function pointer with return value
  • Not checking for NULL after creation
5. You want to create an event group and ensure your program handles failure gracefully. Which code snippet correctly creates the event group and checks for failure?
hard
A. EventGroupHandle_t xGroup = xEventGroupCreate(); if (xGroup == NULL) { /* proceed */ } else { /* handle error */ }
B. EventGroupHandle_t xGroup; xGroup = xEventGroupCreate; if (xGroup == NULL) { /* handle error */ }
C. EventGroupHandle_t xGroup = xEventGroupCreate(); if (xGroup != NULL) { /* proceed */ } else { /* handle error */ }
D. EventGroupHandle_t xGroup = CreateEventGroup(); if (xGroup == NULL) { /* handle error */ }

Solution

  1. Step 1: Verify correct function call and assignment

    EventGroupHandle_t xGroup = xEventGroupCreate(); if (xGroup != NULL) { /* proceed */ } else { /* handle error */ } correctly calls xEventGroupCreate() with parentheses and assigns the handle.
  2. Step 2: Check the logic for failure handling

    It checks if the handle is not NULL to proceed, else handles error. This is the correct logic.
  3. Final Answer:

    EventGroupHandle_t xGroup = xEventGroupCreate(); if (xGroup != NULL) { /* proceed */ } else { /* handle error */ } -> Option C
  4. Quick Check:

    Correct call and NULL check = A [OK]
Hint: Call with () and check if handle is NULL to handle errors [OK]
Common Mistakes:
  • Not using parentheses on function call
  • Reversing NULL check logic
  • Using wrong function name
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard