enable rts_gpio in RS485

Moderator: nferre

GaneshK
Posts: 3
Joined: Fri Apr 12, 2019 6:11 pm

enable rts_gpio in RS485

Thu May 02, 2019 6:04 am

Hello everyone,

I m trying to enable the rts_gpio in RS485, using a GPIO to control the RTS pin on one of the AT91 chips(SAMA5D27). Is there any patch to control the rts_GPIO. i tried to change the code in driver "drivers/tty/serial/atmel_serial.c", after some modifications i got the results as below

=> SAMA5D27 is receiving the data from other board.
SAMA5D27(RS485) <----------------------- Other(RS485)

=> SAMA5D27 is trasmitting the data to other board.
SAMA5D27(RS485) -----------------------> Other(RS485)

After Transmitting from SAMA527 to other board its not receiving anything from other board, its not coming back to receiving mode.

=> SAMA5D27 is not receiving the data from other board.
SAMA5D27(RS485) X<----------------------- Other(RS485)

Please anyone help me out from this issue...

Thanks & Regards
Ganesh
blue_z
Location: USA
Posts: 1943
Joined: Thu Apr 19, 2007 10:15 pm

Re: enable rts_gpio in RS485

Thu May 02, 2019 10:17 pm

GaneshK wrote: I m trying to enable the rts_gpio in RS485, using a GPIO to control the RTS pin on one of the AT91 chips(SAMA5D27).
...
i tried to change the code in driver "drivers/tty/serial/atmel_serial.c", ...
You neglect to describe what you did, but it is likely misguided.
RTS control for RS-485 is implemented in the Atmel USART hardware.
Study the SoC datasheet.

GaneshK wrote: Is there any patch to control the rts_GPIO.
The Linux kernel and the driver for the Atmel USART have supported the RS-485 hardware feature for quite a while, so there's no need for a patch.
Study the Documentation/serial/serial-rs485.txt file in the kernel source.

Regards
GaneshK
Posts: 3
Joined: Fri Apr 12, 2019 6:11 pm

Re: enable rts_gpio in RS485

Mon May 06, 2019 3:13 pm

Hello,

thank you for your reply...

my Kernel source version: 4.9.109..i wanted to transmit and receive the data by toggle one gpio up and down. Please help me to solve this.

my device tree:
*************
uart2: serial@f8024000 {
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_uart2_default>;
rtsgpio = <&pioA PIN_PC21 GPIO_ACTIVE_HIGH>;
atmel,use-dma-rx;
atmel,use-dma-tx;
linux,rs485-enabled-at-boot-time;
rs485-rts-delay = <0 200>;
status = "okay";
};

driver changes:
**************
in static void atmel_stop_tx(struct uart_port *port):
******************************************
atmel_uart_writel(port, ATMEL_US_IDR, atmel_port->tx_done_mask);
+ printk("in atmel_stop_tx flag:%x...\n",port->rs485.flags);
+#if 1
+ if (port->rs485.flags & SER_RS485_ENABLED){
+ if(reg_value && ATMEL_US_TXEMPTY){
+ if (port->rs485.flags & SER_RS485_RTS_AFTER_SEND){
+ gpio_set_value(port->rts_gpio, 1);}
+ else {
+ gpio_set_value(port->rts_gpio, 0);}
+ }}
+#endif
// if ((port->rs485.flags & SER_RS485_ENABLED) &&
// !(port->rs485.flags & SER_RS485_RX_DURING_TX))
// atmel_start_rx(port);

in static void atmel_start_tx(struct uart_port *port):
******************************************

+#if 1
+ if (atmel_use_pdc_tx(port) || atmel_use_dma_tx(port)){
+ if (port->rs485.flags & SER_RS485_ENABLED){
+ if(port->rs485.flags & SER_RS485_RTS_ON_SEND){
+ gpio_set_value(port->rts_gpio, 1);}
+ else {
+ gpio_set_value(port->rts_gpio, 0);}
+ }}
+#endif
// if (atmel_use_pdc_tx(port) || atmel_use_dma_tx(port))
// if ((port->rs485.flags & SER_RS485_ENABLED) &&
// !(port->rs485.flags & SER_RS485_RX_DURING_TX))
// atmel_stop_rx(port);

in static void atmel_init_rs485(struct uart_port *port, struct platform_device *pdev):
**********************************************************************
+ if (pdata && pdata->rts_gpio > 0)
+ port->rts_gpio = pdata->rts_gpio;
+ else if (np)
+ port->rts_gpio = of_get_named_gpio(np, "rtsgpio", 0);
+
+ if (gpio_is_valid(port->rts_gpio)) {
+ ret = devm_gpio_request(&pdev->dev, port->rts_gpio, "RTS");
+ if (ret) {
+ dev_err(&pdev->dev, "error requesting RTS GPIO\n");
+ // goto err;
+ }
+ ret = gpio_direction_output(port->rts_gpio, 0);
+ if (ret) {
+ dev_err(&pdev->dev, "error setting up RTS GPIO\n");
+ // goto err;
+ }
+ }

if (np) {
struct serial_rs485 *rs485conf = &port->rs485;
u32 rs485_delay[2];
/* rs485 properties */
if (of_property_read_u32_array(np, "rs485-rts-delay",
rs485_delay, 2) == 0) {
rs485conf->delay_rts_before_send = rs485_delay[0];
rs485conf->delay_rts_after_send = rs485_delay[1];
rs485conf->flags = 0;
}

if (of_get_property(np, "rs485-rx-during-tx", NULL))
rs485conf->flags |= SER_RS485_RX_DURING_TX;

+ if (of_get_property(np, "linux,rs485-enabled-at-boot-time",
+ NULL)){
+ rs485conf->flags |= SER_RS485_ENABLED;
+ rs485conf->flags |= SER_RS485_RTS_ON_SEND;
}


*********************************************************************************************above changes has been done by me in the driver...

the output is as like explained above... Please let me know the issue...ASAP

Thanks & Regards
Ganesh.K
blue_z
Location: USA
Posts: 1943
Joined: Thu Apr 19, 2007 10:15 pm

Re: enable rts_gpio in RS485

Wed May 08, 2019 12:11 am

If you want your driver code reviewed, then it needs to be readable.
(1) The code needs to be formated, i.e. use the "code" tag to preserve indentation.
(2) Use kernel coding style, e.g. if is a C keyword and not a function.

Regards
GaneshK
Posts: 3
Joined: Fri Apr 12, 2019 6:11 pm

Re: enable rts_gpio in RS485

Wed May 08, 2019 8:00 am

hello
i updated my code in driver...after flashing the zImage i m getting the kernel panic error...like below
********************************************************************************************
Starting kernel ...

Booting Linux on physical CPU 0x0
Linux version 4.9.109-linux4sam_5.8+-02111-gb7206f3-dirty (ganesh@phytec) (gcc version 7.3.1 20180425 [linaro-7.3-2018.05 revision d29120a424ecfbc167ef90065c0eeb9
CPU: ARMv7 Processor [410fc051] revision 1 (ARMv7), cr=10c53c7d
CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
OF: fdt:Machine model: Atmel SAMA5D27 SOM1 EK
cma: Failed to reserve 64 MiB
Memory policy: Data cache writeback
CPU: All CPU(s) started in SVC mode.
Built 1 zonelists in Zone order, mobility grouping off. Total pages: 16240
Kernel command line: console=ttyS0,115200 console=tty0 earlyprintk root=/dev/mmcblk1p2 rw rootwait
PID hash table entries: 256 (order: -2, 1024 bytes)
Dentry cache hash table entries: 8192 (order: 3, 32768 bytes)
Inode-cache hash table entries: 4096 (order: 2, 16384 bytes)
Memory: 55060K/65536K available (6144K kernel code, 212K rwdata, 1136K rodata, 1024K init, 196K bss, 10476K reserved, 0K cma-reserved)
Virtual kernel memory layout:
vector : 0xffff0000 - 0xffff1000 ( 4 kB)
fixmap : 0xffc00000 - 0xfff00000 (3072 kB)
vmalloc : 0xc4800000 - 0xff800000 ( 944 MB)
lowmem : 0xc0000000 - 0xc4000000 ( 64 MB)
modules : 0xbf000000 - 0xc0000000 ( 16 MB)
.text : 0xc0008000 - 0xc0700000 (7136 kB)
.init : 0xc0900000 - 0xc0a00000 (1024 kB)
.data : 0xc0a00000 - 0xc0a352c0 ( 213 kB)
.bss : 0xc0a352c0 - 0xc0a66378 ( 197 kB)
NR_IRQS:16 nr_irqs:16 16
L2C-310 ID prefetch enabled, offset 2 lines
L2C-310 dynamic clock gating enabled, standby mode enabled
L2C-310 cache controller enabled, 8 ways, 128 kB
L2C-310: CACHE_ID 0x410000c9, AUX_CTRL 0x36020000
clocksource: pit: mask: 0x7ffffff max_cycles: 0x7ffffff, max_idle_ns: 11654027029 ns
sched_clock: 32 bits at 100 Hz, resolution 10000000ns, wraps every 21474836475000000ns
Console: colour dummy device 80x30
console [tty0] enabled
Calibrating delay loop... 326.86 BogoMIPS (lpj=1634304)
pid_max: default: 32768 minimum: 301
Mount-cache hash table entries: 1024 (order: 0, 4096 bytes)
Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes)
CPU: Testing write buffer coherency: ok
Setting up static identity map for 0x20100000 - 0x20100058
devtmpfs: initialized
VFP support v0.3: implementor 41 architecture 2 part 30 variant 5 rev 1
clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
futex hash table entries: 256 (order: -1, 3072 bytes)
pinctrl core: initialized pinctrl subsystem
NET: Registered protocol family 16
DMA: preallocated 256 KiB pool for atomic coherent allocations
cpuidle: using governor menu
AT91: PM: standby: standby, suspend: ulp0
clocksource: tcb_clksrc: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 186464433812 ns
at_xdmac f0010000.dma-controller: 16 channels, mapped at 0xc4883000
at_xdmac f0004000.dma-controller: 16 channels, mapped at 0xc4885000
AT91: Detected SoC family: sama5d2
AT91: Detected SoC: sama5d27c 64MB SiP, revision 2
SCSI subsystem initialized
usbcore: registered new interface driver usbfs
usbcore: registered new interface driver hub
usbcore: registered new device driver usb
at91_i2c f8028000.i2c: could not find pctldev for node /ahb/apb/pinctrl@fc038000/i2c0_default, deferring probe
media: Linux media interface: v0.10
Linux video capture interface: v2.00
Advanced Linux Sound Architecture Driver Initialized.
clocksource: Switched to clocksource tcb_clksrc
NET: Registered protocol family 2
TCP established hash table entries: 1024 (order: 0, 4096 bytes)
TCP bind hash table entries: 1024 (order: 0, 4096 bytes)
TCP: Hash tables configured (established 1024 bind 1024)
UDP hash table entries: 256 (order: 0, 4096 bytes)
UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
NET: Registered protocol family 1
RPC: Registered named UNIX socket transport module.
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
RPC: Registered tcp NFSv4.1 backchannel transport module.
workingset: timestamp_bits=14 max_order=14 bucket_order=0
squashfs: version 4.0 (2009/01/31) Phillip Lougher
JFS: nTxBlock = 430, nTxLock = 3441
io scheduler noop registered (default)
pinctrl-at91-pio4 fc038000.pinctrl: atmel pinctrl initialized
[drm] Initialized
brd: module loaded
loop: module loaded
in atmel_serial_probe rs485...

in atmel_serial_probe rs485...2

in atmel_init_rs485 rs485...

in atmel_serial_probe rs485..3

atmel_usart_serial.0.auto: ttyS1 at MMIO 0xf801c000 (irq = 34, base_baud = 5125000) is a ATMEL_SERIAL
in atmel_serial_probe rs485...

in atmel_serial_probe rs485...2

in atmel_init_rs485 rs485...

in atmel_serial_probe rs485..3

atmel_usart_serial.1.auto: ttyS0 at MMIO 0xf8020000 (irq = 35, base_baud = 5125000) is a ATMEL_SERIAL
console [ttyS0] enabled
in atmel_serial_probe rs485...

in atmel_serial_probe rs485...2

in atmel_init_rs485 rs485...

in atmel_serial_probe rs485..3

in atmel_config_rs485...1

in atmel_config_rs485...2

in atmel_config_rs485...3

in atmel_config_rs485 if...4

Unable to handle kernel NULL pointer dereference at virtual address 00000028
pgd = c0004000
[00000028] *pgd=00000000
Internal error: Oops: 805 [#1] ARM
Modules linked in:
CPU: 0 PID: 1 Comm: swapper Not tainted 4.9.109-linux4sam_5.8+-02111-gb7206f3-dirty #248
Hardware name: Atmel SAMA5
task: c3b64b80 task.stack: c0a6e000
pc : [<c03aeda0>] lr : [<c03aed90>] psr: 60000013
sp : c0a6fc88 ip : 60000013 fp : 00000001
r10: c0a58048 r9 : c0a584c0 r8 : 00000478
r7 : 00000000 r6 : c0a58044 r5 : c0a58598 r4 : c0a584c0
r3 : 00000000 r2 : 000000c8 r1 : 00000000 r0 : 0000001d
Flags: nZCv IRQs on FIQs on Mode SVC_32 ISA ARM Segment none
Control: 10c53c7d Table: 20004059 DAC: 00000051
Process swapper (pid: 1, stack limit = 0xc0a6e208)
Stack: (0xc0a6fc88 to 0xc0a70000)
fc80: 00000002 c00c8600 c0a58044 c03b0e20 00000000 c00d0960
fca0: c07a038c c00c8610 ffffffed c0a1b244 fffffdfb 00000000 00000000 c0a1d224
fcc0: 00000000 c03f0be0 c0a593a4 c00c8610 c0a1b244 00000000 00000000 c03ef4a4
fce0: 00000000 c0a6fd10 c03ef638 00000001 c0a59380 c03ed96c c3b624dc c3bd0634
fd00: c00c8610 c00c8644 c0a1c0d0 c03ef200 c00c8610 00000001 c00c8610 c00c8618
fd20: c00c8610 c0a1c0d0 00000000 c03ee75c c00c8618 c0023810 c00c8610 c03ecae0
fd40: c00c8610 c0337404 c0a6fe3c c00c8600 00000000 c00c8600 c0023810 00000002
fd60: c00c8610 c00c8610 ffffffff c03f09f4 c0a6fe3c c00c8600 c0023810 00000000
fd80: 00000010 c040cca8 00000000 c2000b00 c00c9180 c3f6014c 40000013 c00c9184
fda0: c0a6fe80 00000000 00000001 c0023810 fffffffe 00000000 00000000 c040ce20
fdc0: 00000000 00000000 00000000 00000000 c00c9180 c01abac0 c0023810 c0023810
fde0: c00c91d0 fffffffe c0a6fe3c 00000001 c092b838 c0938f6c 00000000 c040ceec
fe00: 00000000 00000000 00000000 ffffffed c0023810 ffffffed c0a1d250 fffffdfb
fe20: 00000000 c040d1a4 00000000 00000000 00000000 c0215f60 00000000 c07a10b4
fe40: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
fe60: 00000000 c07a90ec 00000000 00000000 00000000 00000000 00000000 00000000
fe80: c0023810 c03f0be0 c0a593a4 c0023810 c0a1d250 00000000 00000000 c03ef4a4
fea0: c0023810 c0a1d250 c0023844 00000000 000000a9 c03ef634 00000000 c0a1d250
fec0: c03ef590 c03ed8c4 c3b624cc c3b5a830 c0a1d250 c00c7f80 c0a1c0d0 c03ee9fc
fee0: c07a90dc c04ad484 c0a1d250 c0a1d250 c091d5b8 c092b830 c0a352c0 c03efd10
ff00: 00000000 c091d5b8 c092b830 c0101658 c0a0cd64 00000000 00000000 c020cd88
ff20: c0704a00 c3f2ec00 c0719214 c3f4e74d 000000a9 c012ea2c c081a4f0 c07ba6ec
ff40: c0777fc4 00000006 00000006 00000000 00000000 00000007 c0a352c0 c092b82c
ff60: 00000007 c0a352c0 c092b830 c0a352c0 000000a9 c0900cfc 00000006 00000006
ff80: 00000000 c0900528 00000000 c06b723c 00000000 00000000 00000000 00000000
ffa0: 00000000 c06b7244 00000000 c0107570 00000000 00000000 00000000 00000000
ffc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
ffe0: 00000000 00000000 00000000 00000000 00000013 00000000 3b32a3ba 2923ab3a
Function entered at [<c03aeda0>] from [<c03b0e20>]
Function entered at [<c03b0e20>] from [<c03f0be0>]
Function entered at [<c03f0be0>] from [<c03ef4a4>]
Function entered at [<c03ef4a4>] from [<c03ed96c>]
Function entered at [<c03ed96c>] from [<c03ef200>]
Function entered at [<c03ef200>] from [<c03ee75c>]
Function entered at [<c03ee75c>] from [<c03ecae0>]
Function entered at [<c03ecae0>] from [<c03f09f4>]
Function entered at [<c03f09f4>] from [<c040cca8>]
Function entered at [<c040cca8>] from [<c040ce20>]
Function entered at [<c040ce20>] from [<c040ceec>]
Function entered at [<c040ceec>] from [<c040d1a4>]
Function entered at [<c040d1a4>] from [<c03f0be0>]
Function entered at [<c03f0be0>] from [<c03ef4a4>]
Function entered at [<c03ef4a4>] from [<c03ef634>]
Function entered at [<c03ef634>] from [<c03ed8c4>]
Function entered at [<c03ed8c4>] from [<c03ee9fc>]
Function entered at [<c03ee9fc>] from [<c03efd10>]
Function entered at [<c03efd10>] from [<c0101658>]
Function entered at [<c0101658>] from [<c0900cfc>]
Function entered at [<c0900cfc>] from [<c06b7244>]
Function entered at [<c06b7244>] from [<c0107570>]
Code: e3a02c02 e5943004 e58421c4 e5952008 (e5832028)
---[ end trace 76a498d7b023ff2e ]---
Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b

---[ end Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b

random: fast init done
***************************************************************************************


i m sharing my driver file in tar file.
Please let me know the whats the issue..
blue_z
Location: USA
Posts: 1943
Joined: Thu Apr 19, 2007 10:15 pm

Re: enable rts_gpio in RS485

Thu May 09, 2019 1:36 am

You need to rebuild your kernel with symbols for debugging (i.e. make menuconfig -> Kernel hacking -> Compile the kernel with debug info : CONFIG_DEBUG_INFO) so that the trace is actually useful.

Regards

Return to “SAMA5-based”

Who is online

Users browsing this forum: No registered users and 2 guests