Skip to content

Commit

Permalink
v1.0 release.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ludovic-Lesur committed Jun 19, 2023
1 parent 1869a03 commit 53e181a
Show file tree
Hide file tree
Showing 12 changed files with 3,900 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build/
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [v1.0](https://github.com/sigfox-tech-radio/sigfox-ep-rf-api-st-s2lp/releases/tag/v1.0) - 19 Jun 2023

### General

* First version of the S2LP RF API implementation example.

### Known limitations

* **LBT** not implemented.
81 changes: 81 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
cmake_minimum_required(VERSION 3.15)
project(s2lp_rf_api)
include(ExternalProject)

#Check if Project configure by himself or by a parent project (like sfx_lib_core_protocol)
if ( ${CMAKE_SOURCE_DIR} STREQUAL ${PROJECT_SOURCE_DIR} )
if (NOT DEFINED SIGFOX_EP_LIB_DIR)
message(FATAL_ERROR "${PROJECT_NAME} cannot be configured without -DSIGFOX_EP_LIB_DIR=<sfx_lib_core_protocol directory>")
endif()
add_subdirectory(${SIGFOX_EP_LIB_DIR} "${CMAKE_CURRENT_BINARY_DIR}/${SIGFOX_EP_LIB_DIR}")
else()
set(SIGFOX_EP_LIB_DIR ${CMAKE_SOURCE_DIR})
message("${PROJECT_NAME} is Fetched by a parent project")
endif()

set (S2LP_RF_API_SOURCES
src/manuf/s2lp_rf_api.c
src/board/s2lp_hw_api.c
)

set (S2LP_RF_API_HEADERS
inc/manuf/s2lp_rf_api.h
inc/board/s2lp_hw_api.h
)

set( CHIP_RF_HEADERS_LIST "")

if (NOT TARGET s2lp_driver)
list(APPEND CHIP_RF_HEADERS_LIST ${CMAKE_CURRENT_BINARY_DIR}/drivers-src/s2lp/Drivers/BSP/Components/S2LP/S2LP_Library/inc/)
ExternalProject_Add(s2lp
PREFIX drivers-build
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
UPDATE_COMMAND
COMMAND bash -c "git -C ${CMAKE_CURRENT_BINARY_DIR}/drivers-src/s2lp/ reset --hard"
SOURCE_DIR drivers-src/s2lp
GIT_PROGRESS TRUE
GIT_SHALLOW TRUE
GIT_REPOSITORY https://github.com/STMicroelectronics/x-cube-sfxs2lp1.git
GIT_TAG v4.0.0
PATCH_COMMAND git apply ${CMAKE_CURRENT_LIST_DIR}/cmake/s2lp.patch
)
else ()
list(APPEND CHIP_RF_HEADERS_LIST "$<BUILD_INTERFACE:$<TARGET_PROPERTY:s2lp_driver,INTERFACE_INCLUDE_DIRECTORIES>>")
endif()

#Add Cmake module path
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")

#Precompile module
include(precompile_s2lp_rf_api)


add_library(${PROJECT_NAME}_obj OBJECT EXCLUDE_FROM_ALL src/manuf/s2lp_rf_api.c)
if (NOT TARGET s2lp_driver)
add_dependencies(${PROJECT_NAME}_obj s2lp)
endif()
target_include_directories( ${PROJECT_NAME}_obj PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/inc
${SIGFOX_EP_LIB_DIR}/inc
${CHIP_RF_HEADERS_LIST}
)
target_compile_definitions(${PROJECT_NAME}_obj PUBLIC ${DEF_FLAG_LIST})


add_library(${PROJECT_NAME} STATIC ${S2LP_RF_API_SOURCES})
add_dependencies(${PROJECT_NAME} precompil_${PROJECT_NAME} s2lp)
target_include_directories(${PROJECT_NAME} PUBLIC ${PRECOMPIL_DIR}/inc ${CHIP_RF_HEADERS_LIST})
target_compile_definitions(${PROJECT_NAME} PUBLIC ${DEF_FLAG_LIST})
target_compile_options(${PROJECT_NAME} PRIVATE -Wall)
#set_target_properties(${PROJECT_NAME} PROPERTIES PUBLIC_HEADER "${PRECOMPIL_ADDON_RFP_PUBLIC_HEADERS}")
set_target_properties(${PROJECT_NAME}
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY ${LIB_LOCATION}
LIBRARY_OUTPUT_DIRECTORY ${LIB_LOCATION}
)
install(TARGETS ${PROJECT_NAME}
ARCHIVE DESTINATION ${LIB_LOCATION}
PUBLIC_HEADER DESTINATION ${API_LOCATION}
)
128 changes: 128 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# S2LP RF API implementation example

## Description

This **S2LP RF API** is a low level implementation example of the [Sigfox EP library](https://github.com/sigfox-tech-radio/sigfox-ep-lib), showing the `manuf/rf_api.c` file implementation for the [S2LP](https://www.st.com/en/wireless-connectivity/s2-lp.html) transceiver from ST-Microelectronics.

The table below shows the version compatibility with the SIGFOX_EP_LIB version.

| **S2LP_RF_API** | **SIGFOX_EP_LIB** |
|:----------------------------------------------------------------------------------:|:----------------------------------------------------------------------------:|
| [v1.0](https://github.com/sigfox-tech-radio/sigfox-ep-rf-api-st-s2lp/releases/tag/v1.0) | [v3.2](https://github.com/sigfox-tech-radio/sigfox-ep-lib/releases/tag/v3.2) |

**Note:** the resulting radio performances of your device strongly depends on your hardware design (schematic, PCB routing, crystal oscillator placement, good RF practices, etc...). **Sigfox certification remains mandatory** whatever the software embedded in your device (including the Sigfox End-Point library and its implementation examples).

## Architecture

<p align="center">
<img src="docs/images/sigfox_ep_example_st_s2lp_architecture.png" width="600"/>
</p>

## External S2LP library

The **S2LP RF API** is based on the official [S2LP library](https://github.com/STMicroelectronics/x-cube-sfxs2lp1/tree/main/Drivers/BSP/Components/S2LP/S2LP_Library) from ST-Microelectronics. This library exposes a functional interface to configure the chip registers, which is used to perform the Sigfox uplink modulation and optional downlink reception.

## Hardware

The driver relies on **low level functions** (called board drivers) which need to be implemented to run on your specific hardware. There are divided in 2 groups:

* **MCU_Interface_template** : low level functions of the S2LP library from ST (registers access through SPI and shutdown pin management).
* **S2LP_HW_API** : additional hardware-dependent functions required to get a generic RF API implementation of the S2LP.

These drivers are located in the `src/board` folder.

## Code optimization

The driver inherits all the [Sigfox EP library](https://github.com/sigfox-tech-radio/sigfox-ep-lib) flags and can be optimized accordingly.

## Getting Started

### Cloning the repository

```bash
$ git clone https://github.com/sigfox-tech-radio/sigfox-ep-rf-api-st-s2lp.git
```

### Usage

This code can be used in 3 different ways:
* The [original source code](#original-source-code) to use the raw sources files
* The [precompiled source code](#precompiled-source-code) to remove all unused source code and have more readability.
* The [static-library](#static-library) to generate a compiled library.

### Original source code

Sources files are available in the `inc` and `src` folders and must be copied directly in your embedded project.

### Precompiled source code

#### Dependency

Before building process install **unifdef** and **cmake**. The unifdef tool is used to remove dead code and cmake to build.

#### Building process

If you want to **precompile** the sources files for a given flags selection, you need to use the **cmake** commands:

Create a build folder:

```bash
$ cd sigfox-ep-rf-api-st-s2lp
$ mkdir build
$ cd build
```

* Precompiling by reading the `inc/sigfox_ep_flags.h` file:

```bash
$ cmake -DSIGFOX_EP_LIB_DIR=<Sigfox EP library path> \
-DUSE_SIGFOX_EP_FLAGS_H=ON ..
$ make precompil
```
* Precompiling by entering the flags selection on command line:

```bash
$ cmake -DSIGFOX_EP_LIB_DIR=<Sigfox EP library path> \
-DUSE_SIGFOX_EP_FLAGS_H=OFF \
-DRC1=ON \
-DRC2=ON \
-DRC3C=ON \
-DRC3D=ON \
-DRC4=ON \
-DRC5=ON \
-DRC6=ON \
-DRC7=ON \
-DAPPLICATION_MESSAGES=ON \
-DCONTROL_KEEP_ALIVE_MESSAGE=ON \
-DBIDIRECTIONAL=ON \
-DASYNCHRONOUS=ON \
-DLOW_LEVEL_OPEN_CLOSE=ON \
-DREGULATORY=ON \
-DLATENCY_COMPENSATION=ON \
-DSINGLE_FRAME=ON \
-DPARAMETERS_CHECK=ON \
-DCERTIFICATION=ON \
-DPUBLIC_KEY_CAPABLE=ON \
-DVERBOSE=ON \
-DCRC_HW=OFF \
-DERROR_CODES=ON \
-DUL_BIT_RATE_BPS=OFF \
-DT_IFU_MS=OFF \
-DT_CONF_MS=OFF \
-DUL_PAYLOAD_SIZE=OFF \
-DMESSAGE_COUNTER_ROLLOVER=OFF \
-DERROR_STACK=12 ..
$ make precompil
```

The precompiled files will be generated in the `build/precompil` folder.

### Static library

If you want to build a **static library**, you need to run this additionnal **cmake** command:

```bash
$ make s2lp_rf_api
```

The archive will be generated in the `build/lib` folder.
51 changes: 51 additions & 0 deletions cmake/precompile_s2lp_rf_api.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
find_program(UNIFDEF unifdef REQUIRED)
if(NOT UNIFDEF)
message(FATAL_ERROR "unifdef not found!")
endif()

#List of precompileInc and precompileSrc files
foreach(X IN LISTS S2LP_RF_API_SOURCES)
LIST(APPEND PRECOMPIL_S2LP_RF_API_SOURCES "${PRECOMPIL_DIR}/${X}")
endforeach()
foreach(X IN LISTS S2LP_RF_API_HEADERS)
LIST(APPEND PRECOMPIL_S2LP_RF_API_HEADERS "${PRECOMPIL_DIR}/${X}")
endforeach()

#Custom command Loop for all RF api Sources and RF api Header
foreach(X IN LISTS S2LP_RF_API_SOURCES S2LP_RF_API_HEADERS)
add_custom_command(
OUTPUT "${PRECOMPIL_DIR}/${X}"
DEPENDS ${CMAKE_BINARY_DIR}/undefs_rf_api_file
DEPENDS ${CMAKE_BINARY_DIR}/defs_rf_api_file
DEPENDS ${X}
COMMAND ${CMAKE_COMMAND} -E make_directory ${PRECOMPIL_DIR}/src/manuf ${PRECOMPIL_DIR}/inc/manuf ${PRECOMPIL_DIR}/src/board ${PRECOMPIL_DIR}/inc/board
COMMAND unifdef -B -k -x 2 -f ${CMAKE_BINARY_DIR}/undefs_file -f ${CMAKE_BINARY_DIR}/undefs_rf_api_file -f ${CMAKE_BINARY_DIR}/defs_file -f ${CMAKE_BINARY_DIR}/defs_rf_api_file ${PROJECT_SOURCE_DIR}/${X} > "${PRECOMPIL_DIR}/${X}"
VERBATIM
)
endforeach()

add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/defs_rf_api_file
DEPENDS ${RF_API_HEADERS}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND cc -E -dMM ${DEF_FLAG_LIST} -I${CMAKE_CURRENT_SOURCE_DIR}/inc -I${CMAKE_SOURCE_DIR}/inc -I${SIGFOX_EP_LIB_DIR}/inc ${S2LP_RF_API_HEADERS} > "${CMAKE_BINARY_DIR}/defs_rf_api_file.tmp"
COMMAND grep -v __ "${CMAKE_BINARY_DIR}/defs_rf_api_file.tmp" | sort -u > "${CMAKE_BINARY_DIR}/defs_rf_api_file"
COMMAND rm "${CMAKE_BINARY_DIR}/defs_rf_api_file.tmp"
)

add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/undefs_rf_api_file
DEPENDS ${RF_API_HEADERS}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND cat ${CMAKE_CURRENT_SOURCE_DIR}/src/manuf/*c ${CMAKE_CURRENT_SOURCE_DIR}/inc/manuf/*.h | unifdef -s | sort -u | grep -v __ | sed "s/^/#undef /" >"${CMAKE_BINARY_DIR}/undefs_rf_api_file"
)

set_property(GLOBAL PROPERTY ALLOW_DUPLICATE_CUSTOM_TARGETS 1)

add_custom_target(precompil_${PROJECT_NAME}
DEPENDS precompil
DEPENDS ${PRECOMPIL_S2LP_RF_API_SOURCES}
DEPENDS ${PRECOMPIL_S2LP_RF_API_HEADERS}
VERBATIM
)



Loading

0 comments on commit 53e181a

Please sign in to comment.