cancel
Showing results for 
Search instead for 
Did you mean: 

Handle RS485 DE signal from Linux

Mark81
Associate III

is there a way to tell the kernel (I'm using the Distribution Package) to use a specific pin (not the built-in DE signal) to control the Data Enable of an rs485 transceiver whenever I write something to the related tty?

7 REPLIES 7
mleo
Senior II

​Hello @Mark81​ ,

The USARTx_DE signal pins are defined by hw - see pinout table in DS.

If you need to use specific pin, you would have to control the specific gpio pin in your user code and establish necessary timing characteristics  of the DE signal.

See https://wiki.st.com/stm32mpu/wiki/How_to_control_a_GPIO_in_userspace

I hope I understood you correctly.

BR,

Milan

Mark81
Associate III

Exactly. What I wonder is if there's a way to instruct the kernel to handle the pin automatically. I find something in the kernel source code:

https://docs.huihoo.com/doxygen/linux/kernel/3.7/include_2uapi_2linux_2serial_8h_source.html

but it still uses the RTS pin. Perhaps there is a settings to do this with a different gpio.

The problem with manual handling in user space is that I cannot know exactly when the FIFO tx buffer is empty.

I mean, if I `fwrite`, say, 100 bytes to `/dev/ttySTM2` how can I be SURE to change the DE pin just a couple of ms after the last bit of the last byte was sent? Writing a firmware this is a very simple task, but writing a software in user space, without knowing all the stuff between my application and the hw is quite frightening.

mleo
Senior II

​Hi @Mark81​ ,

There's a solution to your issue, see this patch coming from community:

https://patchwork.kernel.org/project/linux-arm-kernel/list/?series=274187

Warning - this patch hasn't been backported, tested and delivered by ST.

Milan

Mark81
Associate III

Thanks! But I don't understand how to apply these patches.

I searched for `stm32-usart.c` under the whole Distribution-Package and it finds nothing.

Hi @Mark81​ ,

To update/patch/rebuild the kernel is an advanved topic.

You need to use Developer package - study please information provided in following links:

https://wiki.st.com/stm32mpu/wiki/STM32MP1_Developer_Package#Building_and_deploying_the_Linux_kernel_for_the_first_time

https://github.com/STMicroelectronics/meta-st-stm32mp/blob/dunfell/recipes-kernel/linux/linux-stm32mp/README.HOW_TO.txt

https://wiki.st.com/stm32mpu/wiki/Getting_started/STM32MP1_boards/STM32MP157x-DK2/Develop_on_Arm%C2%AE_Cortex%C2%AE-A7/Modify,_rebuild_and_reload_the_Linux%C2%AE_kernel

The see file `stm32-usart.c` in Distribution-Package tou have to first run build using bitbake command. Then you can find it in build_xxxx directory.

Hope this helps

Milan

Hi @mleo​ Did you test that patch on linux-st kernel? I use it on my kernel and doesn't work.

Hi @Community member​ ,

I consulted with an expert - the patch covering rs485 isn't yet mature enough.

Either you can finalize on your own or wait until it's ready.

Best regards,

Milan