适用于 STM32 Blue Pill 的 USB 至 3 端口串行 (UART) 适配器固件。
bluepill-serial-monster is a firmware for STM32 Blue Pill that turns it into a 3 Port USB-to-Serial adapter. The firmware implements a USB 2.0 full-speed composite device that consists of 3 USB CDC devices.
STM32 Blue Pill is a ridiculously cheap STM32 development board which is available in many stores around the globe. The board contains decent hardware that supports USB 2.0 Full-Speed, has 3 independent USARTs and enough processing power to handle high-speed UART communications.
Note: some Blue Pill clones have an incorrect pull-up resistor soldered to the USB D+ line (PA12) which prevents them from being successfully detected by the host. Please refer to Fixing USB on Blue Pill Boards for more information.
Some USB controllers work fine even with faulty Blue Pill boards. If your board works with your computer, don't bother fixing it.
(1) UART1 does not support CTS because it is occupied by USB (PA11) and cannot be remapped. RTS can still be used.
If this project helped you with whatever you use it for or you just want to say thanks, you can buy me a coffee :)
Although STM32F103C8T6 installed on the Blue Pill board is a 3.3 V device, a number of its inputs are actually 5 V tolerant. This means you can safely use the selected inputs with 3.3 and 5 V TTL devices.
Do not use non 5 V tolerant inputs with 5 V devices as doing that will result in permanent damage of MCU inputs or MCU itself.
When configured as an output, none of the STM32F103C8T6 pins is 5 V tolerant. Make sure you don't accidentally get more than 4.0 V on such pin or damage may occur.
5 V tolerant pins are shown in bold in the next section.
| Signal | Direction | UART1 | UART2 | UART3 |
|---|---|---|---|---|
| RX | IN | PA10 | PA3 | PB11 |
| TX | OUT | PA9 | PA2 | PB10 |
| RTS | OUT | PA15 | PA1 | PB14 |
| CTS | IN | N/A | PA0 | PB13 |
| DSR | IN | PB7 | PB4 | PB6 |
| DTR | OUT | PA4 | PA5 | PA6 |
| DCD | IN | PB15 | PB8 | PB9 |
| RI | IN | PB3 | PB12 | PA8 |
| TXA | OUT | PB0 | PB1 | PA7 |
Note: 5 V tolerant input pins are shown in bold.
RTS, CTS, DSR, DTR, DCD, RI are active-low signals, TXA is an active-high signal.
TXA (TX Active) is active when UART is transmitting data and can be used to control DE and /RE pins of RS-485 transceivers.
TXA goes inactive within 0.6 us after the transmission is complete, which meets RS-485 and IO-link timing requirements at speeds up to 920 kBaud with almost double safety margin.
DSR, DTR, and DCD, RI are connected to the internal weak pull-up resistors, so they remain inactive at rest.
CTS is pulled down internally, which enables UART TX when nothing is connected to CTS. Hardware flow control is always on, but it does not get in the way of communications as long as nothing is connected to the flow control lines.
RTS can be controlled by the host, but as soon as the UART RX buffer is half-full, RTS is forced to the inactive state. As long as more than one half of the buffer space is available, RTS remains in the state set by the host. Please take this behaviour into account if you rely on the RTS signal to control non-standard periphery.
DSR, DCD, and RI are polled 50 times per second.
UART DMA RX/TX buffer size is 1024 bytes.
Unfortunately, operating systems ignore CDC port names reported by the firmware. Linux and macOS tend to assign device numbers incrementally so that UART1 gets the lowest and UART3 the highest /dev/ttyACM... (Linux) or /dev/tty.usbmodem... (macOS) numbers. On the other hand, Windows can get pretty creative when assigning COM port numbers to USB CDC devices.
To find out which physical UART corresponds to a particular COM port on Windows, open Device Manager, right click on the COM port under Ports (COM & LPT), and choose Properties. Open the Details tab and select the Bus reported device description property. The Value field will indicate the physical UART name.
All versions of Windows have a bug in the USB CDC system driver (usbser.sys) that affects RTS signal handling.
The driver does not send USB SET_CONTROL_LINE_STATE messages when the RTS state changes. However, on the DTR state change, the driver sends a SET_CONTROL_LINE_STATE message containing the updated states for both RTS and DTR signals.
It is unknown why usbser.sys does this, but the disassembled code of the driver suggests that sending SET_CONTROL_LINE_STATE on RTS change is simply left out by mistake. It looks like Microsoft is not going to fix this bug. However, it can be easily worked around.
The workaround for this bug is to update DTR (even to the same state) each time RTS needs to be updated as in the example below:
…Some existing software already does that. CwType, Win-Test, CoolTerm are the examples of such software. Others like N1MM Logger Plus or Termite do not implement the workaround.
The RTS issue does not affect Linux or macOS.
Linux terminal subsystem echoes characters coming from a
bluepill-serial-monster port back to this port until it is switched to
the raw more (see man 3 cfmakeraw).
This behaviour is Linux-specific and is not related to bluepill-serial-monster itself. See this Stack Overflow post for details.
Usually, this is not an issue; however, it may lead to garbage characters appearing when the configuration shell is started. For instance, if PA5 is tied to the ground when bluepill-serial-monster is plugged in, the device sends the configuration mode banner to the host. The host echoes the content of the banner back to the device, which in turn tries to parse it as if it was a sequence of configuration shell commands. When screen or another terminal emulation software is started, its output may contain garbage characters left due to the above exchange.
bluepill-serial-monster provides a configuration shell that allows controlling various parameters of the UART signal lines.
To access the configuration shell, open the first USB serial port (UART1) with any terminal emulator application (such as screen, Tera Term, etc.) and connect PB5 to ground. Serial port settings do not matter.
You should see the configuration shell prompt:
*******************************
* Configuration Shell Started *
*******************************
>The configuration shell has minimal support for ANSI escape sequences. You can use the arrow keys to move the cursor when editing a command, erase text with Backspace, and insert text anywhere in the command. You can also recall the last command by pressing UP.
Command and parameter names are case-sensitive.
To get the list of available commands, type:
>helpTo get command-specific help, type:
>help command-nameUART port parameters can be viewed and set with the uart command:
…Changes to the UART parameters are applied instantly; however, the configuration is not stored in the flash memory until you explicitly save it with:
>config saveTo view current configuration of all UART ports, type:
>uart all showTo view current configuration of a particular UART port, type:
>uart port-number showwhere port-number is in range of 1 to 3.
Output type can be set for any output signal. Available output types are:
Example:
uart 1 tx output odPull type can be set for any input signal. Available pull types are:
Example:
uart 1 dcd pull upSignal polarity can be set for all input and output signals except for RX, TX, and CTS. Available signal polarities are:
Example:
uart 1 rts active highIt is possible to set multiple signal parameters for multiple signals in one command:
uart 1 tx output od rts output od active highIf the uart command encounters a syntax error or an invalid parameter in the middle of a multiple parameters command line, it stops execution immediately. However, it does not roll back valid parameters set before the point where the error occured.
It is also possible to set signal parameters for multiple ports in one command:
uart all tx output odTo permanently save current device configuration, type:
config saveTo reset the device to the default settings, type:
config resetTo print the firmware version, type:
versionThe default configuration is automatically stored in the flash memory after reset.
Download binary firmware from the Releases page.
Flash with ST-LINK or similar programmer.
st-flash --format ihex write bluepill-serial-monster.hexIt is also possible to flash STM32F103C8T6 via a built-in serial bootloader. Visit https://www.st.com/en/development-tools/flasher-stm32.html for instructions and software.
You can also use bluepill-serial-monster-stm32duino-0x8002000.bin or bluepill-serial-monster-stm32duino-0x8005000.bin with STM32duino-bootloader and dfu-util.
Windows versions prior to Windows 10 require an INF file that maps the device Vendor ID / Product ID to the Microsoft usbser.sys CDC ACM driver. Windows 10 does not require this and loads the standard driver automatically.
A signed INF file for Windows XP, 7, and 8 is included in the distribution. To install the INF file, plug in bluepill-serial-monster and point Windows to a directory containing both bluepill-serial-monster.inf and **bluepill-serial-mons
暂无开放 Issues,或尚未同步最近议题。