Queue fails on literal constant

akimata wrote on Monday, November 11, 2019:

I’ve been playing with RTOS and i can’t quite understand why queue fails on passing address of pointer to constant literal.

void eventGive(void *pv)
	eventControl_t *eControl = (eventControl_t *)pv;
	uint8_t requiredBits = (EVENT1_BIT | EVENT2_BIT | EVENT3_BIT);

		xQueueSend(gatekeeperQueue, &tekst[eControl->textNum], portMAX_DELAY);
		xEventGroupSync(eventGroupTest, eControl->eventBit, requiredBits, portMAX_DELAY);
		xQueueSend(gatekeeperQueue, &"sync", portMAX_DELAY);

		vTaskDelay(rand() % 200);

Right after xQueueSend(the one after EventGroupSync) finishes and preemption starts my processor hardfaults without a reason. The weirder part is that if i replace :

xQueueSend(gatekeeperQueue, &"sync", portMAX_DELAY);


> const char *syncText = "sync";
> xQueueSend(gatekeeperQueue, &syncText, portMAX_DELAY);

Everything is back to normal and works as intended.
Hardware: NXP K22 processor with Cortex M4 core

richard_damon wrote on Monday, November 11, 2019:

I think &“sync” doesn’t give you what you think it does. it doesn’t give you the address of a pointer to the string, but the address of the string with type char[5]. That means that rather than putting into the queue a pointer to string, you are putting the characters themselves into the queue, so when the receive task receives that as a pointer and trys to access the memory it points to you fault.

akimata wrote on Monday, November 11, 2019:

Oh, you are absolutely right. I dont know why did i think that i can get address of a pointer from a constant literal like that. That also explains why second method worked without problem.

Thanks :slight_smile: