Skip to content

Commit

Permalink
Merge pull request #9 from r2axz/r2axz-config-interface
Browse files Browse the repository at this point in the history
Implement UART Configuration Interface
  • Loading branch information
r2axz authored Nov 25, 2020
2 parents b280bc5 + 2846292 commit c299798
Show file tree
Hide file tree
Showing 12 changed files with 1,302 additions and 102 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# General Target Settings
TARGET = bluepill-serial-monster
SRCS = main.c system_clock.c status_led.c usb_core.c usb_descriptors.c usb_io.c usb_uid.c usb_panic.c usb_cdc.c
SRCS = main.c system_clock.c status_led.c usb_core.c usb_descriptors.c\
usb_io.c usb_uid.c usb_panic.c usb_cdc.c cdc_shell.c gpio.c device_config.c

# Toolchain & Utils
CC = arm-none-eabi-gcc
Expand Down
148 changes: 147 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ board works with your computer, don't bother fixing it.
* _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 hardware flow control because _RTS_/_CTS_ pins
Expand Down Expand Up @@ -68,7 +69,7 @@ or damage may occur.**

Note: **5 V** tolerant input pins are shown **in bold**.

## Control Signals
## Control Signals (Default Configuration)

**RTS**, **CTS**, **DSR**, **DTR**, **DCD** are **active-low** signals.

Expand All @@ -89,6 +90,151 @@ by the host. Please take this behaviour into account if you rely on the

_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 _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:

```text
*******************************
* 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:

```text
>help
```

To get command-specific help, type:

```text
>help command-name
```

### UART Port Parameters

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

```text
>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:

```text
>config save
```

To view current configuration of all UART ports, type:

```text
>uart all show
```

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

```text
>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:

```text
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:

```text
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:

```text
uart 1 rts active high
```

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

```text
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:

```text
uart all tx output od
```

### Saving and Resetting Configuration

To permanently save current device configuration, type:

```text
config save
```

To reset the device to the default settings, type:

```text
config reset
```

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

## Flashing Firmware

Download binary firmware from the
Expand Down
21 changes: 21 additions & 0 deletions cdc_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* MIT License
*
* Copyright (c) 2020 Kirill Kotyagin
*/

#ifndef CDC_CONFIG_H
#define CDC_CONFIG_H

#include "gpio.h"
#include "usb_cdc.h"

typedef struct {
gpio_pin_t pins[cdc_pin_last];
} __attribute__ ((packed)) cdc_port_t;

typedef struct {
cdc_port_t port_config[USB_CDC_NUM_PORTS];
} __attribute__ ((packed)) cdc_config_t;

#endif /* CDC_CONFIG_H */
Loading

0 comments on commit c299798

Please sign in to comment.