RobertCNelson / bb-kernel

MIT License
130 stars 102 forks source link

Kernel 5.10 (and likely others) may need a patch to fix RS-485 #65

Closed willeccles closed 3 years ago

willeccles commented 3 years ago

After updating from 4.19 (where we did not see this issue, at least as far as we can recall) to 5.10, we ran into a problem where RS-485 would not send properly. Every now and again, it would send the amount of data we told it to, but it would resend the first byte of the previous message it sent, then the data we wanted, minus the last byte. After some digging, I found a patch which was submitted to the kernel which appeared it may have fixed this: https://github.com/torvalds/linux/commit/f6aa5beb45be27968a4df90176ca36dfc4363d37

I cherry-picked this patch onto HEAD for 5.10 and it seems to have fixed our RS-485 problem. It seems to have been reverted a few commit later (https://github.com/torvalds/linux/commit/3c9dc275dba1124c1e16e7037226038451286813), but the comment in the patch does call out AM335x so I decided to throw it in there and see what happened. The revert commit brings up a few counter-points, but for a kernel specifically built for an AM335x platform, it might make sense to use this patch.

I cherry-picked the patch on top of the kernel and ended up putting it into bb-kernel/patches/drivers/ti/serial after I verified it works. Let me know your thoughts on this. It would require a little more effort to backport, as I can't recall having this issue in 4.19 (though it may have happened and we didn't notice), so it might require a little digging to find out when it first became relevant.

This patch is definitely required for 5.11 as well, that much I know for certain.

Edit: it looks like this patch first appeared in v4.20, so it's possible that related commits post-4.19 caused the issue in the first place. It might be easier than I thought to figure out which kernels require the patch.

Another edit: I may take the time to figure out how to fix this "properly" (see the discussion in https://github.com/torvalds/linux/commit/3c9dc275dba1124c1e16e7037226038451286813) specifically for 8250 OMAP, but in the meantime, this patch does fix it. On the other hand, I have not properly tested a standard (non-485) UART with this, so that would be good to test as well.

RobertCNelson commented 3 years ago

Awesome @willeccles ! i've added a revert of https://github.com/torvalds/linux/commit/3c9dc275dba1124c1e16e7037226038451286813 to our current tree

funnyfrish commented 3 years ago

Is there a chance to test it? Is it using the 82650 driver or omap? What is required to use the rs485? Im using a self developed serial to rs485 cape. Using a gpio to enable transmit. I habe adopted the devicetree overlay and few changes in the kernel 4. Pls give a detailled insteuction how to enable rs485 in the kernel and what changes are required in the overlay.

Robert Nelson @.***> schrieb am Do., 20. Mai 2021, 21:30:

Awesome @willeccles https://github.com/willeccles ! i've added a revert of @.*** https://github.com/torvalds/linux/commit/3c9dc275dba1124c1e16e7037226038451286813 to our current tree

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/RobertCNelson/bb-kernel/issues/65#issuecomment-845416733, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAXWP6Y2C3E5N2ZJMP26N63TOVPPDANCNFSM45HRNLGQ .

RobertCNelson commented 3 years ago

To quickly test, just run:

git clone -b am33x-v5.7 https://github.com/RobertCNelson/bb-kernel.git
./build_deb.sh

cp linux-image*.deb to beagle, and install with

sudo dpkg -i linux-image*.deb
sudo reboot

Or wait a few more hours and it should hit the repo shortly..

Regards,

willeccles commented 3 years ago

Is there a chance to test it? Is it using the 82650 driver or omap? What is required to use the rs485? Im using a self developed serial to rs485 cape. Using a gpio to enable transmit. I habe adopted the devicetree overlay and few changes in the kernel 4. Pls give a detailled insteuction how to enable rs485 in the kernel and what changes are required in the overlay. Robert Nelson @.> schrieb am Do., 20. Mai 2021, 21:30: Awesome @willeccles https://github.com/willeccles ! i've added a revert of @. [torvalds/linux@3c9dc27](https://github.com/torvalds/linux/commit/3c9dc275dba1124c1e16e7037226038451286813) to our current tree — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub <#65 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAXWP6Y2C3E5N2ZJMP26N63TOVPPDANCNFSM45HRNLGQ .

RS-485 is already available in the kernel and is supported by GPIO OMAP. The only external hardware required is, of course, an RS-485 transceiver. The one downside is that the GPIO used for the RTS pin must be the RTSN pin corresponding to the UART's RTSN pin, though you should configure it in mode 7 (GPIO). Reference on built-in support for RS-485 can be found here: https://www.kernel.org/doc/html/latest/driver-api/serial/serial-rs485.html Note also that there are RS-485 configuration flags you should put in the device tree as well. See here: https://elixir.bootlin.com/linux/latest/source/Documentation/devicetree/bindings/serial/rs485.yaml

This patch is simply to fix a bug with RS-485 and does not add or remove any functionality.

willeccles commented 3 years ago

I am unable to test the patch you added, @RobertCNelson. I am using am335x-rt-v5.10, but can confirm of course that it works here. Unfortunately, our device does not have a UART line to test non-485 UART, so you should confirm that this patch does not mess with that at all. I doubt it will, but it's worth a test.

RobertCNelson commented 3 years ago

Hey @willeccles yeah that was for funnyfrish if he wanted to quickly test , i'll have 5.10.x patched by default shortly. ;)

funnyfrish commented 3 years ago

Thats very bad. Im using not the corresponsing rtsn pin. And also not all UARTS on BBB has a RTSN PIN. Im using other gpios... so I will have no luck with kernel 5.11 to get the rs485 work...

Robert Nelson @.***> schrieb am Do., 20. Mai 2021, 22:34:

Hey @willeccles https://github.com/willeccles yeah that was for funnyfrish if he wanted to quickly test , i'll have 5.10.x patched by default shortly. ;)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/RobertCNelson/bb-kernel/issues/65#issuecomment-845458157, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAXWP65L7O4FGJCXVU4X7T3TOVW5JANCNFSM45HRNLGQ .

willeccles commented 3 years ago

Thats very bad. Im using not the corresponsing rtsn pin. And also not all UARTS on BBB has a RTSN PIN. Im using other gpios... so I will have no luck with kernel 5.11 to get the rs485 work... Robert Nelson @.***> schrieb am Do., 20. Mai 2021, 22:34: Hey @willeccles https://github.com/willeccles yeah that was for funnyfrish if he wanted to quickly test , i'll have 5.10.x patched by default shortly. ;) — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#65 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAXWP65L7O4FGJCXVU4X7T3TOVW5JANCNFSM45HRNLGQ .

If you are having issues getting it to work, you will need to use the OMAP driver instead of the 8250-based driver, which is what this patch focuses on. The 8250-based driver does not support arbitrary GPIO RTS pins. Disable the 8250 OMAP driver in the kernel config and enable the OMAP UART driver separately.

willeccles commented 3 years ago

Hey @willeccles yeah that was for funnyfrish if he wanted to quickly test , i'll have 5.10.x patched by default shortly. ;)

Thanks Robert!

willeccles commented 3 years ago

Closing this, as it's been addressed and the discussion is no longer active.