Skip to content

Commit 28892fd

Browse files
committed
Merge branch 'svm4x_2.0.3_20231114_0935' into 'master'
Update SVM4x driver from SVM4X model version 2.0.3 See merge request MSO-SW/drivers/raspberry-pi/raspberry-pi-uart-svm4x!12
2 parents 0384f29 + dc95034 commit 28892fd

24 files changed

+1564
-1328
lines changed

.gitignore

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
/svm41_uart_example_usage
2-
/tests/svm41-test-uart
3-
/.idea
1+
/example-usage/svm4x_uart_example_usage
2+
/algorithm-tuning-example/svm4x_uart_algorithm_tunign_example

.gitlab-ci.yml

+57-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,60 @@
11
stages:
22
- validate
33
- build
4+
5+
6+
variables:
7+
YQ_URL: https://github.com/mikefarah/yq/releases/download/v4.33.3/yq_linux_amd64
8+
9+
metadata_check:
10+
stage: validate
11+
image:
12+
name: registry.gitlab.sensirion.lokal/mso-sw/drivers/docker-driver-generator:0.2.0
13+
tags: [linux, docker]
14+
before_script:
15+
- apt-get -qq update && apt-get -qq install -y wget
16+
- if ! [ -d downloads/ ]; then mkdir downloads; fi
17+
- if ! [ -e downloads/yq ]; then wget --no-verbose $YQ_URL -O downloads/yq; fi
18+
- cp downloads/yq /usr/local/bin/yq && chmod +x /usr/local/bin/yq
19+
script:
20+
# check if metadata.yml exists
21+
- >
22+
if ! [ -f "metadata.yml" ]; then
23+
echo "metadata.yml file not found"
24+
exit 1
25+
fi
26+
# check that dg_status is 'released'
27+
- export DG_STATUS=$(yq ".dg_status.[]" ./metadata.yml)
28+
- >
29+
if [ $DG_STATUS != "released" ]; then
30+
echo "dg_status in metadata.yml has to be 'released', not '$DG_STATUS'"
31+
exit 1
32+
fi
33+
# check that last_generated is not older than timestamp of last non-merge commit (+ 3 minutes)
34+
- export IS_MANUALLY_MODIFIED=$(yq ".is_manually_modified" ./metadata.yml)
35+
- >
36+
if [ $IS_MANUALLY_MODIFIED = false ]; then
37+
export LAST_GENERATED_TS=$(yq ".last_generated" ./metadata.yml)
38+
export LAST_GENERATED_TS_EPOCH=$(date -d "$LAST_GENERATED_TS" +%s)
39+
export LAST_NON_MERGE_COMMIT_TS=$(git log --format=%ad --date=iso-strict --no-merges -1)
40+
export COMMIT_TS_EPOCH=$(date -d "$LAST_NON_MERGE_COMMIT_TS" +%s)
41+
if [ $(($LAST_GENERATED_TS_EPOCH + 180)) -lt $COMMIT_TS_EPOCH ]; then
42+
echo "'last_generated' timestamp in metadata.yml is older than commit timestamp ($LAST_GENERATED_TS vs $LAST_NON_MERGE_COMMIT_TS)"
43+
exit 1
44+
fi
45+
fi
46+
# check that 'is_manually_modified' is set to true if commit is not from driver generator
47+
- export LAST_NON_MERGE_COMMIT_AUTHOR=$(git log --format=%an --no-merges -1)
48+
- >
49+
if ! [ "$LAST_NON_MERGE_COMMIT_AUTHOR" = "Driver Generator 2" ] && [ "$IS_MANUALLY_MODIFIED" = false ]; then
50+
echo "Last commit is not from Driver Generator. Please update 'is_manually_modified' in metadata.yml"
51+
exit 1
52+
fi
453
554
syntax_check:
655
stage: validate
756
image:
8-
name: registry.gitlab.sensirion.lokal/mso-sw/drivers/docker-driver-generator:0.1.0
57+
name: registry.gitlab.sensirion.lokal/mso-sw/drivers/docker-driver-generator:0.2.0
958
tags: [linux, docker]
1059
script:
1160
- find . -type f -iregex ".*\.\(c\|h\|cpp\|ino\)" -exec clang-format-6.0 -i -style=file {} \; && git diff --exit-code
@@ -14,23 +63,26 @@ syntax_check:
1463
cppcheck:
1564
stage: validate
1665
image:
17-
name: registry.gitlab.sensirion.lokal/mso-sw/drivers/docker-driver-generator:0.1.0
66+
name: registry.gitlab.sensirion.lokal/mso-sw/drivers/docker-driver-generator:0.2.0
1867
tags: [linux, docker]
1968
script:
20-
- cppcheck --std=c89 --language=c --error-exitcode=1 --enable=warning,style,performance,portability -i sample-implementations/ .
69+
- cppcheck --std=c89 --language=c --error-exitcode=1 --enable=warning,style,performance,portability --suppress=unreadVariable -i sample-implementations/ .
2170

2271
build:
2372
stage: build
2473
image:
2574
name: sensirion/embedded-ci:2.4.0
2675
tags: [linux, docker]
2776
script:
77+
- cd example-usage
2878
- make
2979

80+
81+
3082
TODO_check:
3183
stage: validate
3284
image:
33-
name: registry.gitlab.sensirion.lokal/mso-sw/drivers/docker-driver-generator:0.1.0
85+
name: registry.gitlab.sensirion.lokal/mso-sw/drivers/docker-driver-generator:0.2.0
3486
tags: [linux, docker]
3587
script:
36-
- '! grep -rnw --exclude=.gitlab-ci.yml --exclude-dir=.git . -e "TODO: DRIVER_GENERATOR"'
88+
- '! grep -rnw --exclude=.gitlab-ci.yml --exclude=sensirion_uart_hal.c --exclude-dir=.git --exclude-dir=sample-implementations . -e "TODO"'

CHANGELOG.md

+9-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [Unreleased]
8+
9+
#### CHANGED
10+
11+
- svm41_uart.h/c changed to svm4x_uart.h/c and method prefix changed also from svm41_ to svm4x_
12+
713
## [0.2.0] - 2022-08-15
814

915
- Change interface for `sensirion_uart_hal_init` in `sensirion_uart_hal` to allow passing
@@ -21,5 +27,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2127

2228
Initial release
2329

24-
[0.1.0]: https://github.com/Sensirion/raspberry-pi-uart-svm41/releases/tag/0.1.0
25-
30+
[unreleased]: https://github.com/Sensirion/raspberry-pi-uart-svm41/compare/0.2.0...HEAD
31+
[0.2.0]: https://github.com/Sensirion/raspberry-pi-uart-svm41/compare/0.1.0...0.2.0
32+
[0.1.0]: https://github.com/Sensirion/raspberry-pi-uart-svm41/releases/tag/0.1.0

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
BSD 3-Clause License
22

3-
Copyright (c) 2021, Sensirion AG
3+
Copyright (c) 2023, Sensirion AG
44
All rights reserved.
55

66
Redistribution and use in source and binary forms, with or without

Makefile

-22
This file was deleted.

README.md

+73-41
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
# Sensirion Raspberry Pi UART SVM4x Driver
1+
# Sensirion Raspberry Pi UART SVM4X Driver
22

3-
This document explains how to set up a SVM4x evaluation kit to run on a Raspberry Pi using the provided code.
3+
The repository provides a driver for setting up a SVM4X evaluation kit to run on a Raspberry Pi over UART using the SHDLC protocol.
4+
5+
<img src="images/svm4x.png" width="300px">
6+
7+
Click [here](https://www.sensirion.com/my-sgp-ek/) to learn more about the Sensirion SVM4X evaluation kit.
48

5-
<img src="images/SVM41.png" width="400px">
69

7-
Click [here](https://sensirion.com/my-sgp-ek) to learn more about the Sensirion SVM4x evalutaion kit.
810
The SVM4x evaluation kit covers evaluation of the SGP40 and SGP41 sensors.
11+
This driver supports SVM4x firmware version 3.1.0 and above.
912

1013

1114
## Connect the sensor
@@ -20,73 +23,102 @@ Plug the provided USB cable into your Raspberry Pi and sensor.
2023
<details><summary>Connecting the Sensor over UART Pins</summary>
2124
<p>
2225

23-
Use the following pins to connect your SVM4x to your Raspberry Pi:
26+
Use the following pins to connect your SVM4X to your Raspberry Pi:
2427

25-
<img src="images/SVM41-Pinout-UART.png" width="400px">
28+
<img src="images/svm41-pinout-uart.png" width="300px">
2629

27-
| *Pin SVM4x* | *Cable Color* | *Name* | *Pin Raspberry Pi* | *Description* |*Description* |
28-
|-------------|---------------|--------|--------------------|---------------|---------------|
29-
| 1 | red |VDD |Pin 2 (VDD)| Supply Voltage | 3.3 or 5V |
30-
| 2 | black |GND |Pin 6 (GND) | Ground | |
31-
| 3 | green |RX | Pin 8 (TXD) | UART communication | |
32-
| 4 | yellow |TX | Pin 10 (RXD) | UART communication | |
33-
| 5 | blue |SEL | Pin 4 (VDD) | Interface select | Leave floating or pull to VDD to select UART |
34-
| 6 | purple |NC | - | Do not connect |
30+
| *Pin SVM4X* | *Cable Color* | *Name* | *Pin Raspberry Pi* | *Description* | *Comments* |
31+
|---|---|:---:|---|---|---|
32+
| 1 | red | VDD | Pin 2 | Supply Voltage | 3.3 or 5V |
33+
| 2 | black | GND | Pin 6 | Ground | |
34+
| 3 | green | RX | Pin 8 | UART: Transmission pin for communication | |
35+
| 4 | yellow | TX | Pin 10 | UART: Receiving pin for communication | |
36+
| 5 | blue | SEL | Pin 4 | Interface select | Leave floating or pull to VDD to select UART |
3537

36-
<img src="images/raspi-pinout-uart-5V.png" width="700px">
38+
<img src="images/raspi-uart-pinout-5V.png" width="400px">
3739

3840
> **Note:** Make sure to [configure your hardware serial interface](https://www.raspberrypi.com/documentation/computers/configuration.html#disabling-the-linux-serial-console) on your Raspberry Pi.
3941
4042
> **Note:** Make sure to connect serial pins as cross-over (RX pin of sensor -> TX on Raspberry Pi; TX pin of sensor -> RX pin of Raspberry Pi)
4143
42-
4344
</p></details>
4445

4546
## Quick start example
4647

4748
- [Install the Raspberry Pi OS on to your Raspberry Pi](https://projects.raspberrypi.org/en/projects/raspberry-pi-setting-up)
48-
- Connect the SVM4x sensor as explained in the [section above](#connect-the-sensor)
49-
- Download the SVM4x driver from [Github](https://github.com/Sensirion/raspberry-pi-uart-svm4x) and extract the `.zip`
49+
- Download the SVM4X driver from [Github](https://github.com/Sensirion/raspberry-pi-uart-svm4x) and extract the `.zip`
5050
on your Raspberry Pi
51-
- Compile the driver
52-
1. Open a [terminal](https://projects.raspberrypi.org/en/projects/raspberry-pi-using/8)
53-
2. Navigate to the driver directory. E.g. `cd ~/raspberry-pi-uart-svm4x`
54-
3. Check that the correct serial port is set in the define in `svm41_uart_example_usage.c`
55-
1. For connection over USB use (in case you have other devices connected check the USB number) `#define SENSIRION_UART_TTYDEV "/dev/ttyUSB0"`
56-
2. For connection over UART Pins use `#define SENSIRION_UART_TTYDEV "/dev/serial0"`
57-
4. Run the `make` command to compile the driver
58-
59-
Output:
60-
```
61-
rm -f svm41_uart_example_usage
62-
cc -Os -Wall -fstrict-aliasing -Wstrict-aliasing=1 -Wsign-conversion -fPIC -I. -o svm41_uart_example_usage svm41_uart.h svm41_uart.c sensirion_uart_hal.h sensirion_shdlc.h sensirion_shdlc.c \
63-
sensirion_uart_hal.c sensirion_config.h sensirion_common.h sensirion_common.c svm41_uart_example_usage.c
64-
65-
```
51+
- Connect the SVM4X sensor as explained in the [section above](#connect-the-sensor)
52+
- Check that the correct serial port is set in the define in `sensirion_uart_portdescriptor.h`
53+
- For connection over USB (in case you have other devices connected check the USB number)
54+
55+
`#define SERIAL_0 "/dev/ttyUSB0"`
56+
57+
- For connection over UART Pins
58+
59+
`#define SERIAL_0 "/dev/serial0"`
60+
61+
- Compile the driver
62+
1. Open a [terminal](https://projects.raspberrypi.org/en/projects/raspberry-pi-using/8)
63+
2. Navigate to the driver directory. E.g. `cd ~/raspberry-pi-uart-svm4x`
64+
3. Navigate to the subdirectory example-usage.
65+
4. Run the `make` command to compile the driver
66+
67+
Output:
68+
```
69+
rm -f svm4x_uart_example_usage
70+
cc -Os -Wall -fstrict-aliasing -Wstrict-aliasing=1 -Wsign-conversion -fPIC -I. -o svm4x_uart_example_usage svm4x_uart.h svm4x_uart.c sensirion_uart_hal.h sensirion_shdlc.h sensirion_shdlc.c \
71+
sensirion_uart_hal.c sensirion_config.h sensirion_common.h sensirion_common.c svm4x_uart_example_usage.c
72+
```
6673
- Test your connected sensor
67-
- Run `./svm41_uart_example_usage` in the same directory you used to compile the driver. You should see the
74+
- Run `./svm4x_uart_example_usage` in the same directory you used to compile the driver. You should see the
6875
measurement values in the console.
6976
77+
## Troubleshooting
78+
79+
### Building driver failed
80+
81+
If the execution of `make` in the compilation step 3 fails with something like
82+
83+
```bash
84+
make: command not found
85+
```
86+
87+
your RaspberryPi likely does not have the build tools installed. Proceed as follows:
88+
89+
```
90+
$ sudo apt-get update
91+
$ sudo apt-get upgrade
92+
$ sudo apt-get install build-essential
93+
```
94+
95+
96+
7097
## Contributing
7198

7299
**Contributions are welcome!**
73100

74-
We develop and test this driver using our company internal tools (version control, continuous integration, code review
75-
etc.) and automatically synchronize the master branch with GitHub. But this doesn't mean that we don't respond to issues
76-
or don't accept pull requests on GitHub. In fact, you're very welcome to open issues or create pull requests :)
101+
We develop and test this driver using our company internal tools (version
102+
control, continuous integration, code review etc.) and automatically
103+
synchronize the master branch with GitHub. But this doesn't mean that we don't
104+
respond to issues or don't accept pull requests on GitHub. In fact, you're very
105+
welcome to open issues or create pull requests :)
77106

78107
This Sensirion library uses
79-
[`clang-format`](https://releases.llvm.org/download.html) to standardize the formatting of all our `.c` and `.h` files.
80-
Make sure your contributions are formatted accordingly:
108+
[`clang-format`](https://releases.llvm.org/download.html) to standardize the
109+
formatting of all our `.c` and `.h` files. Make sure your contributions are
110+
formatted accordingly:
81111

82112
The `-i` flag will apply the format changes to the files listed.
83113

84114
```bash
85115
clang-format -i *.c *.h
86116
```
87117

88-
Note that differences from this formatting will result in a failed build until they are fixed.
118+
Note that differences from this formatting will result in a failed build until
119+
they are fixed.
120+
89121

90122
## License
91123

92-
See [LICENSE](LICENSE).
124+
See [LICENSE](LICENSE).

algorithm-tuning-example/Makefile

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
src_dir = ..
2+
common_sources = ${src_dir}/sensirion_config.h ${src_dir}/sensirion_common.h ${src_dir}/sensirion_common.c
3+
uart_sources = ${src_dir}/sensirion_uart_hal.h ${src_dir}/sensirion_shdlc.h ${src_dir}/sensirion_shdlc.c
4+
driver_sources = ${src_dir}/svm4x_uart.h ${src_dir}/svm4x_uart.c
5+
6+
uart_implementation ?= ${src_dir}/sensirion_uart_hal.c
7+
8+
CFLAGS = -Os -Wall -fstrict-aliasing -Wstrict-aliasing=1 -Wsign-conversion -fPIC -I${src_dir} -I.
9+
10+
ifdef CI
11+
CFLAGS += -Werror
12+
endif
13+
14+
.PHONY: all clean
15+
16+
all: svm4x_uart_algorithm_tuning_example
17+
18+
svm4x_uart_algorithm_tuning_example: clean
19+
$(CC) $(CFLAGS) -o $@ ${driver_sources} ${uart_sources} \
20+
${uart_implementation} ${common_sources} svm4x_uart_algorithm_tuning_example.c
21+
22+
clean:
23+
$(RM) svm4x_uart_algorithm_tuning_example

0 commit comments

Comments
 (0)