MacOS Big Sur 版本11.2.3 安装8266串口问题
我在网上找了很多教程,依然无法打开USB串口,路过的大神给个指点USB Serial:
产品ID: 0x7523厂商ID: 0x1a86版本: 2.64速度: 最高可达12 Mb/秒位置ID: 0x14200000 / 10可用电流(mA): 500所需电流(mA): 98额外的操作电流(mA): 0
jason-mac:~ oct$ ls /dev/tty*/dev/tty /dev/ttyse/dev/tty.Bluetooth-Incoming-Port /dev/ttysf/dev/tty.Little3-WirelessiAP /dev/ttyt0/dev/tty.usbserial-1420 /dev/ttyt1/dev/ttyp0 /dev/ttyt2/dev/ttyp1 /dev/ttyt3/dev/ttyp2 /dev/ttyt4/dev/ttyp3 /dev/ttyt5/dev/ttyp4 /dev/ttyt6/dev/ttyp5 /dev/ttyt7/dev/ttyp6 /dev/ttyt8/dev/ttyp7 /dev/ttyt9/dev/ttyp8 /dev/ttyta/dev/ttyp9 /dev/ttytb/dev/ttypa /dev/ttytc/dev/ttypb /dev/ttytd/dev/ttypc /dev/ttyte/dev/ttypd /dev/ttytf/dev/ttype /dev/ttyu0/dev/ttypf /dev/ttyu1/dev/ttyq0 /dev/ttyu2/dev/ttyq1 /dev/ttyu3/dev/ttyq2 /dev/ttyu4/dev/ttyq3 /dev/ttyu5/dev/ttyq4 /dev/ttyu6/dev/ttyq5 /dev/ttyu7/dev/ttyq6 /dev/ttyu8/dev/ttyq7 /dev/ttyu9/dev/ttyq8 /dev/ttyua/dev/ttyq9 /dev/ttyub/dev/ttyqa /dev/ttyuc/dev/ttyqb /dev/ttyud/dev/ttyqc /dev/ttyue/dev/ttyqd /dev/ttyuf/dev/ttyqe /dev/ttyv0/dev/ttyqf /dev/ttyv1/dev/ttyr0 /dev/ttyv2/dev/ttyr1 /dev/ttyv3/dev/ttyr2 /dev/ttyv4/dev/ttyr3 /dev/ttyv5/dev/ttyr4 /dev/ttyv6/dev/ttyr5 /dev/ttyv7/dev/ttyr6 /dev/ttyv8/dev/ttyr7 /dev/ttyv9/dev/ttyr8 /dev/ttyva/dev/ttyr9 /dev/ttyvb/dev/ttyra /dev/ttyvc/dev/ttyrb /dev/ttyvd/dev/ttyrc /dev/ttyve/dev/ttyrd /dev/ttyvf/dev/ttyre /dev/ttyw0/dev/ttyrf /dev/ttyw1/dev/ttys0 /dev/ttyw2/dev/ttys000 /dev/ttyw3/dev/ttys1 /dev/ttyw4/dev/ttys2 /dev/ttyw5/dev/ttys3 /dev/ttyw6/dev/ttys4 /dev/ttyw7/dev/ttys5 /dev/ttyw8/dev/ttys6 /dev/ttyw9/dev/ttys7 /dev/ttywa/dev/ttys8 /dev/ttywb/dev/ttys9 /dev/ttywc/dev/ttysa /dev/ttywd/dev/ttysb /dev/ttywe/dev/ttysc /dev/ttywf/dev/ttysdjason-mac:~ oct$
class ESPLoader(object):
""" Base class providing access to ESP ROM & software stub bootloaders.
Subclasses provide ESP8266 & ESP32 specific functionality.
Don't instantiate this base class directly, either instantiate a subclass or
call ESPLoader.detect_chip() which will interrogate the chip and return the
appropriate subclass instance.
"""
CHIP_NAME = "Espressif device"
IS_STUB = False
DEFAULT_PORT = "/dev/ttyUSB0"
# Commands supported by ESP8266 ROM bootloader
ESP_FLASH_BEGIN = 0x02
ESP_FLASH_DATA= 0x03
ESP_FLASH_END = 0x04
ESP_MEM_BEGIN = 0x05
ESP_MEM_END = 0x06
ESP_MEM_DATA = 0x07
ESP_SYNC = 0x08
ESP_WRITE_REG = 0x09
ESP_READ_REG = 0x0a
# Some comands supported by ESP32 ROM bootloader (or -8266 w/ stub)
ESP_SPI_SET_PARAMS = 0x0B
ESP_SPI_ATTACH = 0x0D
ESP_CHANGE_BAUDRATE = 0x0F
ESP_FLASH_DEFL_BEGIN = 0x10
ESP_FLASH_DEFL_DATA= 0x11
ESP_FLASH_DEFL_END = 0x12
ESP_SPI_FLASH_MD5 = 0x13
# Some commands supported by stub only
ESP_ERASE_FLASH = 0xD0
ESP_ERASE_REGION = 0xD1
ESP_READ_FLASH = 0xD2
ESP_RUN_USER_CODE = 0xD3
# Flash encryption debug more command
ESP_FLASH_ENCRYPT_DATA = 0xD4
# Maximum block sized for RAM and Flash writes, respectively.
ESP_RAM_BLOCK = 0x1800
FLASH_WRITE_SIZE = 0x400
# Default baudrate. The ROM auto-bauds, so we can use more or less whatever we want.
ESP_ROM_BAUD = 115200
# First byte of the application image
ESP_IMAGE_MAGIC = 0xe9
# Initial state for the checksum routine
ESP_CHECKSUM_MAGIC = 0xef
# Flash sector size, minimum unit of erase.
FLASH_SECTOR_SIZE = 0x1000
# This register happens to exist on both ESP8266 & ESP32
UART_DATA_REG_ADDR = 0x60000078
UART_CLKDIV_MASK = 0xFFFFF
# Memory addresses
IROM_MAP_START = 0x40200000
IROM_MAP_END = 0x40300000
# The number of bytes in the UART response that signify command status
STATUS_BYTES_LENGTH = 2
def __init__(self, port=DEFAULT_PORT, baud=ESP_ROM_BAUD, trace_enabled=False):
"""Base constructor for ESPLoader bootloader interaction
Don't call this constructor, either instantiate ESP8266ROM
or ESP32ROM, or use ESPLoader.detect_chip().
This base class has all of the instance methods for bootloader
functionality supported across various chips & stub
loaders. Subclasses replace the functions they don't support
with ones which throw NotImplementedInROMError().
"""
if isinstance(port, basestring):
self._port = serial.serial_for_url(port)
else:
self._port = port
self._slip_reader = slip_reader(self._port, self.trace)
# setting baud rate in a separate step is a workaround for
# CH341 driver on some Linux versions (this opens at 9600 then
# sets), shouldn't matter for other platforms/drivers. See
# https://github.com/espressif/esptool/issues/44#issuecomment-107094446
self._set_port_baudrate(baud)
self._trace_enabled = trace_enabled
# set write timeout, to prevent esptool blocked at write forever.
try:
self._port.write_timeout = DEFAULT_SERIAL_WRITE_TIMEOUT
except NotImplementedError:
# no write timeout for RFC2217 ports
# need to set the property back to None or it will continue to fail
self._port.write_timeout = None
def _set_port_baudrate(self, baud):
try:
self._port.baudrate = baud
except IOError:
raise FatalError("Failed to set baud rate %d. The driver may not support this rate." % baud)
@staticmethod
def detect_chip(port=DEFAULT_PORT, baud=ESP_ROM_BAUD, connect_mode='default_reset', trace_enabled=False):
""" Use serial access to detect the chip type.
We use the UART's datecode register for this, it's mapped at
the same address on ESP8266 & ESP32 so we can use one
memory read and compare to the datecode register for each chip
type.
This routine automatically performs ESPLoader.connect() (passing
connect_mode parameter) as part of querying the chip.
"""
detect_port = ESPLoader(port, baud, trace_enabled=trace_enabled)
detect_port.connect(connect_mode)
try:
print('Detecting chip type...', end='')
sys.stdout.flush()
date_reg = detect_port.read_reg(ESPLoader.UART_DATA_REG_ADDR)
for cls in :
if date_reg == cls.DATE_REG_VALUE:
# don't connect a second time
inst = cls(detect_port._port, baud, trace_enabled=trace_enabled)
print(' %s' % inst.CHIP_NAME, end='')
return inst
finally:
print('')# end line
raise FatalError("Unexpected UART datecode value 0x%08x. Failed to autodetect chip type." % date_reg)
""" Read a SLIP packet from the serial port """
def read(self):
return next(self._slip_reader)
""" Write bytes to the serial port while performing SLIP escaping """
def write(self, packet):
buf = b'\xc0' \
+ (packet.replace(b'\xdb',b'\xdb\xdd').replace(b'\xc0',b'\xdb\xdc')) \
+ b'\xc0'
self.trace("Write %d bytes: %s", len(buf), HexFormatter(buf))
self._port.write(buf)
def trace(self, message, *format_args):
if self._trace_enabled:
now = time.time()
try:
delta = now - self._last_trace
except AttributeError:
delta = 0.0
self._last_trace = now
prefix = "TRACE +%.3f " % delta
print(prefix + (message % format_args))
""" Calculate checksum of a blob, as it is defined by the ROM """
@staticmethod
def checksum(data, state=ESP_CHECKSUM_MAGIC):
for b in data:
if type(b) is int:# python 2/3 compat
state ^= b
else:
state ^= ord(b)
return state
""" Send a request and read the response """
def command(self, op=None, data=b"", chk=0, wait_response=True, timeout=DEFAULT_TIMEOUT):
saved_timeout = self._port.timeout
new_timeout = min(timeout, MAX_TIMEOUT)
if new_timeout != saved_timeout:
self._port.timeout = new_timeout
try:
if op is not None:
self.trace("command op=0x%02x data len=%s wait_response=%d timeout=%.3f data=%s",
op, len(data), 1 if wait_response else 0, timeout, HexFormatter(data))
pkt = struct.pack(b'<BBHI', 0x00, op, len(data), chk) + data
self.write(pkt)
if not wait_response:
return
# tries to get a response until that response has the
# same operation as the request or a retries limit has
# exceeded. This is needed for some esp8266s that
# reply with more sync responses than expected.
for retry in range(100):
p = self.read()
if len(p) < 8:
continue
(resp, op_ret, len_ret, val) = struct.unpack('<BBHI', p[:8])
if resp != 1:
continue
data = p
if op is None or op_ret == op:
return val, data
finally:
if new_timeout != saved_timeout:
self._port.timeout = saved_timeout
raise FatalError("Response doesn't match request")
页:
[1]