• AVR Freaks

Hot!SAMA5D2 atmel serial sends '0' in serial port on close() syscall

Author
axel101
New Member
  • Total Posts : 3
  • Reward points : 0
  • Joined: 2020/12/29 06:12:36
  • Location: 0
  • Status: offline
2021/01/12 04:22:18 (permalink)
2 (1)

SAMA5D2 atmel serial sends '0' in serial port on close() syscall

Hi, All.
I am using SAMA5D2 MPU and serial port in linux.
Linux uses atmel_serial driver there is strange behavior of this driver. Each time a device file is closed, a 0 is sent to the port.
This happens when atmel_serial driver calls atmel_uart_writel(port, ATMEL_US_CR, ATMEL_US_TXDIS);
Atmel serial datasheet says that command ATMEL_US_TXDIS disables transmitter. This command sets a logical 0 in the TX line. Remoter receiver interpretes this as a 0 character because there should be logical 1 in line if nothing is happens.
What should I do in this case? Can I comment out  ATMEL_US_TXDIS command  call?
#1

9 Replies Related Threads

    ric
    Super Member
    • Total Posts : 29434
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: SAMA5D2 atmel serial sends '0' in serial port on close() syscall 2021/01/12 14:35:06 (permalink)
    4 (1)
    Never used that chip, but presumably when the serial peripheral is disabled, the pin reverts back to manual GPIO control, so you should set the state of that pin to HIGH rather than LOW before opening the port.

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #2
    blue_z
    New Member
    • Total Posts : 5
    • Reward points : 0
    • Joined: 2020/11/10 23:16:57
    • Location: 0
    • Status: offline
    Re: SAMA5D2 atmel serial sends '0' in serial port on close() syscall 2021/01/13 00:50:12 (permalink)
    0
    aermakov@topcon.comAtmel serial datasheet says that command ATMEL_US_TXDIS disables transmitter. This command sets a logical 0 in the TX line.
    How do you know this?  
     
     
    aermakov@topcon.comRemoter receiver interpretes this as a 0 character because ...
    A steady logical-low input to a UART is not a "0 character" (there is no framing), but is detected as a break condition. 
    I don't know offhand how Windows treats a break condition. 
    But I do know that termios can be configured to handle a break condition in a variety of ways on Linux. 
    Termios can be configured to ignore the receipt of a break condition, and the user application is never notified. 
    Or termios can be configured to report the receipt of a break condition either of two ways, and the user application will read either a single NUL byte or a three-byte pattern.
     
    aermakov@topcon.com... there should be logical 1 in line if nothing is happens.
    I'm not a board designer, but if you expect an undriven line to be high, then I assume that you need to do something to ensure that the line goes high.  
     
    You mention "using SAMA5D2 MPU", which seems to imply that you are using a custom board. 
    Look at the USART circuit(s) of the Xplained board; notice the pull-up resistors on the signal lines?
     
    aermakov@topcon.comCan I comment out  ATMEL_US_TXDIS command  call?
    No, that's not the proper fix. 
     
     
    Regards
    post edited by blue_z - 2021/01/13 00:52:22
    #3
    axel101
    New Member
    • Total Posts : 3
    • Reward points : 0
    • Joined: 2020/12/29 06:12:36
    • Location: 0
    • Status: offline
    Re: SAMA5D2 atmel serial sends '0' in serial port on close() syscall 2021/01/14 01:46:08 (permalink)
    0
    How do you know this?   
    I don't have an oscilloscope, so I connected a voltmeter and I got -6V (RS232 logical 1) while port is opened and +6V (logical 0) after closing port on TX line.
    A steady logical-low input to a UART is not a "0 character" (there is no framing), but is detected as a break condition. 
    Yes, you are right, thanks. But problem is that I can't change terminal settings on remote side
    I'm not a board designer, but if you expect an undriven line to be high, then I assume that you need to do something to ensure that the line goes high.   
    You mention "using SAMA5D2 MPU", which seems to imply that you are using a custom board. 
    Look at the USART circuit(s) of the Xplained board; notice the pull-up resistors on the signal lines?
    Yes, this is custom board. I looked at the circuit of our board and there is no pull-up resistor.
    The issue reproducing on FLEXCOM USART, but Xplained board has no FLEXCOM UART.
    I am not a board designer too, is there some instructions or recomendations which I could show to board designer?
    #4
    ric
    Super Member
    • Total Posts : 29434
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: SAMA5D2 atmel serial sends '0' in serial port on close() syscall 2021/01/14 01:51:20 (permalink)
    4 (1)
    Have you looked in to my suggestion of the GPIO setting for the TX pin?
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #5
    axel101
    New Member
    • Total Posts : 3
    • Reward points : 0
    • Joined: 2020/12/29 06:12:36
    • Location: 0
    • Status: offline
    Re: SAMA5D2 atmel serial sends '0' in serial port on close() syscall 2021/01/14 03:39:02 (permalink)
    0
    ric
    Have you looked in to my suggestion of the GPIO setting for the TX pin?

    My pin (PB28) by default configured as GPIO input with pull-up resistor. I didn't tried to configure it as output and set to 1 yet, but I have found solution.
     
    There is no nessecary to pull-up by external resister since each pin can be configured with builtin pull-up resistor. I changed devicetree pin configuration from 'bias-disable' to 'bias-pull-up' and it works fine for me. But I confused that there are 'bias-disable' config by default.
    #6
    ric
    Super Member
    • Total Posts : 29434
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: SAMA5D2 atmel serial sends '0' in serial port on close() syscall 2021/01/14 03:58:09 (permalink)
    0
    I suspect setting it as "output high" would have the same effect.

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #7
    blue_z
    New Member
    • Total Posts : 5
    • Reward points : 0
    • Joined: 2020/11/10 23:16:57
    • Location: 0
    • Status: offline
    Re: SAMA5D2 atmel serial sends '0' in serial port on close() syscall 2021/01/14 18:37:47 (permalink)
    0
    aermakov@topcon.com... is there some instructions or recomendations which I could show to board designer?
    The DBGU port of Xplained board? 
    The RS-232 port of the SAMA5D3x-EK motherboards?
    Also see Proper connection for unused pins in SAMA5D2 devices
     
     
    aermakov@topcon.comI didn't tried to configure it as output and set to 1 yet, ...
    That would be an ugly kernel hack, and dynamic pin muxing is not recommended (especially for this issue).
     
     
    aermakov@topcon.comThere is no nessecary to pull-up by external resister since each pin can be configured with builtin pull-up resistor. I changed devicetree pin configuration from 'bias-disable' to 'bias-pull-up' and it works fine for me.
    That could be a Q&D solution.
     
    aermakov@topcon.comBut I confused that there are 'bias-disable' config by default.
    Possibly to minimize power consumption and/or avoid duplicate/multiple pull-ups. 

    Atmel/Microchip SAM9 and SAMA5 EK and Xplained boards seem to "always" install external pull-ups on DBGU (UART TTL) and RS-232 (USART) ports.  The only exception seems to be the SAMA5D4-EK, which does not have external pull-ups for its RS-232 port.  
     
    On the AT91SAM9M10-G45-EK both the DBGU and user RS-232 ports have external pull-ups, even though a tech support article mentions using internal pull-ups.  See  What is reason for TXD pull-up in SAM9G45 USART?
     
     
    You neglect to mention how this break condition and subsequent read of a NUL byte affects the receiving application.  
    If this is more than an aesthetics concern, i.e. it breaks the receiving protocol, then you may encounter future issues with disconnections and/or framing & parity errors.  
    IOW a robust receiving protocol should be able to cope with an extraneous NUL byte.
     
    Regards
    #8
    ric
    Super Member
    • Total Posts : 29434
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: SAMA5D2 atmel serial sends '0' in serial port on close() syscall 2021/01/14 18:43:03 (permalink)
    0
    blue_z
    aermakov@topcon.comI didn't tried to configure it as output and set to 1 yet, ...
    That would be an ugly kernel hack, and dynamic pin muxing is not recommended (especially for this issue).
     

    This is setting what the pin switches back to when the UART is disabled.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #9
    blue_z
    New Member
    • Total Posts : 5
    • Reward points : 0
    • Joined: 2020/11/10 23:16:57
    • Location: 0
    • Status: offline
    Re: SAMA5D2 atmel serial sends '0' in serial port on close() syscall 2021/01/14 19:07:48 (permalink)
    0
    ric
    This is setting what the pin switches back to when the UART is disabled.
    Not on any SAMA5 device.  
    A peripheral device is disabled by disabling its peripheral clock. 
    The pin muxing is not affected, and is separately controlled. 
    Two functions handled by two separate control subsystems of the SoC.
     
    Besides the OP is not "disabling" the UART device.  Merely the transmitter is disabled, an operation that is performed internal within the UART.
     
    Regards
     
    #10
    Jump to:
    © 2021 APG vNext Commercial Version 4.5