When is the puart rx callback called?

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Is it called immediately when anything is put into the uart rx buffer? Or does it wait until the buffer is either full or not receiving data to be called?

0 Likes
1 Solution
Anonymous
Not applicable

I didn't do exactly what he did, but I ended up implementing software flow control. Similar to his post, I just sent 16 bytes to the chip and had the chip respond over uart when it was done reading all 16 bytes and could receive another 16.

View solution in original post

0 Likes
6 Replies
BoonT_56
Employee
Employee
500 likes received 250 likes received 100 likes received

I was checking out the uart-fw-upgrade source code in the sdk and found that the callback is called once for every byte received. It depends on what you set for the RX watermark.

0 Likes
Anonymous
Not applicable

That's what I thought, but I'm getting some weird behavior. I'm sending a message to the uart rx pin that is 19 bytes long and I'm losing the last three bytes. Now I know the internal uart buffer is only 16 bytes, however, I figured since the callback fired every byte, it'd consume the bytes fast enough to not fill up the buffer and lose data. Since I'm only receiving the first 16 bytes, it seems like there is a large delay before the callback runs, causing the buffer to fill up before it can consume any bytes. I figured if the callback was firing once or twice as the buffer was filling that I would get 17 or 18 bytes, but I'm not. I tried lowering the baud rate so the data coming through the uart rx pin would come at a slower rate, it helped a little, but I ran into another bug where the data I send out through the uart tx pin starts losing bytes in the middle of the message. It seems since lowering the baud rate affects both pins, now the uart tx pin is receiving data from the chip too fast and losing data. I tried to enable flow control, but it appears to not be possible on the chip I have (BCM920737TAG). Are these bugs that I can't fix? Does anyone know of any work arounds?

0 Likes

The fifo size is 16 bytes.  If you need to send more than 16 bytes, you should use some flow control going back to the host saying that it can continue.  I think puart_control is using PUART_CONTROL_READ_CHUNK_SIZE for that purpose.

if (bytes_read % PUART_CONTROL_READ_CHUNK_SIZE == 0)
{
   test_puart_write(PUART_CONTROL_EVENT_CONTINUE);
}
0 Likes
Anonymous
Not applicable

swelan did you get a chance to test out what victorz wrote?

0 Likes
Anonymous
Not applicable

I didn't do exactly what he did, but I ended up implementing software flow control. Similar to his post, I just sent 16 bytes to the chip and had the chip respond over uart when it was done reading all 16 bytes and could receive another 16.

0 Likes
Anonymous
Not applicable

thanks for sharing!

0 Likes