So came up with the possible solution but I'm concerned it's inefficient. To give you some context, the task reads from the RS485 till it finds the start byte (0x53) then reads the next 4 bytes to get the LSB and MSB of the message size, with that in hand it reads the whole message.
Any feedback would be appreciated.
void usart_receive_task(void* pvParameters) {
int error;
size_t n;
NVIC_SetPriority(FLEXCOMM2_IRQn, 5);
do {
do {
USART_RTOS_Receive(RS485_2_rtos_handle, receive_buffer, 1, &n);
} while ((n != 1) && (receive_buffer[0] != 0x53));
size_t bits_for_address = 4;
do {
USART_RTOS_Receive(RS485_2_rtos_handle, receive_buffer + 1 + (4 - bits_for_address), bits_for_address, &n);
bits_for_address -= n;
} while (bits_for_address > 0);
uint16_t msg_size = receive_buffer[2] + (receive_buffer[3] << 8);
} while (error != kStatus_Success);
}