Skip to content

Commit

Permalink
Add spl-uart-printf-simple example, refactor old one (#47)
Browse files Browse the repository at this point in the history
This renames the old exapmle to spl-uart-loopback and adds a new,
simple UART printf() example which works for all supported STM8 boards.

The old "spl-uart" example was a rather complex UART1 to UART3
loopback and buffer check firmware, that also doesn't compile for the
boards that do not have a UART1 peripheral.
  • Loading branch information
maxgerhardt authored Mar 25, 2021
1 parent bef5278 commit 76068b4
Show file tree
Hide file tree
Showing 25 changed files with 1,229 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ jobs:
- "examples/arduino-ping-hc04"
- "examples/spl-blink"
- "examples/spl-flash"
- "examples/spl-uart"
- "examples/spl-uart-loopback"
- "examples/spl-uart-simple-printf"
- "examples/native-blink"
runs-on: ${{ matrix.os }}
steps:
Expand Down
3 changes: 2 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ environment:
- PLATFORMIO_PROJECT_DIR: "examples/arduino-ping-hc04"
- PLATFORMIO_PROJECT_DIR: "examples/spl-blink"
- PLATFORMIO_PROJECT_DIR: "examples/spl-flash"
- PLATFORMIO_PROJECT_DIR: "examples/spl-uart"
- PLATFORMIO_PROJECT_DIR: "examples/spl-uart-loopback"
- PLATFORMIO_PROJECT_DIR: "examples/spl-uart-simple-printf"
- PLATFORMIO_PROJECT_DIR: "examples/native-blink"

install:
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ How to build PlatformIO based project
.. code-block:: bash
# Change directory to example
> cd platform-ststm8/examples/spl-uart
> cd platform-ststm8/examples/spl-uart-loopback
# Build project
> platformio run
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions examples/spl-uart-simple-printf/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.pio
.vscode
38 changes: 38 additions & 0 deletions examples/spl-uart-simple-printf/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
.. Copyright 2018-present PlatformIO <[email protected]>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
How to build PlatformIO based project
=====================================

1. `Install PlatformIO Core <http://docs.platformio.org/page/core.html>`_
2. Download `development platform with examples <https://github.com/platformio/platform-ststm8/archive/develop.zip>`_
3. Extract ZIP archive
4. Run these commands:

.. code-block:: bash
# Change directory to example
> cd platform-ststm8/examples/spl-uart-simple-printf
# Build project
> platformio run
# Upload firmware
> platformio run --target upload
# Build specific environment
> platformio run -e stm8sdisco
# Upload firmware for the specific environment
> platformio run -e stm8sdisco --target upload
# Clean build files
> platformio run --target clean
39 changes: 39 additions & 0 deletions examples/spl-uart-simple-printf/include/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

This directory is intended for project header files.

A header file is a file containing C declarations and macro definitions
to be shared between several project source files. You request the use of a
header file in your project source file (C, C++, etc) located in `src` folder
by including it, with the C preprocessing directive `#include'.

```src/main.c

#include "header.h"

int main (void)
{
...
}
```

Including a header file produces the same results as copying the header file
into each source file that needs it. Such copying would be time-consuming
and error-prone. With a header file, the related declarations appear
in only one place. If they need to be changed, they can be changed in one
place, and programs that include the header file will automatically use the
new version when next recompiled. The header file eliminates the labor of
finding and changing all the copies as well as the risk that a failure to
find one copy will result in inconsistencies within a program.

In C, the usual convention is to give header files names that end with `.h'.
It is most portable to use only letters, digits, dashes, and underscores in
header file names, and at most one dot.

Read more about using header files in official GCC documentation:

* Include Syntax
* Include Operation
* Once-Only Headers
* Computed Includes

https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
46 changes: 46 additions & 0 deletions examples/spl-uart-simple-printf/lib/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

This directory is intended for project specific (private) libraries.
PlatformIO will compile them to static libraries and link into executable file.

The source code of each library should be placed in a an own separate directory
("lib/your_library_name/[here are source files]").

For example, see a structure of the following two libraries `Foo` and `Bar`:

|--lib
| |
| |--Bar
| | |--docs
| | |--examples
| | |--src
| | |- Bar.c
| | |- Bar.h
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
| |
| |--Foo
| | |- Foo.c
| | |- Foo.h
| |
| |- README --> THIS FILE
|
|- platformio.ini
|--src
|- main.c

and a contents of `src/main.c`:
```
#include <Foo.h>
#include <Bar.h>

int main (void)
{
...
}

```

PlatformIO Library Dependency Finder will find automatically dependent
libraries scanning project source files.

More information about PlatformIO Library Dependency Finder
- https://docs.platformio.org/page/librarymanager/ldf.html
45 changes: 45 additions & 0 deletions examples/spl-uart-simple-printf/platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env:stm8sblue]
platform = ststm8
board = stm8sblue
framework = spl
upload_protocol = stlinkv2

[env:mb208]
platform = ststm8
board = mb208
framework = spl

[env:nucleo_8s207k8]
platform = ststm8
board = nucleo_8s207k8
framework = spl

[env:s8uno]
platform = ststm8
board = s8uno
framework = spl

[env:stm8s003f3]
platform = ststm8
board = stm8s003f3
framework = spl

[env:stm8sblack]
platform = ststm8
board = stm8sblack
framework = spl

[env:stm8sdisco]
platform = ststm8
board = stm8sdisco
framework = spl
Loading

0 comments on commit 76068b4

Please sign in to comment.