Skip to content

Commit

Permalink
Merge pull request #51 from r2axz/r2axz-add-device-version
Browse files Browse the repository at this point in the history
Add Device Version Reporting
  • Loading branch information
r2axz authored Feb 10, 2022
2 parents 4e8df8f + 6e63211 commit 7cea59a
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 4 deletions.
17 changes: 17 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,23 @@ ifneq ($(FIRMWARE_ORIGIN),)
LDFLAGS += -Wl,-section-start=.isr_vector=$(FIRMWARE_ORIGIN)
endif

GIT_VERSION := $(subst ., ,$(subst v,,$(shell git describe --abbrev=0 --tags 2>/dev/null || true)))

ifneq ($(GIT_VERSION),)
GIT_VERSION_MAJOR := $(word 1, $(GIT_VERSION))
ifneq ($(GIT_VERSION_MAJOR),)
CFLAGS += -DDEVICE_VERSION_MAJOR=$(GIT_VERSION_MAJOR)
endif
GIT_VERSION_MINOR := $(word 2, $(GIT_VERSION))
ifneq ($(GIT_VERSION_MINOR),)
CFLAGS += -DDEVICE_VERSION_MINOR=$(GIT_VERSION_MINOR)
endif
GIT_VERSION_REVISION := $(word 3, $(GIT_VERSION))
ifneq ($(GIT_VERSION_REVISION),)
CFLAGS += -DDEVICE_VERSION_REVISION=$(GIT_VERSION_REVISION)
endif
endif

.PHONY: all
all: $(TARGET).hex $(TARGET).bin size

Expand Down
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,6 @@ 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.



## Advanced Configuration

_bluepill-serial-monster_ provides a configuration shell that allows
Expand Down Expand Up @@ -339,6 +337,14 @@ To reset the device to the default settings, type:
config reset
```

### Printing the Firmware Version

To print the firmware version, type:

```text
version
```

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

## Flashing Firmware
Expand Down
16 changes: 15 additions & 1 deletion cdc_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "gpio.h"
#include "cdc_config.h"
#include "device_config.h"
#include "version.h"
#include "cdc_shell.h"


Expand Down Expand Up @@ -349,6 +350,13 @@ static void cdc_shell_cmd_config(int argc, char *argv[]) {
cdc_shell_write_string(cdc_shell_err_config_missing_arguments);
}

static const char cdc_shell_device_version[] = DEVICE_VERSION_STRING;

static void cdc_shell_cmd_version(int argc, char *argv[]) {
cdc_shell_write_string(cdc_shell_device_version);
cdc_shell_write_string(cdc_shell_new_line);
}

static void cdc_shell_cmd_help(int argc, char *argv[]);

static const cdc_shell_cmd_t cdc_shell_commands[] = {
Expand Down Expand Up @@ -379,7 +387,13 @@ static const cdc_shell_cmd_t cdc_shell_commands[] = {
" active\t[low|high]\r\n"
" pull\t\t[floating|up|down]\r\n"
"Example: \"uart 1 tx output od\" sets UART1 TX output type to open-drain\r\n"
"Example: \"uart 3 rts active high dcd active high pull down\" allows to set multiple parameters at once."
"Example: \"uart 3 rts active high dcd active high pull down\" allows to set multiple parameters at once.",
},
{
.cmd = "version",
.handler = cdc_shell_cmd_version,
.description = "print firmware version",
.usage = "Usage: version",
},
{ 0 }
};
Expand Down
3 changes: 2 additions & 1 deletion usb_descriptors.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "usb_core.h"
#include "usb_cdc.h"
#include "version.h"
#include "usb_descriptors.h"

#define USB_CONTROL_ENDPOINT_SIZE 16
Expand Down Expand Up @@ -95,7 +96,7 @@ const usb_device_descriptor_t usb_device_descriptor = {
.bMaxPacketSize = usb_endpoints[usb_endpoint_address_control].rx_size,
.idVendor = USB_ID_VENDOR,
.idProduct = USB_ID_PRODUCT,
.bcdDevice = USB_BCD_VERSION(1, 0, 0),
.bcdDevice = USB_BCD_VERSION(DEVICE_VERSION_MAJOR, DEVICE_VERSION_MINOR, DEVICE_VERSION_REVISION),
.iManufacturer = usb_string_index_manufacturer,
.iProduct = usb_string_index_product,
.iSerialNumber = usb_string_index_serial,
Expand Down
26 changes: 26 additions & 0 deletions version.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* MIT License
*
* Copyright (c) 2022 Kirill Kotyagin
*/

#ifndef VERSION_H
#define VERSION_H

#ifndef DEVICE_VERSION_MAJOR
#define DEVICE_VERSION_MAJOR 0
#endif

#ifndef DEVICE_VERSION_MINOR
#define DEVICE_VERSION_MINOR 0
#endif

#ifndef DEVICE_VERSION_REVISION
#define DEVICE_VERSION_REVISION 0
#endif

#define __DEVICE_VERSION_STRING(major,minor,revision) "v" #major "." #minor "." #revision
#define _DEVICE_VERSION_STRING(major,minor,revision) __DEVICE_VERSION_STRING(major,minor,revision)
#define DEVICE_VERSION_STRING _DEVICE_VERSION_STRING(DEVICE_VERSION_MAJOR,DEVICE_VERSION_MINOR,DEVICE_VERSION_REVISION)

#endif // VERSION_H

0 comments on commit 7cea59a

Please sign in to comment.