GithubHelp home page GithubHelp logo

aequitasetveritas / bluepill-serial-monster Goto Github PK

View Code? Open in Web Editor NEW

This project forked from r2axz/bluepill-serial-monster

0.0 1.0 0.0 277 KB

USB to 3 Port Serial (UART) adapter firmware for STM32 Blue Pill.

License: MIT License

Makefile 1.74% C 98.26%

bluepill-serial-monster's Introduction

bluepill-serial-monster

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.

Features

  • 3 independent UART ports;
  • Hardware flow control (RTS/CTS) support1;
  • DSR/DTR/DCD/RI signals support;
  • 7 or 8 bit word length;
  • None, even, odd parity;
  • 1, 1.5, and 2 stop bits;
  • Works with CDC Class drives on Linux, OS X, and Windows;
  • Supports all baud rates up to 2 MBaud;
  • TXA signal for controlling RS-485 transceivers (DE, /RE);
  • DMA RX/TX for high-speed communications;
  • IDLE line detection for short response time;
  • Signed INF driver for Windows XP, 7, and 8;
  • Built-in command shell for device parameters configuration;
  • No external dependencies other than CMSIS;

(1) UART1 does not support CTS because it is occupied by USB (PA11) and cannot be remapped. RTS can still be used.

Donations

If this project helped you with whatever you use it for or you just want to say thanks, you can buy me a coffee :)

"Buy Me A Coffee"

UART Signal Levels

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.

UART Pinout

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.

Control Signals (Default Configuration)

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.

Advanced Configuration

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:

>help

To get command-specific help, type:

>help command-name

UART Port Parameters

UART port parameters can be viewed and set with the uart command:

>help uart
uart: set and view UART parameters
Usage: uart port-number|all show|signal-name-1 param-1 value-1 ... [param-n value-n] [signal-name-2 ...]
Use "uart port-number|all show" to view current UART configuration.
Use "uart port-number|all signal-name-1 param-1 value-1 ... [param-n value-n] [signal-name-2 ...]"
to set UART parameters, where signal names are rx, tx, rts, cts, dsr, dtr, dcd,
and params are:
  output        [pp|od]
  active        [low|high]
  pull          [floating|up|down]
Example: "uart 1 tx output od" sets UART1 TX output type to open-drain
Example: "uart 3 rts active high dcd active high pull down" allows to set multiple parameters at once.

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 save

To view current configuration of all UART ports, type:

>uart all show

To view current configuration of a particular UART port, type:

>uart port-number show

where port-number is in range of 1 to 3.

Output type can be set for any output signal. Available output types are:

  • pp for push-pull output;
  • od for open-drain output;

Example:

uart 1 tx output od

Pull type can be set for any input signal. Available pull types are:

  • floating for floating input;
  • up for weak pull up;
  • down for weak pull down;

Example:

uart 1 dcd pull up

Signal polarity can be set for all input and output signals except for RX, TX, and CTS. Available signal polarities are:

  • low for active-low signal polarity;
  • high for active-high signal polarity;

Example:

uart 1 rts active high

It is possible to set multiple signal parameters for multiple signals in one command:

uart 1 tx output od rts output od active high

If 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 od

Saving and Resetting Configuration

To permanently save current device configuration, type:

config save

To reset the device to the default settings, type:

config reset

The default configuration is automatically stored in the flash memory after reset.

Flashing Firmware

Download binary firmware from the Releases page.

Flash with ST-LINK or similar programmer.

st-flash --format ihex write bluepill-serial-monster.hex

You can also flash STM32F103C8T6 via a built-in serial bootloader. Visit https://www.st.com/en/development-tools/flasher-stm32.html for instructions and software.

Windows Driver (WinXP, 7, 8)

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-monster.cat files during a new device installation.

Alternatively, you can open Windows Device Manager, right-click on any of the Bluepill Serial Monster devices, choose Update driver and point Windows to the INF file directory from there.

Fixing USB on Blue Pill Boards

STM32 Blue Pill boards come in slightly different variations. Nevertheless, their schematic is very similar. Below you will find the instructions on how to identify and replace the incorrect USB pull-up resistor on any Blue Pill board.

With a digital multimeter, measure resistance between PA12 and 3.3 V pads on the board. If the resistance reads close to 1.5k (1500 ohms), then your board is either non-faulty or faulty for some other reason, and this section does not apply.

If the resistance if far away from 1.5k (such as 4.7k or 10k), you will have to locate the incorrect resistor on the board and replace it with a 1.5k or 1.8k resistor.

If your board has component names on it, locate R10. Otherwise, trace the board to find the incorrect resistor.

Once you identified the incorrect resistor, replace it with a 1.5k or 1.8k resistor.

Building Firmware

Prerequisites

Install the following software:

Here is an example assuming everything is installed in ~/stm32/, and we use bash:

ARM toolchain and st-link must be added to PATH.

# add ARM toolchain path
export PATH=~/stm32/gcc-arm-none-eabi/bin:$PATH
# add stlink path
export PATH=~/stm32/stlink-install/bin:$PATH

Path to STM32CubeF1 should be also exported (use ~/.bash_profile):

# export STM32Cube
export STM32CUBE_PATH=~/stm32/stm32cube

Building

To build the firmware, cd to the project directory and run

make

To flash the MCU using st-link, run

make flash

To remove object and dependency files, run

make clean

To remove object, dependency, and firmware files, run

make distclean

bluepill-serial-monster's People

Contributors

cyrozap avatar r2axz avatar vnodeng avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.