|
34 | 34 | import zipfile
|
35 | 35 | import argparse
|
36 | 36 | import tempfile
|
| 37 | +from mbed_cdc import mbed_cdc |
37 | 38 |
|
38 | 39 |
|
39 | 40 | # Application version
|
@@ -1752,103 +1753,6 @@ def formaturl(url, format="default"):
|
1752 | 1753 | return url
|
1753 | 1754 |
|
1754 | 1755 |
|
1755 |
| -def cdc(port, reset=False, sterm=False, baudrate=9600, timeout=10): |
1756 |
| - from serial import Serial, SerialException |
1757 |
| - |
1758 |
| - def get_instance(*args, **kwargs): |
1759 |
| - try: |
1760 |
| - serial_port = Serial(*args, **kwargs) |
1761 |
| - serial_port.flush() |
1762 |
| - except Exception as e: |
1763 |
| - error("Unable to open serial port connection to \"%s\"" % port) |
1764 |
| - return False |
1765 |
| - return serial_port |
1766 |
| - |
1767 |
| - def cdc_reset(serial_instance): |
1768 |
| - try: |
1769 |
| - serial_instance.sendBreak() |
1770 |
| - except: |
1771 |
| - try: |
1772 |
| - serial_instance.setBreak(False) # For Linux the following setBreak() is needed to release the reset signal on the target mcu. |
1773 |
| - except: |
1774 |
| - result = False |
1775 |
| - |
1776 |
| - def cdc_term(serial_instance): |
1777 |
| - import serial.tools.miniterm as miniterm |
1778 |
| - |
1779 |
| - term = miniterm.Miniterm(serial_instance, echo=True) |
1780 |
| - term.exit_character = '\x03' |
1781 |
| - term.menu_character = '\x14' |
1782 |
| - term.set_rx_encoding('UTF-8') |
1783 |
| - term.set_tx_encoding('UTF-8') |
1784 |
| - def cli_writer(): |
1785 |
| - menu_active = False |
1786 |
| - while term.alive: |
1787 |
| - try: |
1788 |
| - c = term.console.getkey() |
1789 |
| - except KeyboardInterrupt: |
1790 |
| - c = '\x03' |
1791 |
| - if not term.alive: |
1792 |
| - break |
1793 |
| - if menu_active: |
1794 |
| - term.handle_menu_key(c) |
1795 |
| - menu_active = False |
1796 |
| - elif c == term.menu_character: |
1797 |
| - menu_active = True # next char will be for menu |
1798 |
| - elif c == '\x02' or c == '\x12': # ctrl+b/ctrl+r sendbreak |
1799 |
| - cdc_reset(term.serial) |
1800 |
| - elif c == '\x03' or c == '\x1d': # ctrl+c/ctrl+] |
1801 |
| - term.stop() |
1802 |
| - term.alive = False |
1803 |
| - break |
1804 |
| - elif c == '\x05': # ctrl+e |
1805 |
| - term.echo = not term.echo |
1806 |
| - elif c == '\x08': # ctrl+e |
1807 |
| - print term.get_help_text() |
1808 |
| - elif c == '\t': # tab/ctrl+i |
1809 |
| - term.dump_port_settings() |
1810 |
| - else: |
1811 |
| - text = c |
1812 |
| - for transformation in term.tx_transformations: |
1813 |
| - text = transformation.tx(text) |
1814 |
| - term.serial.write(term.tx_encoder.encode(text)) |
1815 |
| - if term.echo: |
1816 |
| - echo_text = c |
1817 |
| - for transformation in term.tx_transformations: |
1818 |
| - echo_text = transformation.echo(echo_text) |
1819 |
| - term.console.write(echo_text) |
1820 |
| - term.writer = cli_writer |
1821 |
| - action('--- Terminal on {p.name} - {p.baudrate},{p.bytesize},{p.parity},{p.stopbits} ---\n'.format(p=term.serial)) |
1822 |
| - action('--- Quit: CTRL+C | Reset: CTRL+B | Echo: CTRL+E ---') |
1823 |
| - action('--- Info: TAB | Help: Ctrl+H | Menu: Ctrl+T ---') |
1824 |
| - term.start() |
1825 |
| - try: |
1826 |
| - term.join(True) |
1827 |
| - except KeyboardInterrupt: |
1828 |
| - pass |
1829 |
| - term.join() |
1830 |
| - term.close() |
1831 |
| - |
1832 |
| - result = False |
1833 |
| - serial_port = get_instance(port, baudrate=baudrate, timeout=timeout) |
1834 |
| - if serial_port: |
1835 |
| - serial_port.reset_input_buffer() |
1836 |
| - if reset: |
1837 |
| - cdc_reset(serial_port) |
1838 |
| - result = True |
1839 |
| - |
1840 |
| - if sterm: |
1841 |
| - if not serial_port.is_open: |
1842 |
| - serial_port = get_instance(port, baudrate=baudrate, timeout=timeout) |
1843 |
| - try: |
1844 |
| - cdc_term(serial_port) |
1845 |
| - result = True |
1846 |
| - except: |
1847 |
| - pass |
1848 |
| - |
1849 |
| - return result |
1850 |
| - |
1851 |
| - |
1852 | 1756 | # Subparser handling
|
1853 | 1757 | parser = argparse.ArgumentParser(prog='mbed',
|
1854 | 1758 | description="Command-line code management tool for ARM mbed OS - http://www.mbed.com\nversion %s\n\nUse 'mbed <command> -h|--help' for detailed help.\nOnline manual and guide available at https://github.com/ARMmbed/mbed-cli" % ver,
|
@@ -2566,7 +2470,7 @@ def compile_(toolchain=None, target=None, profile=False, compile_library=False,
|
2566 | 2470 | error("Unable to flash the target board connected to your system.", 1)
|
2567 | 2471 |
|
2568 | 2472 | if flash or sterm:
|
2569 |
| - if not cdc(detected['port'], reset=flash, sterm=sterm): |
| 2473 | + if not mbed_cdc(detected['port'], reset=flash, sterm=sterm): |
2570 | 2474 | error("Unable to reset the target board connected to your system.\nThis might be caused by an old interface firmware.\nPlease check the board page for new firmware.", 1)
|
2571 | 2475 |
|
2572 | 2476 | program.set_defaults(target=target, toolchain=tchain)
|
@@ -2774,7 +2678,7 @@ def detect(reset=False, sterm=False):
|
2774 | 2678 | action("Detected unknown target connected to \"%s\" and using com port \"%s\"" % (target['mount'], target['serial']))
|
2775 | 2679 | else:
|
2776 | 2680 | action("Detected \"%s\" connected to \"%s\" and using com port \"%s\"" % (target['name'], target['mount'], target['serial']))
|
2777 |
| - cdc(target['serial'], reset=reset, sterm=sterm) |
| 2681 | + mbed_cdc(target['serial'], reset=reset, sterm=sterm) |
2778 | 2682 |
|
2779 | 2683 | if unknown_found:
|
2780 | 2684 | warning("If you're developing a new target, you can mock the device to continue your development. "
|
|
0 commit comments