| 617 | == DTR |
| 618 | |
| 619 | Some board revisions will reqire DTR to be asserted before the board will come out of reset. DTR is part of a UART policy dating back to the modem days where by default 'HUP' is enabled which will send a 'hangup' signal (via DTR or data-terminal-ready) when the last process closes the tty. In essence DTR# is driven high when no processes have the UART device open and driven low when any process has the UART device open. Unfortunately this is the wrong polarity to 'just work' in an obvious manner. |
| 620 | |
| 621 | You can manually control DTR in a number of ways: |
| 622 | * use {{{picocom}}} ([#picocom see below]) which allows you to toggle DTR via control commands |
| 623 | * use {{{stty}}} to disable HUP which will release DTR# and drive it high letting the CC1352P out of reset but not that terminal programs may put it back in reset if they control DTR. |
| 624 | {{{#!bash |
| 625 | # Find the tty associated with the GW16122 device in your system |
| 626 | TTY=/dev/$(for i in $(ls -1d /sys/bus/usb/devices/*); do [ -r $i/interface ] && { [[ "$(cat $i/interface)" =~ "GW16122" ]] && basename $(ls -d $i/ttyUSB*); }; done) |
| 627 | echo $TTY |
| 628 | stty -F $TTY hup |
| 629 | }}} |
| 630 | * write your own UART code that uses the TIOCMBIS and TIOSMBIS ioctl to manually control the modem signals: |
| 631 | - with a C application use an ioctl on the tty from termios.h: |
| 632 | {{{#!c |
| 633 | cat << EOF > dtr.c |
| 634 | #include <errno.h> |
| 635 | #include <fcntl.h> |
| 636 | #include <stdio.h> |
| 637 | #include <stdlib.h> |
| 638 | #include <unistd.h> |
| 639 | |
| 640 | #include <sys/ioctl.h> |
| 641 | #include <sys/types.h> |
| 642 | #include <sys/stat.h> |
| 643 | |
| 644 | int main(int argc, char **argv) |
| 645 | { |
| 646 | int fd, line, assert; |
| 647 | const char *tty; |
| 648 | |
| 649 | if (argc < 2) { |
| 650 | fprintf(stderr, "usage: %s <ttydev> <0|1>\n", argv[0]); |
| 651 | exit -1; |
| 652 | } |
| 653 | |
| 654 | tty = argv[1]; |
| 655 | assert = atoi(argv[2]); |
| 656 | |
| 657 | /* open serial port */ |
| 658 | fd = open(tty, O_RDWR | O_NOCTTY); |
| 659 | if (fd == -1) { |
| 660 | perror("open"); |
| 661 | exit -errno; |
| 662 | } |
| 663 | |
| 664 | /* perform IOCTL to set DTR */ |
| 665 | line = TIOCM_DTR; |
| 666 | printf("%s: %s DTR#\n", tty, assert ? "assert" : "deassert"); |
| 667 | if (ioctl(fd, assert ? TIOCMBIS : TIOCMBIC, &line) == -1) { |
| 668 | perror("ioctl"); |
| 669 | close(fd); |
| 670 | exit (-errno); |
| 671 | } |
| 672 | close(fd); |
| 673 | |
| 674 | return 0; |
| 675 | } |
| 676 | EOF |
| 677 | }}} |
| 678 | {{{#!bash |
| 679 | gcc -c dtr.c -o dtr |
| 680 | chmod +x dtr |
| 681 | # Find the tty associated with the GW16122 device in your system |
| 682 | TTY=/dev/$(for i in $(ls -1d /sys/bus/usb/devices/*); do [ -r $i/interface ] && { [[ "$(cat $i/interface)" =~ "GW16122" ]] && basename $(ls -d $i/ttyUSB*); }; done) |
| 683 | echo $TTY |
| 684 | # make sure a HUP will not be sent when a process does not have control over the TTY |
| 685 | stty -F $TTY -hup |
| 686 | # assert DTR# (drive low; hold part in reset) |
| 687 | ./dtr $TTY 1 |
| 688 | # deassert DTR# (drive high; release part from reset) |
| 689 | ./dtr $TTY 0 |
| 690 | }}} |
| 691 | - use python-serial via a python script: |
| 692 | {{{#!python |
| 693 | cat << EOF > dtr |
| 694 | #!/usr/bin/env python |
| 695 | |
| 696 | import serial |
| 697 | import string |
| 698 | import sys |
| 699 | |
| 700 | if len(sys.argv) < 3: |
| 701 | print("usage: %s <ttydev> <0|1>\n" % sys.argv[0]) |
| 702 | exit(-1) |
| 703 | |
| 704 | dev=sys.argv[1] |
| 705 | lvl=string.atoi(sys.argv[2]) |
| 706 | |
| 707 | if lvl: |
| 708 | print("%s: assert DTR#\n" % dev) |
| 709 | else: |
| 710 | print("%s: deassert DTR#\n" % dev) |
| 711 | ser = serial.Serial(dev) |
| 712 | ser.isOpen() |
| 713 | ser.setDTR(lvl) |
| 714 | ser.close() |
| 715 | EOF |
| 716 | }}} |
| 717 | {{{#!bash |
| 718 | apt install python python-serial |
| 719 | chmod +x dtr |
| 720 | # Find the tty associated with the GW16122 device in your system |
| 721 | TTY=/dev/$(for i in $(ls -1d /sys/bus/usb/devices/*); do [ -r $i/interface ] && { [[ "$(cat $i/interface)" =~ "GW16122" ]] && basename $(ls -d $i/ttyUSB*); }; done) |
| 722 | echo $TTY |
| 723 | # make sure a HUP will not be sent when a process does not have control over the TTY |
| 724 | stty -F $TTY -hup |
| 725 | # assert DTR# (drive low; hold part in reset) |
| 726 | ./dtr $TTY 1 |
| 727 | # deassert DTR# (drive high; release part from reset) |
| 728 | ./dtr $TTY 0 |
| 729 | }}} |
| 730 | |