Hello!
I am trying to implement support for custom protocol working via RS-485. However I stumbled upon a problem with IO_IOCTL_SERIAL_WAIT_FOR_TC. In my configuration I need to switch a gpio pin after all the data has been sent. To ensure all the data is sent, I tried to use the above ioctl. But on the receiving side I do not get the tail of my data, so it looks like the ioctl returns before all the data is sent. However, I figured out that actually this ioctl does nothing other than waiting for the TC bit in UARTx_S1 register in an infinite loop. I simply removed the ioctl call and replaced it with exact the same infinite loop. Everything started to work as expected afterwards. So my question is, how is this possible? I looked through the serial ioctls part of MQX code and did not found any suspicious calls. For the reference, I am running MQX 4.0.1 on MK20DX256VLK7 CPU. Is there anything I missed in the documentation?
Best regards,
Mikhail Burakov
Solved! Go to Solution.
I am following a good tradition and replying to myself.
Actually it appears there's a bug in MQX source code. The file Freescale_MQX_4_0\mqx\source\io\serial\polled\serl_pol_kuart.c, line 958:
while( ! sci_ptr->S1 & UART_S1_TC_MASK )
must be replaced with:
while( ! (sci_ptr->S1 & UART_S1_TC_MASK))
to bring it in peace with operators precedence.
Best regards,
Mikhail Burakov
Hi Mikhail,
Just wanted to say thank you for your post and findings. It saved me a lot of headache today because I was having a similar problem until I stumbled on your post.
Thanks,
David
I am following a good tradition and replying to myself.
Actually it appears there's a bug in MQX source code. The file Freescale_MQX_4_0\mqx\source\io\serial\polled\serl_pol_kuart.c, line 958:
while( ! sci_ptr->S1 & UART_S1_TC_MASK )
must be replaced with:
while( ! (sci_ptr->S1 & UART_S1_TC_MASK))
to bring it in peace with operators precedence.
Best regards,
Mikhail Burakov
Hi Mikhail, you are absolutely right! It will be fixed in next MQX release. Thanks !