├── .gitignore ├── LICENSE ├── README.md ├── cfg ├── README.md ├── cellular_cfg_module.h ├── cellular_cfg_sw.h └── cellular_cfg_test.h ├── ctrl ├── README.md ├── api │ └── cellular_ctrl.h ├── src │ ├── cellular_ctrl.c │ ├── cellular_ctrl_apn_db.h │ ├── cellular_ctrl_at.c │ └── cellular_ctrl_at.h └── test │ └── cellular_ctrl_test.c ├── example ├── README.md └── thingstream_secured │ ├── README.md │ └── main.c ├── mqtt ├── README.md ├── api │ └── cellular_mqtt.h ├── src │ └── cellular_mqtt.c └── test │ └── cellular_mqtt_test.c ├── pics-for-readme └── architecture.jpg ├── port ├── README.md ├── api │ ├── cellular_port.h │ ├── cellular_port_clib.h │ ├── cellular_port_debug.h │ ├── cellular_port_gpio.h │ ├── cellular_port_os.h │ └── cellular_port_uart.h ├── clib │ ├── cellular_port_clib.c │ └── cellular_port_clib_strtok_r.c ├── platform │ ├── README.md │ ├── common │ │ ├── amazon-freertos │ │ │ ├── README.md │ │ │ ├── iot_secure_sockets.c │ │ │ └── iot_wifi.c │ │ ├── test_automation │ │ │ ├── README.md │ │ │ ├── amazon-freertos │ │ │ │ └── configure.json │ │ │ ├── cellular_tests.bat │ │ │ └── run_unit_tests_and_detect_outcome.py │ │ └── unity │ │ │ ├── cellular_port_unity_addons.c │ │ │ ├── cellular_port_unity_addons.h │ │ │ └── unity_config.h │ ├── espressif │ │ └── esp32 │ │ │ ├── README.md │ │ │ ├── cfg │ │ │ ├── cellular_cfg_hw_platform_specific.h │ │ │ └── cellular_cfg_os_platform_specific.h │ │ │ ├── sdk │ │ │ ├── amazon-freertos │ │ │ │ ├── CMakeLists.txt │ │ │ │ └── README.md │ │ │ └── esp-idf │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── README.md │ │ │ │ └── unit_test │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── cellular_tests │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── component.mk │ │ │ │ └── test │ │ │ │ │ ├── CMakeLists.txt │ │ │ │ │ ├── cellular_port_test_platform_specific.h │ │ │ │ │ └── component.mk │ │ │ │ ├── component.mk │ │ │ │ ├── main │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── component.mk │ │ │ │ └── main_test.c │ │ │ │ └── sdkconfig.defaults │ │ │ └── src │ │ │ ├── cellular_port.c │ │ │ ├── cellular_port_clib_platform_specific.h │ │ │ ├── cellular_port_debug.c │ │ │ ├── cellular_port_gpio.c │ │ │ ├── cellular_port_os.c │ │ │ └── cellular_port_uart.c │ ├── nordic │ │ └── nrf52840 │ │ │ ├── README.md │ │ │ ├── cfg │ │ │ ├── FreeRTOSConfig.h │ │ │ ├── cellular_cfg_hw_platform_specific.h │ │ │ ├── cellular_cfg_os_platform_specific.h │ │ │ └── sdk_config.h │ │ │ ├── sdk │ │ │ ├── gcc │ │ │ │ ├── README.md │ │ │ │ └── unit_test │ │ │ │ │ ├── Makefile │ │ │ │ │ ├── README.md │ │ │ │ │ └── uart_gcc_nrf52.ld │ │ │ └── ses │ │ │ │ ├── README.md │ │ │ │ └── unit_test │ │ │ │ ├── README.md │ │ │ │ ├── cellular_pca10056.emProject │ │ │ │ └── flash_placement.xml │ │ │ ├── src │ │ │ ├── cellular_port.c │ │ │ ├── cellular_port_clib_platform_specific.h │ │ │ ├── cellular_port_debug.c │ │ │ ├── cellular_port_gpio.c │ │ │ ├── cellular_port_os.c │ │ │ ├── cellular_port_private.c │ │ │ ├── cellular_port_private.h │ │ │ └── cellular_port_uart.c │ │ │ └── test │ │ │ ├── cellular_port_test_platform_specific.h │ │ │ └── main_test.c │ └── stm │ │ └── stm32f4 │ │ ├── README.md │ │ ├── cfg │ │ ├── FreeRTOSConfig.h │ │ ├── cellular_cfg_hw_platform_specific.h │ │ └── cellular_cfg_os_platform_specific.h │ │ ├── sdk │ │ └── cube │ │ │ ├── README.md │ │ │ └── unit_test │ │ │ ├── .cproject │ │ │ ├── .project │ │ │ └── README.md │ │ ├── src │ │ ├── cellular_port.c │ │ ├── cellular_port_clib_platform_specific.h │ │ ├── cellular_port_debug.c │ │ ├── cellular_port_gpio.c │ │ ├── cellular_port_os.c │ │ ├── cellular_port_private.c │ │ ├── cellular_port_private.h │ │ ├── cellular_port_uart.c │ │ ├── heap_useNewlib.c │ │ ├── startup_stm32f437vgtx.s │ │ ├── stm32_assert.h │ │ ├── stm32f4xx_hal_conf.h │ │ ├── stm32f4xx_hal_msp.c │ │ ├── stm32f4xx_it.c │ │ ├── stm32f4xx_it.h │ │ ├── syscalls.c │ │ └── system_stm32f4xx.c │ │ └── test │ │ ├── STM32F437VGTX_FLASH.ld │ │ ├── STM32F437VGTX_RAM.ld │ │ ├── cellular_port_test_platform_specific.h │ │ └── main_test.c └── test │ └── cellular_port_test.c └── sock ├── README.md ├── api ├── cellular_sock.h └── cellular_sock_errno.h ├── src ├── cellular_sock.c ├── cellular_sock_lwip_itf.c └── cellular_sock_lwip_itf.h └── test └── cellular_sock_test.c /.gitignore: -------------------------------------------------------------------------------- 1 | /port/platform/espressif/esp32/sdk/esp-idf/unit_test/build 2 | /port/platform/nordic/nrf52480/sdk/gcc/unit_test/_build 3 | /port/platform/nordic/nrf52480/sdk/ses/unit_test/Output 4 | sdkconfig 5 | *.emSession -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This repo is now superseded by https://github.com/u-blox/ubxlib. 2 | 3 | # Introduction 4 | In this repository you will find the implementation of a cellular transport in C for various embedded target platforms, enabling a cellular connection to be used inside the embedded C IoT SDKs of cloud platforms such as AWS and Azure. The implementation consists of: 5 | 6 | - `ctrl`: a driver that allows control of a cellular module over an AT interface, e.g. make connection, read IMEI, read signal strength, etc. 7 | - `sock`: a driver that allows data transfer through a cellular module, presenting the same TCP/UDP sockets API as LWIP and building on top of the AT parser in `ctrl`. 8 | - `port`: the porting layer which allows `ctrl` and `sock` to be compiled and tested on various platforms and within various SDKs; look here for the build files and the tests. 9 | - `cfg`: configuration information for the software in general, specific cellular modules and tests. 10 | 11 | ![Architecture](pics-for-readme/architecture.jpg) 12 | 13 | # Usage 14 | The C API for `ctrl`, `sock` and `port` can be found in their respective `api` sub-directories and are documented in the header files there. Information on how to build run tests on a given target platform can be found in the `README.md` files of the relevant platform sub-directory of `port`. 15 | 16 | # License 17 | The software in this repository is Apache 2.0 licensed and copyright u-blox with the following exceptions: 18 | 19 | - the AT parsing code in `ctrl` is derived from the Apache 2.0 licensed AT parser of mbed-os, 20 | - the heap management code for the STM32 platform (`heap_useNewlib.c`), required because the native ST implementation does not allocate memory correctly when used with FreeRTOS, is copyright Dave Nadler. 21 | 22 | In all cases copyright (and our thanks) remain with the original authors. 23 | -------------------------------------------------------------------------------- /cfg/README.md: -------------------------------------------------------------------------------- 1 | This directory contains generic, platform independent configuration information: 2 | 3 | - `cellular_cfg_module.h`: configuration for all of the possible supported module types. 4 | - `cellular_cfg_sw.h`: generic SW configuration, e.g. switching logging from the cellular driver on or off. 5 | - `cellular_cfg_test.h`: configuration that is used by the `.c` files in the `test` directories. -------------------------------------------------------------------------------- /cfg/cellular_cfg_sw.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 u-blox Cambourne Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _CELLULAR_CFG_SW_H_ 18 | #define _CELLULAR_CFG_SW_H_ 19 | 20 | /* No #includes allowed here */ 21 | 22 | /* This header file contains software configuration information for 23 | * cellular. 24 | */ 25 | 26 | /* ---------------------------------------------------------------- 27 | * COMPILE-TIME MACROS 28 | * -------------------------------------------------------------- */ 29 | 30 | #ifndef CELLULAR_CFG_ENABLE_LOGGING 31 | /** Enable or disable logging from the cellular module. 32 | */ 33 | # define CELLULAR_CFG_ENABLE_LOGGING 1 34 | #endif 35 | 36 | #endif // _CELLULAR_CFG_SW_H_ 37 | 38 | // End of file 39 | -------------------------------------------------------------------------------- /cfg/cellular_cfg_test.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 u-blox Cambourne Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _CELLULAR_CFG_TEST_H_ 18 | #define _CELLULAR_CFG_TEST_H_ 19 | 20 | /* No #includes allowed here */ 21 | 22 | /* This header file contains configuration information to be used 23 | * when testing cellular. 24 | */ 25 | 26 | /* ---------------------------------------------------------------- 27 | * COMPILE-TIME MACROS: CELLULAR NETWORK RELATED 28 | * -------------------------------------------------------------- */ 29 | 30 | #ifndef CELLULAR_CFG_TEST_RAT 31 | /** The RAT to use during testing. 32 | */ 33 | # define CELLULAR_CFG_TEST_RAT CELLULAR_CTRL_RAT_CATM1 34 | #endif 35 | 36 | #ifndef CELLULAR_CFG_TEST_BANDMASK1 37 | /** The bandmask 1 to use during testing. 0x080092 is bands 38 | * 2, 5, 8 and 20. 39 | */ 40 | # define CELLULAR_CFG_TEST_BANDMASK1 0x080092ULL 41 | #endif 42 | 43 | #ifndef CELLULAR_CFG_TEST_BANDMASK2 44 | /** The bandmask 2 to use during testing. 45 | */ 46 | # define CELLULAR_CFG_TEST_BANDMASK2 0ULL 47 | #endif 48 | 49 | #ifndef CELLULAR_CFG_TEST_APN 50 | /** The APN to use when testing connectivity, NULL for unspecified, 51 | * "" for empty. 52 | */ 53 | # define CELLULAR_CFG_TEST_APN NULL 54 | #endif 55 | 56 | #ifndef CELLULAR_CFG_TEST_USERNAME 57 | /** The username to use when testing connectivity, NULL for unspecified, 58 | * "" for empty. 59 | */ 60 | # define CELLULAR_CFG_TEST_USERNAME NULL 61 | #endif 62 | 63 | #ifndef CELLULAR_CFG_TEST_PASSWORD 64 | /** The password to use when testing connectivity, NULL for unspecified, 65 | * "" for empty. 66 | */ 67 | # define CELLULAR_CFG_TEST_PASSWORD NULL 68 | #endif 69 | 70 | #ifndef CELLULAR_CFG_TEST_CONNECT_TIMEOUT_SECONDS 71 | // The time in seconds allowed for a connection to complete. 72 | #define CELLULAR_CFG_TEST_CONNECT_TIMEOUT_SECONDS 240 73 | #endif 74 | 75 | /* ---------------------------------------------------------------- 76 | * COMPILE-TIME MACROS: IP RELATED 77 | * -------------------------------------------------------------- */ 78 | 79 | #ifndef CELLULAR_CFG_TEST_ECHO_UDP_SERVER_DOMAIN_NAME 80 | /** Echo server to use for UDP sockets testing as a domain name. 81 | */ 82 | # define CELLULAR_CFG_TEST_ECHO_UDP_SERVER_DOMAIN_NAME "echo.u-blox.com" 83 | #endif 84 | 85 | #ifndef CELLULAR_CFG_TEST_ECHO_UDP_SERVER_IP_ADDRESS 86 | /** Echo server to use for UDP sockets testing as an IP address. 87 | */ 88 | # define CELLULAR_CFG_TEST_ECHO_UDP_SERVER_IP_ADDRESS "195.34.89.241" 89 | #endif 90 | 91 | #ifndef CELLULAR_CFG_TEST_ECHO_UDP_SERVER_PORT 92 | /** Port number on the echo server to use for UDP testing. 93 | */ 94 | # define CELLULAR_CFG_TEST_ECHO_UDP_SERVER_PORT 7 95 | #endif 96 | 97 | #ifndef CELLULAR_CFG_TEST_ECHO_TCP_SERVER_DOMAIN_NAME 98 | /** Echo server to use for TCP sockets testing as a domain name. 99 | * (note: the u-blox one adds a prefix to the echoed TCP packets 100 | * which is undesirable; mbed don't seem to mind us using theirs). 101 | */ 102 | # define CELLULAR_CFG_TEST_ECHO_TCP_SERVER_DOMAIN_NAME "echo.mbedcloudtesting.com" 103 | #endif 104 | 105 | #ifndef CELLULAR_CFG_TEST_ECHO_TCP_SERVER_IP_ADDRESS 106 | /** Echo server to use for TCP sockets testing as an IP address. 107 | * (note: the u-blox one adds a prefix to the echoed TCP packets 108 | * which is undesirable; mbed don't seem to mind us using theirs). 109 | */ 110 | # define CELLULAR_CFG_TEST_ECHO_TCP_SERVER_IP_ADDRESS "52.215.34.155" 111 | #endif 112 | 113 | #ifndef CELLULAR_CFG_TEST_ECHO_TCP_SERVER_PORT 114 | /** Port number on the echo server to use for TCP testing. 115 | */ 116 | # define CELLULAR_CFG_TEST_ECHO_TCP_SERVER_PORT 7 117 | #endif 118 | 119 | #ifndef CELLULAR_CFG_TEST_LOCAL_PORT 120 | /** Local port number, used when testing binding. 121 | */ 122 | # define CELLULAR_CFG_TEST_LOCAL_PORT 65543 123 | #endif 124 | 125 | #ifndef CELLULAR_CFG_TEST_UDP_RETRIES 126 | /** The number of retries to allow when sending 127 | * data over UDP. 128 | */ 129 | # define CELLULAR_CFG_TEST_UDP_RETRIES 10 130 | #endif 131 | 132 | /* ---------------------------------------------------------------- 133 | * COMPILE-TIME MACROS: MQTT RELATED 134 | * -------------------------------------------------------------- */ 135 | 136 | #ifndef CELLULAR_CFG_TEST_MQTT_SERVER_TIMEOUT_SECONDS 137 | /** The time to wait for an MQTT operation involving 138 | * the MQTT server to complete during testing. 139 | */ 140 | # define CELLULAR_CFG_TEST_MQTT_SERVER_TIMEOUT_SECONDS 180 141 | #endif 142 | 143 | #ifndef CELLULAR_CFG_TEST_MQTT_SERVER_DOMAIN_NAME 144 | /** Server to use for MTT testing as a domain name. 145 | */ 146 | # define CELLULAR_CFG_TEST_MQTT_SERVER_DOMAIN_NAME "test.mosquitto.org:1883" 147 | #endif 148 | 149 | #ifndef CELLULAR_CFG_TEST_MQTT_SERVER_IP_ADDRESS 150 | /** Server to use for MQTT testing as an IP address. 151 | */ 152 | # define CELLULAR_CFG_TEST_MQTT_SERVER_IP_ADDRESS "5.196.95.208" 153 | #endif 154 | 155 | #ifndef CELLULAR_CFG_TEST_MQTT_USERNAME 156 | /** User name to use for the MQTT test server. 157 | */ 158 | # define CELLULAR_CFG_TEST_MQTT_USERNAME NULL 159 | #endif 160 | 161 | #ifndef CELLULAR_CFG_TEST_MQTT_PASSWORD 162 | /** Password to use for the MQTT test server. 163 | */ 164 | # define CELLULAR_CFG_TEST_MQTT_PASSWORD NULL 165 | #endif 166 | 167 | 168 | #endif // _CELLULAR_CFG_TEST_H_ 169 | 170 | // End of file 171 | -------------------------------------------------------------------------------- /ctrl/README.md: -------------------------------------------------------------------------------- 1 | IMPORTANT: this API is still in the process of definition, anything may change, beware! We aim to have it settled by the middle of 2020, COVID 19 permitting. 2 | 3 | # Introduction 4 | These directories provide a driver that implements the control interface to a cellular module. 5 | 6 | # Usage 7 | The directories include only the API and pure C source files that make no reference to a platform, a C library or an operating system. They rely upon the `port` directory to map to a target platform and provide the necessary build/test infrastructure for that target platform; see the relevant platform directory under `port` for build and usage information. 8 | 9 | # Testing 10 | The `test` directory contains generic tests for the `ctrl` API. Please refer to the relevant platform directory of the `port` component for instructions on how to build and run the tests. -------------------------------------------------------------------------------- /example/README.md: -------------------------------------------------------------------------------- 1 | # Introduction 2 | These directories provide the source code examples that show how to use the various APIs. To build and run these source files on a supported platform you need to travel down into the `port/platform///` directory of your choice and follow the instructions in the `README.md` there. For instance to build the examples on an ESP32 chip you would go to `port/platform/espressif/esp32/esp-idf` and follow the instructions in the `README.md` there to both install the Espressif development environment and build/run the examples. 3 | 4 | Note that examples are built and run in exactly the same way as the unit tests, so look in the `unit_test` build for all detailed instructions. 5 | 6 | # Examples 7 | 8 | - `thingstream_secured` contains the example `exampleThingstreamSecured` which demonstrates how to use end to end encryption in a supported u-blox cellular module (e.g. SARA-R5) and exchange these end-to-end encrypted messages using the Thingstream service. The cellular module must have been security sealed for this example to complete. -------------------------------------------------------------------------------- /example/thingstream_secured/README.md: -------------------------------------------------------------------------------- 1 | # Introduction 2 | This example demonstrates how to use end to end encryption in a supported u-blox cellular module (e.g. SARA-R5) and exchange these end-to-end encrypted messages using the Thingstream service. The cellular module must have been security sealed (see the security section of the relevant u-blox AT command manual for details) for this example to complete. 3 | 4 | # Usage 5 | This build requires that you have a Thingstream account. Please visit https://https://thingstream.io/ to set one up. 6 | 7 | To build and run this example on a supported platform you need to travel down into the `port/platform///` directory of your choice and follow the instructions in the `README.md` there. Note that examples are built and run in exactly the same way as the unit tests, so look in the `unit_test` build for all detailed instructions. 8 | 9 | # Compilation Flags/#defines 10 | ## Platform Related 11 | The instructions for your chosen platform will tell you how to set/override conditional compilation flags. There are a number of conditional compilation flags that must be set correctly for your platform in order to build and run this example. 12 | 13 | This build requires a cellular module that supports u-blox security services, e.g. SARA-R5 or SARA-R412M-03B. Consult the `cfg/cellular_cfg_module.h` file to determine which module you intend to use and then define the relevant conditional compilation flag. For instance, to use SARA-R5 `CELLULAR_CFG_MODULE_SARA_R5` must be defined. 14 | 15 | The default values for the MCU pins connecting your cellular module to your choice of MCU are defined in the file `port/platform///cfg/cellular_cfg_hw_platform_specific.h`. You should check if these are correct for your chosen hardware and, if not, override the values of the #defines (where -1 means "not connected"). 16 | 17 | To include the unit tests and examples in the build, define `CELLULAR_CFG_UBLOX_TEST`. To run ONLY this example (otherwise all of the unit test and all of the examples will be run) set the #define `CELLULAR_CFG_TEST_FILTER` to the value `exampleThingstreamSecured` (noting that NO quotation marks should be added around the value part). 18 | 19 | ## Specific To This Example 20 | The following values must be set correctly by opening and editing the values in `main.c`. 21 | 22 | If your cellular operator requires a specific APN to be set, you should set the value of the #define `MY_APN` to that value in `main.c` (and possibly the associated `MY_USERNAME` and `MY_PASSWORD` if your operator requires them also). 23 | 24 | You must have a "thing" in your Thingstream account with which this example can communicate. Create one in your account and, under "Thing Details", look in the "credentials" tab and set the values of the following #defines in `main.c` (you will see example values in there commented out): 25 | 26 | - `MY_THINGSTREAM_CLIENT_ID` - this will begin with "device:"; the value is the whole thing, i.e. including "device:" at the start. 27 | - `MY_THINGSTREAM_USERNAME` - this will be at least 20 characters long. 28 | - `MY_THINGSTREAM_PASSWORD` - this will be at least 40 characters long and may have `/` characters within it. 29 | -------------------------------------------------------------------------------- /mqtt/README.md: -------------------------------------------------------------------------------- 1 | IMPORTANT: this API is still in the process of definition, anything may change, beware! We aim to have it settled by the middle of 2020, COVID 19 permitting. 2 | 3 | # Introduction 4 | These directories provide a driver that implements an MQTT interface with a cellular module. 5 | 6 | The files under the `ctrl` directory provide the actual AT interface to the cellular module and hence are required by this driver (and those of `port`, see next section) to achieve a usable binary image. 7 | 8 | The `sock` API provides IP address manipulation functions which are required by this driver. 9 | 10 | # Usage 11 | The directories include only the API and pure C source files that make no reference to a platform, a C library or an operating system. They rely upon the `port` directory to map to a target platform and provide the necessary build/test infrastructure for that target platform; see the relevant platform directory under `port` for build and usage information. 12 | 13 | # Testing 14 | The `test` directory contains generic tests for the `mqtt` API. Please refer to the relevant platform directory of the `port` component for instructions on how to build and run the tests. -------------------------------------------------------------------------------- /pics-for-readme/architecture.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/u-blox/cellular/85ed70ef362666edea806e7196c4ea4fd39f55fb/pics-for-readme/architecture.jpg -------------------------------------------------------------------------------- /port/README.md: -------------------------------------------------------------------------------- 1 | IMPORTANT: this API is still in the process of definition, anything may change, beware! We aim to have it settled by the middle of 2020, COVID 19 permitting. 2 | 3 | # Introduction 4 | These directories provide the porting layer that allows the files in the `ctrl` and `sock` directories to be linked and run on a target platform. 5 | 6 | No attempt is made to create a full platform porting API; only the APIs necessay for `ctrl` and `sock` to run are implemented here. 7 | 8 | # Usage 9 | The `api` directory defines the platform API, as required by `ctrl` and `sock`. The `clib` directory contains a generic mapping of the C library portion of the porting API to the standard C library; this can usually be employed on any platform. In the `platform` directory you will find the implementation of the remainder of the porting API on various target platforms and the necessary instructions to create a working binary and tests on each of those target platforms. Please refer to the `README.md` file in your chosen target platform directory for more information. 10 | 11 | The `test` directory contains tests for the porting layer that can be run on any platform. -------------------------------------------------------------------------------- /port/api/cellular_port.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 u-blox Cambourne Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _CELLULAR_PORT_H_ 18 | #define _CELLULAR_PORT_H_ 19 | 20 | /* No #includes allowed here */ 21 | 22 | /** Common stuff for porting layer. 23 | */ 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | /* ---------------------------------------------------------------- 30 | * COMPILE-TIME MACROS 31 | * -------------------------------------------------------------- */ 32 | 33 | /** On some platforms we need to run a timer to get our 64-bit 34 | * tick timer. This specifies the timer instance to use for that. 35 | */ 36 | #ifndef CELLULAR_PORT_TICK_TIMER_INSTANCE 37 | # define CELLULAR_PORT_TICK_TIMER_INSTANCE 0 38 | #endif 39 | 40 | /* ---------------------------------------------------------------- 41 | * TYPES 42 | * -------------------------------------------------------------- */ 43 | 44 | /** Error codes. 45 | */ 46 | typedef enum { 47 | CELLULAR_PORT_SUCCESS = 0, 48 | CELLULAR_PORT_UNKNOWN_ERROR = -1, 49 | CELLULAR_PORT_NOT_INITIALISED = -2, 50 | CELLULAR_PORT_NOT_IMPLEMENTED = -3, 51 | CELLULAR_PORT_INVALID_PARAMETER = -4, 52 | CELLULAR_PORT_OUT_OF_MEMORY = -5, 53 | CELLULAR_PORT_TIMEOUT = -6, 54 | CELLULAR_PORT_PLATFORM_ERROR = -7, 55 | CELLULAR_PORT_FORCE_32_BIT = 0x7FFFFFFF // Force this enum to be 32 bit 56 | // as it can be used as a size 57 | // also 58 | } CellularPortErrorCode_t; 59 | 60 | /* ---------------------------------------------------------------- 61 | * FUNCTIONS 62 | * -------------------------------------------------------------- */ 63 | 64 | /** Start the platform. This should be called before 65 | * anything else: it configures clocks, resources, etc. and, 66 | * then calls the entry point function. 67 | * Where there is code already in the system that does these 68 | * things, that code should be adapted to include the 69 | * necessary portions of this function. 70 | * This function only returns if there is an error; 71 | * code execution ends up in pEntryPoint, which should 72 | * never return. 73 | * 74 | * @param pEntryPoint the function to run. 75 | * @param pParameter a pointer that will be passed to pEntryPoint 76 | * when it is called. Usually NULL. 77 | * @param stackSizeBytes the number of bytes of memory to dynamically 78 | * allocate for stack; ignored if an RTOS 79 | * task is already running. 80 | * @param priority the priority at which to run a task that 81 | * is pEntryPoint; ignored if an RTOS 82 | * task is already running. 83 | * @return negative error code. 84 | */ 85 | int32_t cellularPortPlatformStart(void (*pEntryPoint)(void *), 86 | void *pParameter, 87 | size_t stackSizeBytes, 88 | int32_t priority); 89 | 90 | /** Initialise the porting layer. 91 | * 92 | * @return zero on success else negative error code. 93 | */ 94 | int32_t cellularPortInit(); 95 | 96 | /** Deinitialise the porting layer. 97 | */ 98 | void cellularPortDeinit(); 99 | 100 | /** Get the current OS tick converted to a time in milliseconds. 101 | * This is guaranteed to be unaffected by any time setting activity 102 | * It is NOT maintained while the processor is sleeping; port 103 | * initialisation must be called on return from sleep and 104 | * that will restart this time from zero once more. 105 | * 106 | * @return the current OS tick converted to milliseconds. 107 | */ 108 | int64_t cellularPortGetTickTimeMs(); 109 | 110 | #ifdef __cplusplus 111 | } 112 | #endif 113 | 114 | #endif // _CELLULAR_PORT_H_ 115 | 116 | // End of file 117 | -------------------------------------------------------------------------------- /port/api/cellular_port_debug.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 u-blox Cambourne Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _CELLULAR_PORT_DEBUG_H_ 18 | #define _CELLULAR_PORT_DEBUG_H_ 19 | 20 | /* No #includes allowed here */ 21 | 22 | /** Porting layer for debug functions. 23 | */ 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | /* ---------------------------------------------------------------- 30 | * COMPILE-TIME MACROS 31 | * -------------------------------------------------------------- */ 32 | 33 | /** Define this to enable debug prints. How they leave the building 34 | * depends upon the port. 35 | */ 36 | #if defined(CELLULAR_CFG_ENABLE_LOGGING) && CELLULAR_CFG_ENABLE_LOGGING 37 | # define cellularPortLog(format, ...) cellularPortLogF(format, ##__VA_ARGS__) 38 | #else 39 | # define cellularPortLog(...) 40 | #endif 41 | 42 | /* ---------------------------------------------------------------- 43 | * TYPES 44 | * -------------------------------------------------------------- */ 45 | 46 | /* ---------------------------------------------------------------- 47 | * FUNCTIONS 48 | * -------------------------------------------------------------- */ 49 | 50 | /** printf()-style logging. 51 | * 52 | * @param pFormat a printf() style format string. 53 | * @param ... variable argument list. 54 | */ 55 | void cellularPortLogF(const char *pFormat, ...); 56 | 57 | #ifdef __cplusplus 58 | } 59 | #endif 60 | 61 | #endif // _CELLULAR_PORT_DEBUG_H_ 62 | 63 | // End of file 64 | -------------------------------------------------------------------------------- /port/api/cellular_port_gpio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 u-blox Cambourne Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _CELLULAR_PORT_GPIO_H_ 18 | #define _CELLULAR_PORT_GPIO_H_ 19 | 20 | /* No #includes allowed here */ 21 | 22 | /** Porting layer for GPIO access functions. These functions 23 | * are thread-safe. 24 | */ 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | /* ---------------------------------------------------------------- 31 | * COMPILE-TIME MACROS 32 | * -------------------------------------------------------------- */ 33 | 34 | /* ---------------------------------------------------------------- 35 | * TYPES 36 | * -------------------------------------------------------------- */ 37 | 38 | /** The possible GPIO directions. 39 | */ 40 | typedef enum { 41 | CELLULAR_PORT_GPIO_DIRECTION_NONE, 42 | CELLULAR_PORT_GPIO_DIRECTION_INPUT, 43 | CELLULAR_PORT_GPIO_DIRECTION_OUTPUT, 44 | CELLULAR_PORT_GPIO_DIRECTION_INPUT_OUTPUT, 45 | MAX_NUM_CELLULAR_PORT_GPIO_DIRECTIONS 46 | } CellularPortGpioDirection_t; 47 | 48 | /** The possible GPIO pull modes. 49 | */ 50 | typedef enum { 51 | CELLULAR_PORT_GPIO_PULL_MODE_NONE, 52 | CELLULAR_PORT_GPIO_PULL_MODE_PULL_UP, 53 | CELLULAR_PORT_GPIO_PULL_MODE_PULL_DOWN, 54 | MAX_NUM_CELLULAR_PORT_GPIO_PULL_MODES 55 | } CellularPortGpioPullMode_t; 56 | 57 | /** The possible GPIO drive modes. 58 | */ 59 | typedef enum { 60 | CELLULAR_PORT_GPIO_DRIVE_MODE_NORMAL, 61 | CELLULAR_PORT_GPIO_DRIVE_MODE_OPEN_DRAIN, 62 | MAX_NUM_CELLULAR_PORT_GPIO_DRIVE_MODES 63 | } CellularPortGpioDriveMode_t; 64 | 65 | /** The possible GPIO drive capabilities. 66 | * A number from 0 to 3 where 0 is weakest. 67 | */ 68 | typedef enum { 69 | CELLULAR_PORT_GPIO_DRIVE_CAPABILITY_WEAKEST = 0, 70 | CELLULAR_PORT_GPIO_DRIVE_CAPABILITY_WEAK = 1, 71 | CELLULAR_PORT_GPIO_DRIVE_CAPABILITY_STRONG = 2, 72 | CELLULAR_PORT_GPIO_DRIVE_CAPABILITY_STRONGEST = 3, 73 | MAX_NUM_CELLULAR_PORT_GPIO_DRIVE_CAPABILITIES 74 | } CellularPortGpioDriveCapability_t; 75 | 76 | /** GPIO configuration structure. 77 | * If you update this, don't forget to update 78 | * CELLULAR_PORT_GPIO_CONFIG_DEFAULT also. 79 | */ 80 | typedef struct { 81 | int32_t pin; 82 | CellularPortGpioDirection_t direction; 83 | CellularPortGpioPullMode_t pullMode; 84 | CellularPortGpioDriveMode_t driveMode; 85 | CellularPortGpioDriveCapability_t driveCapability; 86 | } CellularPortGpioConfig_t; 87 | 88 | /** Default values for the above. 89 | */ 90 | #define CELLULAR_PORT_GPIO_CONFIG_DEFAULT {-1, \ 91 | CELLULAR_PORT_GPIO_DIRECTION_NONE, \ 92 | CELLULAR_PORT_GPIO_PULL_MODE_NONE, \ 93 | CELLULAR_PORT_GPIO_DRIVE_MODE_NORMAL, \ 94 | CELLULAR_PORT_GPIO_DRIVE_CAPABILITY_STRONG} 95 | 96 | /* ---------------------------------------------------------------- 97 | * FUNCTIONS 98 | * -------------------------------------------------------------- */ 99 | 100 | /** Configure a GPIO. 101 | * 102 | * @param pConfig a pointer to the configuration to set, cannot be NULL. 103 | * @return zero on success else negative error code. 104 | */ 105 | int32_t cellularPortGpioConfig(CellularPortGpioConfig_t *pConfig); 106 | 107 | /** Set the state of a GPIO. 108 | * 109 | * @param pin the pin to set. 110 | * @param level the level to set, 0 for low or non-zero for high. 111 | * @return zero on success else negative error code. 112 | */ 113 | int32_t cellularPortGpioSet(int32_t pin, int32_t level); 114 | 115 | /** Get the state of a GPIO. 116 | * 117 | * @param pin the pin to get the state of. 118 | * @return on success the level (0 or 1) else negative error code. 119 | */ 120 | int32_t cellularPortGpioGet(int32_t pin); 121 | 122 | #ifdef __cplusplus 123 | } 124 | #endif 125 | 126 | #endif // _CELLULAR_PORT_GPIO_H_ 127 | 128 | // End of file 129 | -------------------------------------------------------------------------------- /port/clib/cellular_port_clib_strtok_r.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 u-blox Cambourne Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "string.h" 18 | #include "cellular_port_clib_platform_specific.h" 19 | 20 | /** strtok_r 21 | * @param pStr on first call this should be a pointer to 22 | * the string to tokenise. On subsequent calls 23 | * it must be NULL to return further tokens. 24 | * The contents of pStr are modified by this 25 | * function (NULLs being written to delineate 26 | * tokens). 27 | * @param pDelimiters the delimiters to tokenise based on. 28 | * @param ppSave a pointer to a pointer that can be used to 29 | * save context between calls. 30 | * @return the token, NULL terminated. 31 | */ 32 | char *strtok_r(char *pStr, const char *pDelimiters, char **ppSave) 33 | { 34 | char *pEnd; 35 | 36 | if (pStr == NULL) { 37 | // On subsequent calls, with pStr NULL, 38 | // set pStr to start from the saved position 39 | pStr = *ppSave; 40 | } 41 | 42 | if (*pStr != '\0') { 43 | // Find the position of any delimiters 44 | // at the beginning of the string/saved pointer 45 | pStr += strspn(pStr, pDelimiters); 46 | if (*pStr != '\0') { 47 | // Having found a token, find the start 48 | // of the next one 49 | pEnd = pStr + strcspn(pStr, pDelimiters); 50 | if (*pEnd != '\0') { 51 | // Found one: write a NULL to the position 52 | // of the start of the next token 53 | // in order to make sure the returned 54 | // token is terminated and make the 55 | // saved pointer point beyond it for 56 | // next time. 57 | *pEnd = '\0'; 58 | *ppSave = ++pEnd; 59 | } else { 60 | // No next one, save the end 61 | // for next time 62 | *ppSave = pEnd; 63 | } 64 | } else { 65 | // None at all, save it and 66 | // set the return value to NULL 67 | *ppSave = pStr; 68 | pStr = NULL; 69 | } 70 | } else { 71 | // If we're at the terminator, 72 | // save where we are and set the 73 | // return value to NULL 74 | *ppSave = pStr; 75 | pStr = NULL; 76 | } 77 | 78 | return pStr; 79 | } -------------------------------------------------------------------------------- /port/platform/README.md: -------------------------------------------------------------------------------- 1 | # Introduction 2 | 3 | These directories provide the implementation of the porting layer on various platforms. The `common` directory contains `.c` files that are common to more than one platform (e.g. files for `amazon-freertos` which may be used by `espressif` and also by other platforms that run `amazon-freertos`). 4 | 5 | # Structure 6 | 7 | Each platform directory will include the following sub-directories: 8 | 9 | - `sdk` - build files for the SDKs on which that platform can be used. 10 | - `src` - the `.c` files that implement the porting layer for that platform. 11 | - `cfg` - definitions for the specific HW on which that platform is supported. This shall include, as a minimum: 12 | - the following pins, where -1 is used to indicate that there is no such pin: 13 | - `CELLULAR_CFG_PIN_ENABLE_POWER` the GPIO output pin that enables power to the cellular module, may be -1. 14 | - `CELLULAR_CFG_PIN_PWR_ON` the GPIO output pin that is connected to the PWR_ON pin of the cellular module. 15 | - `CELLULAR_CFG_PIN_VINT` the GPIO input pin that is connected to the VInt pin of the cellular module, may be -1 but note that this is NOT advisable: it is only possible to tell when a module has powered down by waiting for the VInt pin to go low, lack of response to AT commands is not a guide. 16 | - `CELLULAR_CFG_PIN_TXD` the GPIO output pin that sends UART data to the cellular module. 17 | - `CELLULAR_CFG_PIN_RXD` the GPIO input pin that receives UART data from the cellular module. 18 | - `CELLULAR_CFG_PIN_CTS` the GPIO input pin that the cellular module will use to indicate that it is ready to receive data on `CELLULAR_CFG_PIN_TXD`, may be -1. 19 | - `CELLULAR_CFG_PIN_RTS` the GPIO output pin that tells the cellular module that it can send more data on `CELLULAR_CFG_PIN_RXD`, may be -1. 20 | - `CELLULAR_CFG_UART` the UART HW block to use inside the chipset. 21 | - `CELLULAR_CFG_RTS_THRESHOLD` the buffer threshold at which RTS is deasserted to stop the cellular module sending data to into the UART, must be specified if `CELLULAR_CFG_PIN_RTS` is not -1. -------------------------------------------------------------------------------- /port/platform/common/amazon-freertos/README.md: -------------------------------------------------------------------------------- 1 | You won't find build files or build instructions for Amazon FreeRTOS in here! This folder simply holds a few files which are common to all platforms which support Amazon FreeRTOS. For build files, build instructions and tests you need to look under the chipset platform (e.g. Espressif). If that chipset platform has support for Amazon FreeRTOS you will find the build stuff for Amazon FreeRTOS in its `sdk` directory. -------------------------------------------------------------------------------- /port/platform/common/test_automation/README.md: -------------------------------------------------------------------------------- 1 | The files in here are required when running automated tests on the ports. You can ignore them. -------------------------------------------------------------------------------- /port/platform/common/test_automation/amazon-freertos/configure.json: -------------------------------------------------------------------------------- 1 | { 2 | "afr_source_dir":"../..", 3 | "thing_name":"$thing_name", 4 | "wifi_ssid":"$wifi_ssid", 5 | "wifi_password":"$wifi_password", 6 | "wifi_security":"$wifi_security" 7 | } -------------------------------------------------------------------------------- /port/platform/common/unity/cellular_port_unity_addons.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 u-blox Cambourne Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /* This file implements a mechanism to run a series of Unity tests, 18 | * learning from the implementation of the esp-idf unity component, 19 | * which in turn learned it from the catch framework. 20 | * It may be included in a build for a platform which includes no 21 | * unit test framework of its own. 22 | */ 23 | 24 | #ifdef CELLULAR_CFG_OVERRIDE 25 | # include "cellular_cfg_override.h" // For a customer's configuration override 26 | #endif 27 | #include "cellular_port_clib.h" 28 | #include "cellular_port.h" 29 | #include "cellular_port_test_platform_specific.h" 30 | #include "cellular_port_unity_addons.h" 31 | 32 | /* ---------------------------------------------------------------- 33 | * COMPILE-TIME MACROS 34 | * -------------------------------------------------------------- */ 35 | 36 | /* ---------------------------------------------------------------- 37 | * TYPES 38 | * -------------------------------------------------------------- */ 39 | 40 | // Linked list anchor. 41 | static CellularPortUnityTestDescription_t *gpTestList = NULL; 42 | 43 | /* ---------------------------------------------------------------- 44 | * VARIABLES 45 | * -------------------------------------------------------------- */ 46 | 47 | /* ---------------------------------------------------------------- 48 | * STATIC FUNCTIONS 49 | * -------------------------------------------------------------- */ 50 | 51 | // Run a test. 52 | void runTest(const CellularPortUnityTestDescription_t *pTest, 53 | const char *pPrefix) 54 | { 55 | UNITY_PRINT_EOL(); 56 | UnityPrint(pPrefix); 57 | UnityPrint("Running "); 58 | UnityPrint(pTest->pName); 59 | UnityPrint("..."); 60 | UNITY_PRINT_EOL(); 61 | UNITY_OUTPUT_FLUSH(); 62 | 63 | Unity.TestFile = pTest->pFile; 64 | Unity.CurrentDetail1 = pTest->pGroup; 65 | UnityDefaultTestRun(pTest->pFunction, pTest->pName, pTest->line); 66 | } 67 | 68 | /* ---------------------------------------------------------------- 69 | * PUBLIC FUNCTIONS 70 | * -------------------------------------------------------------- */ 71 | 72 | // Add a test to the list. 73 | void cellularPortUnityTestRegister(CellularPortUnityTestDescription_t *pDescription) 74 | { 75 | CellularPortUnityTestDescription_t **ppTest = &gpTestList; 76 | 77 | while (*ppTest != NULL) { 78 | ppTest = &((*ppTest)->pNext); 79 | } 80 | *ppTest = pDescription; 81 | } 82 | 83 | // Print out the test names and groups 84 | void cellularPortUnityPrintAll(const char *pPrefix) 85 | { 86 | const CellularPortUnityTestDescription_t *pTest = gpTestList; 87 | size_t count = 0; 88 | char buffer[16]; 89 | 90 | while (pTest != NULL) { 91 | UnityPrint(pPrefix); 92 | cellularPort_snprintf(buffer, sizeof(buffer), "%3.d: ", count + 1); 93 | UnityPrint(buffer); 94 | UnityPrint(pTest->pName); 95 | UnityPrint(" ["); 96 | UnityPrint(pTest->pGroup); 97 | UnityPrint("]"); 98 | UNITY_PRINT_EOL(); 99 | pTest = pTest->pNext; 100 | count++; 101 | } 102 | UNITY_PRINT_EOL(); 103 | } 104 | 105 | // Run a named test. 106 | void cellularPortUnityRunNamed(const char *pName, 107 | const char *pPrefix) 108 | { 109 | const CellularPortUnityTestDescription_t *pTest = gpTestList; 110 | 111 | while (pTest != NULL) { 112 | if ((pName == NULL) || 113 | (cellularPort_strcmp(pTest->pName, pName) == 0)) { 114 | runTest(pTest, pPrefix); 115 | } 116 | pTest = pTest->pNext; 117 | } 118 | } 119 | 120 | // Run all of the tests whose names 121 | // begin with the given filter string. 122 | void cellularPortUnityRunFiltered(const char *pFilter, 123 | const char *pPrefix) 124 | { 125 | const CellularPortUnityTestDescription_t *pTest = gpTestList; 126 | 127 | while (pTest != NULL) { 128 | if ((pFilter == NULL) || 129 | (pCellularPort_strstr(pTest->pName, pFilter) == pTest->pName)) { 130 | runTest(pTest, pPrefix); 131 | } 132 | pTest = pTest->pNext; 133 | } 134 | } 135 | 136 | // Run all of the tests in a group. 137 | void cellularPortUnityRunGroup(const char *pGroup, 138 | const char *pPrefix) 139 | { 140 | const CellularPortUnityTestDescription_t *pTest = gpTestList; 141 | 142 | while (pTest != NULL) { 143 | if ((pGroup == NULL) || 144 | (cellularPort_strcmp(pTest->pGroup, pGroup) == 0)) { 145 | runTest(pTest, pPrefix); 146 | } 147 | pTest = pTest->pNext; 148 | } 149 | } 150 | 151 | // Run all of the tests. 152 | void cellularPortUnityRunAll(const char *pPrefix) 153 | { 154 | const CellularPortUnityTestDescription_t *pTest = gpTestList; 155 | 156 | while (pTest != NULL) { 157 | runTest(pTest, pPrefix); 158 | pTest = pTest->pNext; 159 | } 160 | } 161 | 162 | // End of file 163 | -------------------------------------------------------------------------------- /port/platform/common/unity/cellular_port_unity_addons.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 u-blox Cambourne Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _CELLULAR_PORT_UNITY_ADDONS_H_ 18 | #define _CELLULAR_PORT_UNITY_ADDONS_H_ 19 | 20 | /** This file defines some additional bits and bobs to make Unity 21 | * work for cellular. 22 | */ 23 | 24 | #include "unity.h" 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | /* ---------------------------------------------------------------- 31 | * COMPILE-TIME MACROS 32 | * -------------------------------------------------------------- */ 33 | 34 | /** Macro to map a unit test assertion to Unity. 35 | */ 36 | #define CELLULAR_PORT_UNITY_TEST_ASSERT(condition) TEST_ASSERT(condition) 37 | 38 | /** Make up a Unity unique function name. 39 | */ 40 | #define CELLULAR_PORT_UNITY_EXPAND2(x, y) x ## y 41 | #define CELLULAR_PORT_UNITY_EXPAND(x, y) CELLULAR_PORT_UNITY_EXPAND2(x, y) 42 | #define CELLULAR_PORT_UNITY_UID(x) CELLULAR_PORT_UNITY_EXPAND(x, __LINE__) 43 | 44 | /* ---------------------------------------------------------------- 45 | * TYPES 46 | * -------------------------------------------------------------- */ 47 | 48 | /** A test function. 49 | */ 50 | typedef void (*pCellularPortUnityTestFunction_t)(void); 51 | 52 | /** Full description of a test. 53 | */ 54 | typedef struct CellularPortUnityTestDescription_t { 55 | const char *pName; 56 | const char *pGroup; 57 | const pCellularPortUnityTestFunction_t pFunction; 58 | const char *pFile; 59 | int32_t line; 60 | struct CellularPortUnityTestDescription_t *pNext; 61 | } CellularPortUnityTestDescription_t; 62 | 63 | /* ---------------------------------------------------------------- 64 | * FUNCTION: TEST CASE REGISTRATION 65 | * -------------------------------------------------------------- */ 66 | 67 | /** Like it says. 68 | * 69 | * @param pDescription the test case description. 70 | */ 71 | void cellularPortUnityTestRegister(CellularPortUnityTestDescription_t *pDescription); 72 | 73 | /* ---------------------------------------------------------------- 74 | * COMPILE-TIME MACROS: TEST DEFINITION MACRO 75 | * -------------------------------------------------------------- */ 76 | 77 | /** Macro to wrap the definition of a test function and 78 | * map it to Unity. 79 | */ 80 | #define CELLULAR_PORT_UNITY_TEST_FUNCTION(name, group) \ 81 | /* Test function prototype */ \ 82 | static void CELLULAR_PORT_UNITY_UID(testFunction) (void); \ 83 | /* Use constructor attribute so that this is run during C initialisation before anything else runs */ \ 84 | static void __attribute__((constructor)) CELLULAR_PORT_UNITY_UID(testRegistrationHelper) () \ 85 | { \ 86 | /* Static description of the tests to pass to the register function */ \ 87 | static CellularPortUnityTestDescription_t CELLULAR_PORT_UNITY_UID(testDescription) = { \ 88 | .pName = name, \ 89 | .pGroup = group, \ 90 | .pFunction = &CELLULAR_PORT_UNITY_UID(testFunction), \ 91 | .pFile = __FILE__, \ 92 | .line = __LINE__, \ 93 | .pNext = NULL \ 94 | }; \ 95 | /* Call the register function with the description so it can keep a list of the tests */ \ 96 | cellularPortUnityTestRegister(&CELLULAR_PORT_UNITY_UID(testDescription)); \ 97 | } \ 98 | /* Actual start of test function */ \ 99 | static void CELLULAR_PORT_UNITY_UID(testFunction) (void) 100 | 101 | /* ---------------------------------------------------------------- 102 | * FUNCTIONS 103 | * -------------------------------------------------------------- */ 104 | 105 | /** Print out all the registered test cases. 106 | * 107 | * @param pPrefix prefix string to print at start of line. 108 | */ 109 | void cellularPortUnityPrintAll(const char *pPrefix); 110 | 111 | /** Run a named test case. 112 | * 113 | * @param pName the name of the test to run; if 114 | * NULL then all tests are run. 115 | * @param pPrefix prefix string to print at start of line. 116 | */ 117 | void cellularPortUnityRunNamed(const char *pName, 118 | const char *pPrefix); 119 | 120 | /** Run all of the tests whose names begin 121 | * with the given filter string. 122 | * 123 | * @param pFilter the filter string; if NULL then all 124 | * tests are run. 125 | * @param pPrefix prefix string to print at start of line. 126 | */ 127 | void cellularPortUnityRunFiltered(const char *pFilter, 128 | const char *pPrefix); 129 | 130 | /** Run all of the tests in a group. 131 | * 132 | * @param pGroup the name of the group to run; if 133 | * NULL then all groups are run. 134 | * @param pPrefix prefix string to print at start of line. 135 | */ 136 | void cellularPortUnityRunGroup(const char *pGroup, 137 | const char *pPrefix); 138 | 139 | /** Run all the registered test cases. 140 | * 141 | * @param pPrefix prefix string to print at start of line. 142 | */ 143 | void cellularPortUnityRunAll(const char *pPrefix); 144 | 145 | #ifdef __cplusplus 146 | } 147 | #endif 148 | 149 | #endif // _CELLULAR_PORT_UNITY_ADDONS_H_ 150 | 151 | // End of file 152 | -------------------------------------------------------------------------------- /port/platform/common/unity/unity_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 u-blox Cambourne Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _UNITY_CONFIG_H_ 18 | #define _UNITY_CONFIG_H_ 19 | 20 | /** This file will be included by Unity and allows us to fiddle 21 | * with what it does. 22 | */ 23 | 24 | /* Before bringing in Unity, map its output character macro 25 | * to ours. 26 | */ 27 | #define UNITY_OUTPUT_CHAR(x) cellularPortLogF("%c", x) 28 | #define UNITY_OUTPUT_CHAR_HEADER_DECLARATION cellularPortLogF(const char *pFormat, ...) 29 | 30 | #endif // _UNITY_CONFIG_H_ 31 | 32 | // End of file 33 | -------------------------------------------------------------------------------- /port/platform/espressif/esp32/README.md: -------------------------------------------------------------------------------- 1 | These directories provide the implementation of the porting layer on the Espressif ESP32 platform plus the associated build and board configuration information: 2 | 3 | - `cfg`: contains the single file `cellular_cfg_hw.h` which provides default configuration for the u-blox `WHRE` board which includes the `NINA-W1` module, inside of which is an ESP32 chip, and a `SARA-R4` module. 4 | - `sdk`: contains the files to build/test for the Espressif ESP32 platform: 5 | - `esp-idf`: contains the build and test files for the native ESP32 SDK, ESP-IDF. 6 | - `amazon-freertos`: contains the build files for Amazon FreeRTOS, providing ESP32 support in that SDK. 7 | - `src`: contains the implementation of the porting layers for ESP32. -------------------------------------------------------------------------------- /port/platform/espressif/esp32/cfg/cellular_cfg_hw_platform_specific.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 u-blox Cambourne Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _CELLULAR_CFG_HW_PLATFORM_SPECIFIC_H_ 18 | #define _CELLULAR_CFG_HW_PLATFORM_SPECIFIC_H_ 19 | 20 | /* No #includes allowed here */ 21 | 22 | /* This header file contains hardware configuration information for 23 | * the cellular WHRE platform which is an ESP32 platform. 24 | */ 25 | 26 | /* ---------------------------------------------------------------- 27 | * COMPILE-TIME MACROS FOR THE "WHRE" BOARD: MISC 28 | * -------------------------------------------------------------- */ 29 | 30 | #ifndef CELLULAR_CFG_UART 31 | /** The UART HW block to use inside the ESP32 chip. 32 | */ 33 | # define CELLULAR_CFG_UART 1 34 | #endif 35 | 36 | #ifndef CELLULAR_CFG_RTS_THRESHOLD 37 | /** The buffer threshold at which RTS is de-asserted, indicating the 38 | * cellular module should stop sending data to us. Must be defined 39 | * if CELLULAR_CFG_PIN_RTS is not -1. 40 | * Must be less than UART_FIFO_LEN, which is 128. 41 | */ 42 | # define CELLULAR_CFG_RTS_THRESHOLD 100 43 | #endif 44 | 45 | /* ---------------------------------------------------------------- 46 | * COMPILE-TIME MACROS FOR THE "WHRE" BOARD: PINS 47 | * -------------------------------------------------------------- */ 48 | 49 | #ifndef CELLULAR_CFG_PIN_ENABLE_POWER 50 | /** The ESP32 GPIO output that enables power to the cellular module on 51 | * the WHRE demo board. 52 | * -1 is used where there is no such connection. 53 | */ 54 | # define CELLULAR_CFG_PIN_ENABLE_POWER 2 55 | #endif 56 | 57 | #ifndef CELLULAR_CFG_PIN_PWR_ON 58 | /** The ESP32 GPIO output that that is connected to the PWR_ON pin of 59 | * the cellular module on the WHRE demo board. 60 | */ 61 | # define CELLULAR_CFG_PIN_PWR_ON 25 62 | #endif 63 | 64 | #ifndef CELLULAR_CFG_PIN_VINT 65 | /** The ESP32 GPIO input that is connected to the VInt pin of the 66 | * cellular module on the WHRE demo board. 67 | * -1 is used where there is no such connection. 68 | */ 69 | # define CELLULAR_CFG_PIN_VINT 36 70 | #endif 71 | 72 | #ifndef CELLULAR_CFG_PIN_TXD 73 | /** The ESP32 GPIO output pin that sends UART data to the cellular 74 | * module on the WHRE demo board. 75 | */ 76 | # define CELLULAR_CFG_PIN_TXD 4 77 | #endif 78 | 79 | #ifndef CELLULAR_CFG_PIN_RXD 80 | /** The ESP32 GPIO input pin that receives UART data from the cellular 81 | * module on the WHRE demo board. 82 | */ 83 | # define CELLULAR_CFG_PIN_RXD 15 84 | #endif 85 | 86 | #ifndef CELLULAR_CFG_PIN_CTS 87 | /** The ESP32 GPIO input pin that the cellular modem will use to 88 | * indicate that data can be sent to it for the WHRE demo board. 89 | * -1 is used where there is no such connection. 90 | */ 91 | # define CELLULAR_CFG_PIN_CTS -1 92 | #endif 93 | 94 | #ifndef CELLULAR_CFG_PIN_RTS 95 | /** The ESP32 GPIO output pin that tells the cellular modem that it 96 | * can send more data to NINA-W1 on the WHRE demo board. 97 | * -1 is used where there is no such connection. 98 | * If this is *not* -1 then be sure to set up 99 | * CELLULAR_CFG_RTS_THRESHOLD also. 100 | */ 101 | # define CELLULAR_CFG_PIN_RTS -1 102 | #endif 103 | 104 | #endif // _CELLULAR_CFG_HW_PLATFORM_SPECIFIC_H_ 105 | 106 | // End of file 107 | -------------------------------------------------------------------------------- /port/platform/espressif/esp32/cfg/cellular_cfg_os_platform_specific.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 u-blox Cambourne Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _CELLULAR_CFG_OS_PLATFORM_SPECIFIC_H_ 18 | #define _CELLULAR_CFG_OS_PLATFORM_SPECIFIC_H_ 19 | 20 | /* No #includes allowed here */ 21 | 22 | /* This header file contains OS configuration information for 23 | * an ESP32 platform. 24 | */ 25 | 26 | /* ---------------------------------------------------------------- 27 | * COMPILE-TIME MACROS FOR ESP32: OS GENERIC 28 | * -------------------------------------------------------------- */ 29 | 30 | #ifndef CELLULAR_PORT_OS_PRIORITY_MIN 31 | /** The minimum task priority. 32 | * In FreeRTOS, as used on this platform, low numbers indicate 33 | * lower priority. 34 | */ 35 | # define CELLULAR_PORT_OS_PRIORITY_MIN 0 36 | #endif 37 | 38 | #ifndef CELLULAR_PORT_OS_PRIORITY_MAX 39 | /** The maximum task priority, should be less than or 40 | * equal to configMAX_PRIORITIES defined in FreeRTOSConfig.h, 41 | * which is usually set to 25. 42 | */ 43 | # define CELLULAR_PORT_OS_PRIORITY_MAX 25 44 | #endif 45 | 46 | /* ---------------------------------------------------------------- 47 | * COMPILE-TIME MACROS FOR ESP32: AT CLIENT RELATED 48 | * -------------------------------------------------------------- */ 49 | 50 | #ifndef CELLULAR_CTRL_AT_TASK_URC_STACK_SIZE_BYTES 51 | /** The stack size for the AT task that handles URCs. 52 | * Note: this size worst case for unoptimised compilation 53 | * (so that a debugger can be used sensibly) under the worst compiler. 54 | */ 55 | # define CELLULAR_CTRL_AT_TASK_URC_STACK_SIZE_BYTES (1024 * 5) 56 | #endif 57 | 58 | #ifndef CELLULAR_CTRL_AT_TASK_URC_PRIORITY 59 | /** The task priority for the URC handler. In FreeRTOS, 60 | * as used on this platform, low numbers indicate lower priority. 61 | */ 62 | # define CELLULAR_CTRL_AT_TASK_URC_PRIORITY (CELLULAR_PORT_OS_PRIORITY_MAX - 5) 63 | #endif 64 | 65 | #ifndef CELLULAR_CTRL_TASK_CALLBACK_STACK_SIZE_BYTES 66 | /** The stack size of the task in the context of which the callbacks 67 | * of AT command URCs will be run. 5 kbytes should be plenty of room. 68 | */ 69 | # define CELLULAR_CTRL_TASK_CALLBACK_STACK_SIZE_BYTES (1024 * 5) 70 | #endif 71 | 72 | #ifndef CELLULAR_CTRL_TASK_CALLBACK_PRIORITY 73 | /** The task priority for any callback made via 74 | * cellular_ctrl_at_callback(). In FreeRTOS, 75 | * as used on this platform, low numbers indicate 76 | * lower priority. The task within which main() is 77 | * run is usually set to minimum + 1, see esp_task.h. 78 | */ 79 | # define CELLULAR_CTRL_TASK_CALLBACK_PRIORITY (CELLULAR_PORT_OS_PRIORITY_MIN + 2) 80 | #endif 81 | 82 | #if (CELLULAR_CTRL_TASK_CALLBACK_PRIORITY >= CELLULAR_CTRL_AT_TASK_URC_PRIORITY) 83 | # error CELLULAR_CTRL_TASK_CALLBACK_PRIORITY must be less than CELLULAR_CTRL_AT_TASK_URC_PRIORITY 84 | #endif 85 | 86 | #endif // _CELLULAR_CFG_OS_PLATFORM_SPECIFIC_H_ 87 | 88 | // End of file 89 | -------------------------------------------------------------------------------- /port/platform/espressif/esp32/sdk/amazon-freertos/README.md: -------------------------------------------------------------------------------- 1 | # Introduction 2 | This directory contains the build infrastructure for the Espressif ESP32 platform under Amazon FreeRTOS. The Amazon FreeRTOS network manager has no concept of a cellular network connection and so this repo replaces the existing Wifi connectivity under Amazon FreeRTOS with cellular connectivity. 3 | 4 | # Usage 5 | Follow the instructions to set up Amazon FreeRTOS and build/run it on the ESP32 platform. Ensure that you can successfully run the standard Wifi-based demonstration of the default "Hello MQTT" demo. 6 | 7 | https://docs.aws.amazon.com/freertos/latest/userguide/getting_started_espressif.html 8 | 9 | Clone this repo to the same level in your directory tree as Amazon FreeRTOS, i.e.: 10 | 11 | ``` 12 | .. 13 | . 14 | amazon-freertos 15 | cellular 16 | ``` 17 | 18 | Note: you may put this repo in a different location but if you do so you will need to edit the definition of `cellular_dir` in the `CMakeLists.txt` file of this directory. 19 | 20 | With this done, find the `CMakeLists.txt` file in the `vendors\espressif\boards\esp32` directory of Amazon FreeRTOS. Make a back-up of it and then overwrite it with the `CMakeLists.txt` file from this directory. 21 | 22 | To define which cellular module you are using (e.g. one of `CELLULAR_CFG_MODULE_SARA_R412M_03B` or `CELLULAR_CFG_MODULE_SARA_R5`). Create an environment variaable called `CELLULAR_FLAGS` and set it to be that module name in the form: 23 | 24 | ``` 25 | set CELLULAR_FLAGS=-DCELLULAR_CFG_MODULE_SARA_R5 26 | ``` 27 | 28 | Clumsy, I know, but it was the only way I could find to pass adhoc conditional compilation flags into CMake via the command-line. You can overried any other parameters in there, it's just a list, so for instance if you wanted to sat that there's no "enable power" capability on your board you might use: 29 | 30 | ``` 31 | set CELLULAR_FLAGS=-DCELLULAR_CFG_MODULE_SARA_R5 -DCELLULAR_CFG_PIN_ENABLE_POWER=-1 32 | ``` 33 | 34 | Follow the Amazon FreeRTOS build instructions for your platform but add the parameter `-DAFR_ESP_LWIP=1` to the CMake build line, i.e. so that the environment variable `AFR_ESP_LWIP` is defined for the compiler and set to 1. On Windows this would be something like: 35 | 36 | ``` 37 | cmake -DVENDOR=espressif -DBOARD=esp32_wrover_kit -DCOMPILER=xtensa-esp32 -DAFR_ESP_LWIP=1 -GNinja -S . -B build 38 | ``` 39 | 40 | This tells Amazon FreeRTOS to link in the LWIP API, through which the code in this repository provides a cellular driver. 41 | 42 | The SSID field of the Wifi API is re-used to provide the APN for cellular. A default APN will be supplied by the cellular network and hence this field must usually be left empty. You will have followed the Amazon FreeRTOS instructions to edit the file `tools\aws_config_quick_start\configure.json` to contain your Wifi network SSID etc. and hence the field `wifi_ssid` must be changed to an empty string once more. You can change this in `configure.json` however it won't have any effect, the value will have already been written into `demos\include\aws_clientcredential.h` by the quick-start script so you need to go into `aws_clientcredential.h` and change it there. 43 | 44 | If you do have a specific APN, e.g. for some specific/feature from the network, then enter that APN in the field instead. The other fields in `configure.json` can be left as they are. 45 | 46 | Continue following the Amazon FreeRTOS instructions to generate the binary and download it to the ESP32 platform. 47 | 48 | During the build, check that you see a line something like the following somewhere near the start of the build: 49 | 50 | ``` 51 | cellular: added -DYOUR_FLAGS_HERE due to environment variable CELLULAR_FLAGS. 52 | ``` 53 | 54 | If you do not then the build has not picked up the `CELLULAR_FLAGS` environment variable for some reason. Best delete the build directory to clear out the CMake stuff and try again. 55 | 56 | When you run the "Hello MQTT" demo it will now run over cellular instead of Wifi. -------------------------------------------------------------------------------- /port/platform/espressif/esp32/sdk/esp-idf/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # The APIs 2 | set(COMPONENT_ADD_INCLUDEDIRS 3 | # The API for the porting layer 4 | "../../../../../api" 5 | # The API for the control interface 6 | "../../../../../../ctrl/api" 7 | # The API for the data (sockets) interface 8 | "../../../../../../sock/api" 9 | # The API for the MQTT interface 10 | "../../../../../../mqtt/api" 11 | # The generic configuration files 12 | "../../../../../../cfg" 13 | # The platform specific configuration files 14 | "../../cfg") 15 | 16 | # The implementations of the APIs 17 | set(COMPONENT_SRCS 18 | # The control interface 19 | "../../../../../../ctrl/src/cellular_ctrl.c" 20 | "../../../../../../ctrl/src/cellular_ctrl_at.c" 21 | # The data (sockets) interface 22 | "../../../../../../sock/src/cellular_sock.c" 23 | # The MQTT interface 24 | "../../../../../../mqtt/src/cellular_mqtt.c" 25 | # The C library portion of the porting layer, 26 | # which can be used unchanged on this platform 27 | "../../../../../clib/cellular_port_clib.c" 28 | # The porting layer 29 | "../../src/cellular_port.c" 30 | "../../src/cellular_port_debug.c" 31 | "../../src/cellular_port_gpio.c" 32 | "../../src/cellular_port_os.c" 33 | "../../src/cellular_port_uart.c") 34 | 35 | # The private include directories for the above 36 | set(COMPONENT_PRIV_INCLUDEDIRS "../../../../../../ctrl/src" 37 | "../../../../../../sock/src" 38 | "../../../../../../mqtt/src" 39 | "../../../../../clib" 40 | "../../src") 41 | register_component() 42 | 43 | if (DEFINED ENV{CELLULAR_FLAGS}) 44 | separate_arguments(CELLULAR_FLAGS NATIVE_COMMAND "$ENV{CELLULAR_FLAGS}") 45 | target_compile_options(${COMPONENT_TARGET} PUBLIC ${CELLULAR_FLAGS}) 46 | message("cellular: added ${CELLULAR_FLAGS} due to environment variable CELLULAR_FLAGS.") 47 | endif() -------------------------------------------------------------------------------- /port/platform/espressif/esp32/sdk/esp-idf/README.md: -------------------------------------------------------------------------------- 1 | # Introduction 2 | This directory contains the build infrastructure for the native Espressif ESP32 platform build system, AKA ESP-IDF. 3 | 4 | # SDK Installation 5 | Follow the instructions to build for the ESP32 platform. Note that this will use the very latest v4 Espressif environment, rather than the old v3.3 stuff used by the Amazon FreeRTOS SDK. 6 | 7 | https://docs.espressif.com/projects/esp-idf/en/latest/get-started/index.html#get-started-step-by-step 8 | 9 | Only building/running the unit tests (which test absolutely everything) are supported at this moment. 10 | 11 | # Running Examples And Tests 12 | To build the examples and the unit tests, you first need to define which module you are using (e.g. one of `CELLULAR_CFG_MODULE_SARA_R412M_03B` or `CELLULAR_CFG_MODULE_SARA_R5`). To do this, create an environment variable called `CELLULAR_FLAGS` and set it to be that module name in the form: 13 | 14 | ``` 15 | set CELLULAR_FLAGS=-DCELLULAR_CFG_MODULE_SARA_R5 16 | ``` 17 | 18 | Clumsy, I know, but it was the only way I could find to pass adhoc conditional compilation flags into CMake via the command-line. You can override any other parameters in there, it's just a list, so for instance if you wanted to say that there's no "enable power" capability on your board you might use: 19 | 20 | ``` 21 | set CELLULAR_FLAGS=-DCELLULAR_CFG_MODULE_SARA_R5 -DCELLULAR_CFG_PIN_ENABLE_POWER=-1 22 | ``` 23 | 24 | With this done, `cd` to the `unit_test` directory and execute the following: 25 | 26 | ``` 27 | idf.py -p COMx -D TEST_COMPONENTS="cellular_tests" flash monitor 28 | ``` 29 | 30 | ...where `COMx` is replaced by the COM port to which your ESP32 board is attached. The command adds this directory to ESP-IDF as an ESP-IDF component and requests that the examples and tests for this component are built, downloaded to the board and run. 31 | 32 | During the build, check that you see a line something like the following somewhere near the start of the build: 33 | 34 | ``` 35 | cellular: added -DYOUR_FLAGS_HERE due to environment variable CELLULAR_FLAGS. 36 | cellular_tests: added -DYOUR_FLAGS_HERE due to environment variable CELLULAR_FLAGS. 37 | ``` 38 | 39 | e.g.: 40 | 41 | ``` 42 | -- Adding linker script C:/projects/esp32/cellular/port/platform/espressif/esp32/sdk/esp-idf/unit_test/build/esp-idf/esp32/esp32_out.ld 43 | -- Adding linker script C:/projects/esp32/esp-idf/components/esp32/ld/esp32.rom.ld 44 | -- Adding linker script C:/projects/esp32/esp-idf/components/esp32/ld/esp32.peripherals.ld 45 | -- Adding linker script C:/projects/esp32/esp-idf/components/esp32/ld/esp32.rom.libgcc.ld 46 | -- Adding linker script C:/projects/esp32/esp-idf/components/esp32/ld/esp32.rom.spiram_incompatible_fns.ld 47 | cellular: added -DCELLULAR_CFG_MODULE_SARA_R5;-DCELLULAR_CFG_PIN_RXD=19;-DCELLULAR_CFG_PIN_TXD=21;-DCELLULAR_CFG_PIN_PWR_ON=26;-DCELLULAR_CFG_PIN_VINT=-1;-DCELLULAR_CFG_PIN_ENABLE_POWER=-1 due to environment variable CELLULAR_FLAGS. 48 | cellular_tests: added -DCELLULAR_CFG_MODULE_SARA_R5;-DCELLULAR_CFG_PIN_RXD=19;-DCELLULAR_CFG_PIN_TXD=21;-DCELLULAR_CFG_PIN_PWR_ON=26;-DCELLULAR_CFG_PIN_VINT=-1;-DCELLULAR_CFG_PIN_ENABLE_POWER=-1 due to environment variable CELLULAR_FLAGS. 49 | ``` 50 | 51 | If you do not then the build has not picked up the `CELLULAR_FLAGS` environment variable for some reason. Try running it again and adding `reconfigure` to the `idf.py` command-line, i.e.: 52 | 53 | ``` 54 | idf.py -p COMx -D TEST_COMPONENTS="cellular_tests" flash monitor reconfigure 55 | ``` 56 | 57 | When the code has built and downloaded, the Espressif monitor terminal will be launced on the same `COMx` port at 115200 baud and the board will be reset. If you prefer to use your own serial terminal program then omit `monitor` from the command line above and launch your own serial terminal program instead. You should see a prompt: 58 | 59 | ``` 60 | Press ENTER to see the list of tests. 61 | ``` 62 | 63 | Press ENTER and all of the examples and the tests will be listed, something like: 64 | 65 | ``` 66 | Here's the test menu, pick your combo: 67 | (1) "initialisation" [ctrl] 68 | (2) "initialisation" [port] 69 | 70 | Enter test for running. 71 | ``` 72 | 73 | Press 1 followed by ENTER to run example or test number 1, \* to run all, etc. 74 | 75 | # Tracing Guru Meditation Errors (Processor Exceptions) 76 | Good advice on tracing the cause of processor exceptions can be found [here](https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/fatal-errors.html). Note that viewing the debug stream from the target in the ESP-IDF monitor program (i.e. with `monitor` as one of the parameters to `idf.py`) will give you file/line numbers for the back-trace immediately. If you don't happen to be running the ESP-IDF monitor program when the error occurs, you can decode addresses to file/line numbers with: 77 | 78 | `xtensa-esp32-elf-addr2line -pfiaC -e <.elf file> ADDRESS` 79 | 80 | ...where `<.elf file>` is replaced by the path to the `.elf` file created by the build process; for example, if you are running unit tests this will be `build/unit-test-app.elf`. 81 | 82 | If you're getting nowhere, you can compile your code with GDB stub switched on (under `ESP32 Specific` in `menuconfig`). When an exception is hit the target halts and waits for you to connect GDB: if you're in the `monitor` this should happen automatically, otherwise exit any terminal program you are using and invoke ESP32 GDB instead on the same port with: 83 | 84 | `xtensa-esp32-elf-gdb -ex "set serial baud 912600" -ex "target remote COMx" -ex interrupt <.elf file>` 85 | 86 | ...where `COMx` is replaced by the COM port you are using (e.g. in my case `\\.\COM17`) and `<.elf file>` is replaced by the path to the `.elf` file created by the build process. IMPORTANT: if your COM port is higher than 9 then when invoking `xtensa-esp32-elf-gdb`, or when invoking `monitor` to invoke subsequently invoke GDB correctly, you must put `\\.\` in front of the COM port name; this is because `xtensa-esp32-elf-gdb` uses the Windows serial port API and that's just the way it works. IMPORTANT: if you are working from Windows and with a WHRE demo board in a development carrier which has RTS/CTS wired to reset `NINA-W1` you will need to have this board modified to NOT do that for this GDB stub thing to work. This is because, between running applications, Windows sets the flow control lines to a state which resets `NINA-W1`, so between switching from `monitor` to `xtensa-esp32-elf-gdb` the device will have been reset. 87 | 88 | Anyway, once at the GDB prompt you can enter any [GDB command](https://darkdust.net/files/GDB%20Cheat%20Sheet.pdf) to look around at memory, though you can't set breakpoints/watchpoints or continue execution. HOWEVER, note that I found that `xtensa-esp32-elf-gdb` would just exit immediately under Windows 10; I had to run the Windows compatiblity troubleshooter and get that to save working settings for it (Windows 8) first. Anyway, commands like `x/ 0x400C0000` will print the contents of the first location in RTC fast memory in decimal, or `x/x 0x400C0000` will print it in hex, or `print thingy` will print the value of the variable `thingy`, or `print &thingy` will print the address of the variable `thingy`, etc. 89 | -------------------------------------------------------------------------------- /port/platform/espressif/esp32/sdk/esp-idf/unit_test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This is the project CMakeLists.txt file for the test subproject 2 | cmake_minimum_required(VERSION 3.5) 3 | 4 | # Include the body of stuff in the directory 5 | # above and the tests component from below; 6 | # main gets in automagically 7 | set(EXTRA_COMPONENT_DIRS ".." 8 | "cellular_tests") 9 | 10 | # Empty the component list, main will add just what it needs 11 | set(COMPONENTS "") 12 | 13 | # Set the components to include the tests for. 14 | # This is intended to be overriden in the CMake cache 15 | # by invoking idf.py with a line of the following form: 16 | # idf.py -D TEST_COMPONENTS="cellular_test" all 17 | set(TEST_COMPONENTS "replace-me" CACHE STRING "Component to test") 18 | 19 | include($ENV{IDF_PATH}/tools/cmake/project.cmake) 20 | project(cellular-test) -------------------------------------------------------------------------------- /port/platform/espressif/esp32/sdk/esp-idf/unit_test/cellular_tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # I know this looks a bit mad but to persaude the ESP-IDF 2 | # tools to pick this up as a test component it needs 3 | # this directory level as the main component with the 4 | # stuff in the test sub-directory as the tests. 5 | set(COMPONENT_SRCS "") 6 | set(COMPONENT_ADD_INCLUDEDIRS "test") 7 | set(COMPONENT_REQUIRES "esp32" "esptool_py" "unity") 8 | register_component() -------------------------------------------------------------------------------- /port/platform/espressif/esp32/sdk/esp-idf/unit_test/cellular_tests/component.mk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/u-blox/cellular/85ed70ef362666edea806e7196c4ea4fd39f55fb/port/platform/espressif/esp32/sdk/esp-idf/unit_test/cellular_tests/component.mk -------------------------------------------------------------------------------- /port/platform/espressif/esp32/sdk/esp-idf/unit_test/cellular_tests/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # For this platform we can simply bring in the generic test 2 | # source code and map it to the unity framework used by 3 | # Espressif through the macros in cellular_port_test.h 4 | set(COMPONENT_SRCS "../../../../../../../../../ctrl/test/cellular_ctrl_test.c" 5 | "../../../../../../../../../sock/test/cellular_sock_test.c" 6 | "../../../../../../../../../mqtt/test/cellular_mqtt_test.c" 7 | "../../../../../../../../test/cellular_port_test.c" 8 | "../../../../../../../../../example/thingstream_secured/main.c") 9 | set(COMPONENT_ADD_INCLUDEDIRS "." 10 | "../../../../../../../../../ctrl/api" 11 | "../../../../../../../../../sock/api" 12 | "../../../../../../../../../mqtt/api" 13 | "../../../../../../../../../port/api" 14 | "../../../../../../../../../cfg" 15 | "../../../../../../../../api" 16 | "../../../../../cfg" 17 | "../../../../../src") 18 | set(COMPONENT_REQUIRES "esp32" "esptool_py" "unity") 19 | 20 | register_component() 21 | 22 | if (DEFINED ENV{CELLULAR_FLAGS}) 23 | separate_arguments(CELLULAR_FLAGS NATIVE_COMMAND "$ENV{CELLULAR_FLAGS}") 24 | target_compile_options(${COMPONENT_TARGET} PUBLIC ${CELLULAR_FLAGS}) 25 | message("cellular_tests: added ${CELLULAR_FLAGS} due to environment variable CELLULAR_FLAGS.") 26 | endif() -------------------------------------------------------------------------------- /port/platform/espressif/esp32/sdk/esp-idf/unit_test/cellular_tests/test/cellular_port_test_platform_specific.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 u-blox Cambourne Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _CELLULAR_PORT_TEST_PLATFORM_SPECIFIC_H_ 18 | #define _CELLULAR_PORT_TEST_PLATFORM_SPECIFIC_H_ 19 | 20 | /* Only bring in #includes specifically related to the test framework */ 21 | 22 | #include "unity.h" 23 | 24 | /** Porting layer for test execution for the Espressif platform. 25 | * Since test execution is often macro-ised rather than 26 | * function-calling this header file forms part of the platform 27 | * test source code rather than pretending to be a generic API. 28 | */ 29 | 30 | /* ---------------------------------------------------------------- 31 | * COMPILE-TIME MACROS: UNITY RELATED 32 | * -------------------------------------------------------------- */ 33 | 34 | /** Macro to wrap the definition of a test function and 35 | * map it to unity. 36 | */ 37 | #define CELLULAR_PORT_TEST_FUNCTION(func, name, group) TEST_CASE(name, \ 38 | group) 39 | 40 | /** Macro to wrap a test assertion and map it to unity. 41 | */ 42 | #define CELLULAR_PORT_TEST_ASSERT(condition) TEST_ASSERT(condition) 43 | 44 | /* ---------------------------------------------------------------- 45 | * COMPILE-TIME MACROS: OS RELATED 46 | * -------------------------------------------------------------- */ 47 | 48 | /** The stack size to use for the test task created during OS testing. 49 | */ 50 | #define CELLULAR_PORT_TEST_OS_TASK_STACK_SIZE_BYTES 2048 51 | 52 | /** The task priority to use for the task created during OS 53 | * testing: make sure that the priority of the task RUNNING 54 | * the tests is lower than this. In FreeRTOS, as used on this 55 | * platform, low numbers indicate lower priority. 56 | */ 57 | #define CELLULAR_PORT_TEST_OS_TASK_PRIORITY (CELLULAR_PORT_OS_PRIORITY_MIN + 5) 58 | 59 | /** The stack size to use for the test task created during sockets testing. 60 | */ 61 | #define CELLULAR_PORT_TEST_SOCK_TASK_STACK_SIZE_BYTES (1024 * 5) 62 | 63 | /** The priority to use for the test task created during sockets testing; 64 | * lower priority than the URC handler. In FreeRTOS, as used on this 65 | * platform, low numbers indicate lower priority. 66 | */ 67 | #define CELLULAR_PORT_TEST_SOCK_TASK_PRIORITY (CELLULAR_CTRL_AT_TASK_URC_PRIORITY - 1) 68 | 69 | /* ---------------------------------------------------------------- 70 | * COMPILE-TIME MACROS: HW RELATED 71 | * -------------------------------------------------------------- */ 72 | 73 | /** Pin A for GPIO testing: will be used as an output and 74 | * must be connected to pin B via a 1k resistor. 75 | */ 76 | #ifndef CELLULAR_PORT_TEST_PIN_A 77 | # define CELLULAR_PORT_TEST_PIN_A 33 78 | #endif 79 | 80 | /** Pin B for GPIO testing: will be used as both an input and 81 | * and open drain output and must be connected both to pin A via 82 | * a 1k resistor and directly to pin C. 83 | */ 84 | #ifndef CELLULAR_PORT_TEST_PIN_B 85 | # define CELLULAR_PORT_TEST_PIN_B 32 86 | #endif 87 | 88 | /** Pin C for GPIO testing: must be connected to pin B, 89 | * will be used as an input only. 90 | */ 91 | #ifndef CELLULAR_PORT_TEST_PIN_C 92 | # define CELLULAR_PORT_TEST_PIN_C 35 93 | #endif 94 | 95 | /** UART HW block for UART driver testing. 96 | */ 97 | #ifndef CELLULAR_PORT_TEST_UART 98 | # define CELLULAR_PORT_TEST_UART 2 99 | #endif 100 | 101 | /** Handshake threshold for UART testing. 102 | */ 103 | #ifndef CELLULAR_PORT_TEST_UART_RTS_THRESHOLD 104 | # define CELLULAR_PORT_TEST_UART_RTS_THRESHOLD 100 105 | #endif 106 | 107 | /** Tx pin for UART testing: should be connected to the Rx UART pin. 108 | */ 109 | #ifndef CELLULAR_PORT_TEST_PIN_UART_TXD 110 | # define CELLULAR_PORT_TEST_PIN_UART_TXD 13 111 | #endif 112 | 113 | /** Rx pin for UART testing: should be connected to the Tx UART pin. 114 | */ 115 | #ifndef CELLULAR_PORT_TEST_PIN_UART_RXD 116 | # define CELLULAR_PORT_TEST_PIN_UART_RXD 14 117 | #endif 118 | 119 | /** CTS pin for UART testing: should be connected to the RTS UART pin. 120 | */ 121 | #ifndef CELLULAR_PORT_TEST_PIN_UART_CTS 122 | # define CELLULAR_PORT_TEST_PIN_UART_CTS 26 123 | #endif 124 | 125 | /** RTS pin for UART testing: should be connected to the CTS UART pin. 126 | */ 127 | #ifndef CELLULAR_PORT_TEST_PIN_UART_RTS 128 | # define CELLULAR_PORT_TEST_PIN_UART_RTS 27 129 | #endif 130 | 131 | /* ---------------------------------------------------------------- 132 | * FUNCTIONS 133 | * -------------------------------------------------------------- */ 134 | 135 | #endif // _CELLULAR_PORT_TEST_PLATFORM_SPECIFIC_H_ 136 | 137 | // End of file 138 | -------------------------------------------------------------------------------- /port/platform/espressif/esp32/sdk/esp-idf/unit_test/cellular_tests/test/component.mk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/u-blox/cellular/85ed70ef362666edea806e7196c4ea4fd39f55fb/port/platform/espressif/esp32/sdk/esp-idf/unit_test/cellular_tests/test/component.mk -------------------------------------------------------------------------------- /port/platform/espressif/esp32/sdk/esp-idf/unit_test/component.mk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/u-blox/cellular/85ed70ef362666edea806e7196c4ea4fd39f55fb/port/platform/espressif/esp32/sdk/esp-idf/unit_test/component.mk -------------------------------------------------------------------------------- /port/platform/espressif/esp32/sdk/esp-idf/unit_test/main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(COMPONENT_SRCS "main_test.c") 2 | set(COMPONENT_REQUIRES "esp32" "esptool_py" "unity" "test") 3 | register_component() -------------------------------------------------------------------------------- /port/platform/espressif/esp32/sdk/esp-idf/unit_test/main/component.mk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/u-blox/cellular/85ed70ef362666edea806e7196c4ea4fd39f55fb/port/platform/espressif/esp32/sdk/esp-idf/unit_test/main/component.mk -------------------------------------------------------------------------------- /port/platform/espressif/esp32/sdk/esp-idf/unit_test/main/main_test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 u-blox Cambourne Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifdef CELLULAR_CFG_OVERRIDE 18 | # include "cellular_cfg_override.h" // For a customer's configuration override 19 | #endif 20 | #include "cellular_port_clib.h" 21 | #include "cellular_port.h" 22 | #include "cellular_port_test_platform_specific.h" 23 | 24 | /* ---------------------------------------------------------------- 25 | * COMPILE-TIME MACROS 26 | * -------------------------------------------------------------- */ 27 | 28 | /* ---------------------------------------------------------------- 29 | * TYPES 30 | * -------------------------------------------------------------- */ 31 | 32 | /* ---------------------------------------------------------------- 33 | * VARIABLES 34 | * -------------------------------------------------------------- */ 35 | 36 | /* ---------------------------------------------------------------- 37 | * STATIC FUNCTIONS 38 | * -------------------------------------------------------------- */ 39 | 40 | // Do tests. 41 | static void testTask(void *pParam) 42 | { 43 | (void) pParam; 44 | 45 | unity_run_menu(); 46 | } 47 | 48 | /* ---------------------------------------------------------------- 49 | * PUBLIC FUNCTIONS 50 | * -------------------------------------------------------------- */ 51 | 52 | // Application entry point. 53 | void app_main(void) 54 | { 55 | // On this platform the OS is started automagically so we 56 | // don't need to worry about stack sizes or priority 57 | cellularPortPlatformStart(testTask, NULL, 0, 0); 58 | 59 | // Should never get here 60 | cellularPort_assert(false); 61 | } -------------------------------------------------------------------------------- /port/platform/espressif/esp32/src/cellular_port.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 u-blox Cambourne Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifdef CELLULAR_CFG_OVERRIDE 18 | # include "cellular_cfg_override.h" // For a customer's configuration override 19 | #endif 20 | #include "cellular_port_clib.h" 21 | #include "cellular_port.h" 22 | 23 | #include "esp_timer.h" // For esp_timer_get_time() 24 | 25 | /* ---------------------------------------------------------------- 26 | * COMPILE-TIME MACROS 27 | * -------------------------------------------------------------- */ 28 | 29 | /* ---------------------------------------------------------------- 30 | * TYPES 31 | * -------------------------------------------------------------- */ 32 | 33 | /* ---------------------------------------------------------------- 34 | * VARIABLES 35 | * -------------------------------------------------------------- */ 36 | 37 | /* ---------------------------------------------------------------- 38 | * STATIC FUNCTIONS 39 | * -------------------------------------------------------------- */ 40 | 41 | /* ---------------------------------------------------------------- 42 | * PUBLIC FUNCTIONS 43 | * -------------------------------------------------------------- */ 44 | 45 | // Start the platform. 46 | int32_t cellularPortPlatformStart(void (*pEntryPoint)(void *), 47 | void *pParameter, 48 | size_t stackSizeBytes, 49 | int32_t priority) 50 | { 51 | CellularPortErrorCode_t errorCode = CELLULAR_PORT_INVALID_PARAMETER; 52 | 53 | (void) stackSizeBytes; 54 | (void) priority; 55 | 56 | // RTOS is already running, just call pEntryPoint 57 | if (pEntryPoint != NULL) { 58 | errorCode = CELLULAR_PORT_PLATFORM_ERROR; 59 | pEntryPoint(pParameter); 60 | } 61 | 62 | return errorCode; 63 | } 64 | 65 | // Initialise the porting layer. 66 | int32_t cellularPortInit() 67 | { 68 | // Nothing to do 69 | return CELLULAR_PORT_SUCCESS; 70 | } 71 | 72 | // Deinitialise the porting layer. 73 | void cellularPortDeinit() 74 | { 75 | // Nothing to do 76 | } 77 | 78 | // Get the current tick converted to a time in milliseconds. 79 | int64_t cellularPortGetTickTimeMs() 80 | { 81 | return esp_timer_get_time() / 1000; 82 | } 83 | 84 | // End of file 85 | -------------------------------------------------------------------------------- /port/platform/espressif/esp32/src/cellular_port_clib_platform_specific.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 u-blox Cambourne Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _CELLULAR_PORT_CLIB_PLATFORM_SPECIFIC_H_ 18 | #define _CELLULAR_PORT_CLIB_PLATFORM_SPECIFIC_H_ 19 | 20 | /** Implementations of C library functions not available on this 21 | * platform. 22 | */ 23 | 24 | /* ---------------------------------------------------------------- 25 | * COMPILE-TIME MACROS 26 | * -------------------------------------------------------------- */ 27 | 28 | /* ---------------------------------------------------------------- 29 | * TYPES 30 | * -------------------------------------------------------------- */ 31 | 32 | /* ---------------------------------------------------------------- 33 | * FUNCTIONS 34 | * -------------------------------------------------------------- */ 35 | 36 | #endif // _CELLULAR_PORT_CLIB_PLATFORM_SPECIFIC_H_ 37 | 38 | // End of file 39 | -------------------------------------------------------------------------------- /port/platform/espressif/esp32/src/cellular_port_debug.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 u-blox Cambourne Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifdef CELLULAR_CFG_OVERRIDE 18 | # include "cellular_cfg_override.h" // For a customer's configuration override 19 | #endif 20 | #include "cellular_port_clib.h" 21 | #include "cellular_port_debug.h" 22 | 23 | #include "stdio.h" // For vprintf() 24 | 25 | /* ---------------------------------------------------------------- 26 | * COMPILE-TIME MACROS 27 | * -------------------------------------------------------------- */ 28 | 29 | /* ---------------------------------------------------------------- 30 | * TYPES 31 | * -------------------------------------------------------------- */ 32 | 33 | /* ---------------------------------------------------------------- 34 | * VARIABLES 35 | * -------------------------------------------------------------- */ 36 | 37 | /* ---------------------------------------------------------------- 38 | * STATIC FUNCTIONS 39 | * -------------------------------------------------------------- */ 40 | 41 | /* ---------------------------------------------------------------- 42 | * PUBLIC FUNCTIONS 43 | * -------------------------------------------------------------- */ 44 | 45 | // printf()-style logging. 46 | void cellularPortLogF(const char *pFormat, ...) 47 | { 48 | va_list args; 49 | va_start(args, pFormat); 50 | vprintf(pFormat, args); 51 | va_end(args); 52 | } 53 | 54 | // End of file 55 | -------------------------------------------------------------------------------- /port/platform/espressif/esp32/src/cellular_port_gpio.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 u-blox Cambourne Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifdef CELLULAR_CFG_OVERRIDE 18 | # include "cellular_cfg_override.h" // For a customer's configuration override 19 | #endif 20 | #include "cellular_port_clib.h" 21 | #include "cellular_port.h" 22 | #include "cellular_port_gpio.h" 23 | 24 | #include "driver/gpio.h" 25 | #include "driver/rtc_io.h" 26 | 27 | /* ---------------------------------------------------------------- 28 | * COMPILE-TIME MACROS 29 | * -------------------------------------------------------------- */ 30 | 31 | /* ---------------------------------------------------------------- 32 | * TYPES 33 | * -------------------------------------------------------------- */ 34 | 35 | /* ---------------------------------------------------------------- 36 | * VARIABLES 37 | * -------------------------------------------------------------- */ 38 | 39 | /* ---------------------------------------------------------------- 40 | * STATIC FUNCTIONS 41 | * -------------------------------------------------------------- */ 42 | 43 | /* ---------------------------------------------------------------- 44 | * PUBLIC FUNCTIONS 45 | * -------------------------------------------------------------- */ 46 | 47 | // Configure a GPIO. 48 | int32_t cellularPortGpioConfig(CellularPortGpioConfig_t *pConfig) 49 | { 50 | CellularPortErrorCode_t errorCode = CELLULAR_PORT_INVALID_PARAMETER; 51 | bool badConfig = false; 52 | gpio_config_t config; 53 | 54 | if (pConfig != NULL) { 55 | // Set the things that won't change 56 | config.intr_type = GPIO_PIN_INTR_DISABLE; 57 | 58 | // Set the direction and drive mode 59 | switch (pConfig->direction) { 60 | case CELLULAR_PORT_GPIO_DIRECTION_NONE: 61 | config.mode = GPIO_MODE_DISABLE; 62 | break; 63 | case CELLULAR_PORT_GPIO_DIRECTION_INPUT: 64 | config.mode = GPIO_MODE_INPUT; 65 | break; 66 | case CELLULAR_PORT_GPIO_DIRECTION_OUTPUT: 67 | config.mode = GPIO_MODE_OUTPUT; 68 | if (pConfig->driveMode == CELLULAR_PORT_GPIO_DRIVE_MODE_OPEN_DRAIN) { 69 | config.mode = GPIO_MODE_OUTPUT_OD; 70 | } 71 | break; 72 | case CELLULAR_PORT_GPIO_DIRECTION_INPUT_OUTPUT: 73 | config.mode = GPIO_MODE_INPUT_OUTPUT; 74 | if (pConfig->driveMode == CELLULAR_PORT_GPIO_DRIVE_MODE_OPEN_DRAIN) { 75 | config.mode = GPIO_MODE_INPUT_OUTPUT_OD; 76 | } 77 | break; 78 | default: 79 | badConfig = true; 80 | break; 81 | } 82 | 83 | // Set the pull up/down: 84 | // Note that pulling both up and down is apparently 85 | // valid for ESP32 86 | config.pull_down_en = 0; 87 | config.pull_up_en = 0; 88 | switch (pConfig->pullMode) { 89 | case CELLULAR_PORT_GPIO_PULL_MODE_NONE: 90 | break; 91 | case CELLULAR_PORT_GPIO_PULL_MODE_PULL_UP: 92 | config.pull_up_en = 1; 93 | break; 94 | case CELLULAR_PORT_GPIO_PULL_MODE_PULL_DOWN: 95 | config.pull_down_en = 1; 96 | break; 97 | default: 98 | badConfig = true; 99 | break; 100 | } 101 | 102 | // Set the pin 103 | config.pin_bit_mask = 1ULL << pConfig->pin; 104 | 105 | // Actually do the configuration 106 | if (!badConfig) { 107 | errorCode = CELLULAR_PORT_PLATFORM_ERROR; 108 | if (gpio_config(&config) == ESP_OK) { 109 | // If it's an output pin, set the drive capability 110 | if (((pConfig->direction == CELLULAR_PORT_GPIO_DIRECTION_OUTPUT) || 111 | (pConfig->direction == CELLULAR_PORT_GPIO_DIRECTION_INPUT_OUTPUT)) && 112 | (gpio_set_drive_capability(pConfig->pin, pConfig->driveCapability) == ESP_OK)) { 113 | errorCode = CELLULAR_PORT_SUCCESS; 114 | } else { 115 | // It's not an output pin so we're done 116 | errorCode = CELLULAR_PORT_SUCCESS; 117 | } 118 | } 119 | } 120 | } 121 | 122 | return (int32_t) errorCode; 123 | } 124 | 125 | // Set the state of a GPIO. 126 | // Note there used to be code here which tried to 127 | // handle the case of a GPIO being made to hold 128 | // its state during sleep. However, a side-effect 129 | // of doing that was that setting a GPIO when it had 130 | // not yet been made an output, so that when it was made 131 | // an output it immediately had the right level, 132 | // did not work, so that code was removed. 133 | int32_t cellularPortGpioSet(int32_t pin, int32_t level) 134 | { 135 | CellularPortErrorCode_t errorCode = CELLULAR_PORT_PLATFORM_ERROR; 136 | 137 | if (gpio_set_level(pin, level) == ESP_OK) { 138 | errorCode = CELLULAR_PORT_SUCCESS; 139 | } 140 | 141 | return (int32_t) errorCode; 142 | } 143 | 144 | // Get the state of a GPIO. 145 | int32_t cellularPortGpioGet(int32_t pin) 146 | { 147 | return gpio_get_level(pin); 148 | } 149 | 150 | // End of file 151 | -------------------------------------------------------------------------------- /port/platform/nordic/nrf52840/README.md: -------------------------------------------------------------------------------- 1 | # Introduction 2 | These directories provide the implementation of the porting layer on the Nordic NRF52840 platform plus the associated build and board configuration information: 3 | 4 | - `cfg`: contains the file `cellular_cfg_hw_platform_specific.h` which provides default configuration for an NRF52840 board connecting to a cellular module. Note that the type of cellular module is NOT specified, you must do that when you perform your build. Also in here you will find the FreeRTOS configuration header file and the `sdk_config.h` for this build. 5 | - `sdk`: contains the files to build/test for the Nordic NRF52840 platform: 6 | - `gcc`: contains the build and test files for the Nordic SDK, nRF5 under GCC. 7 | - `ses`: contains the build and test files for the Nordic SDK, nRF5 under Segger Embedded Studio. 8 | - `src`: contains the implementation of the porting layers for NRF52840. 9 | - `test`: contains the code that runs the unit tests for the cellular code on NRF52840. 10 | 11 | # Hardware Requirements 12 | This code may be run on either a Nordic NRF52840 development board or a u-blox NINA-B1 module. In either case the NRF52840 chip itself is somewhat challenged in the UART department, having only two. This code needs one to talk to the cellular module leaving one other which might already be required by a customer application. Hence this code is configured by default to send trace output over the SWDIO (AKA RTT) port which a Segger J-Link debugger can interpret (see the #Debugging section below). 13 | 14 | Such a debugger is *already* included on the NRF58240 develoment board however if you're working to a bare NF58240 chip or a bare u-blox NINA-B1 module you REALLY MUST equip yourself with a Segger [J-Link Base](https://www.segger.com/products/debug-probes/j-link/models/j-link-base/) debugger and the right cable to connect it to your board. 15 | 16 | For debugging you will need the Segger J-Link tools, of which the Windows ones can be found here: 17 | 18 | https://www.segger.com/downloads/jlink/JLink_Windows.exe 19 | 20 | If you don't have an NRF52840 board with Segger J-Link built in or you have a bare module etc. and are without a Segger J-Link box, it may be possible to fiddle with the `sdk_config.h` file down in the `cfg` directory to make it spit strings out of the spare UART instead but I don't recommended, it's hell down there. You would need to enable a UART port, switch off `NRF_LOG_BACKEND_RTT_ENABLED` and fiddle with the likes of `NRF_LOG_BACKEND_UART_ENABLED`, `NRF_LOG_BACKEND_UART_TX_PIN` and `NRF_LOG_BACKEND_UART_BAUDRATE`. Good luck! 21 | 22 | # Chip Resource Requirements 23 | This code requires the use of two `TIMER` peripherals (one for time and unfortunately another to count UART received characters) and one `UARTE` peripheral on the NRF52840 chip. The default choices are specified in `cellular_cfg_hw_platform_specific.h` and can be overriden at compile time. Note that the way the `TIMER`, actually used as a counter, has to be used with the `UARTE` requires the PPI (Programmable Peripheral Interconnect) to be enabled. 24 | 25 | # Segger RTT Trace Output 26 | To obtain trace output, start JLink Commander from a command-line with: 27 | 28 | ``` 29 | jlink -Device NRF52840_XXAA -If SWD -Speed 500 -Autoconnect 1 30 | ``` 31 | 32 | With this done, from a separate DOS box start `JLinkRTTClient` and it will find the JLink session and connect up to display trace output. The first run of the target after programming or power-on for some reason takes about 10 seconds to start and then doesn't work properly but all subsequent runs will work. There may be some character loss, hopefully minimal. 33 | 34 | To reset the target, in `jlink` user `r` to stop it and `g` to kick it off again. 35 | 36 | -------------------------------------------------------------------------------- /port/platform/nordic/nrf52840/cfg/cellular_cfg_hw_platform_specific.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 u-blox Cambourne Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _CELLULAR_CFG_HW_PLATFORM_SPECIFIC_H_ 18 | #define _CELLULAR_CFG_HW_PLATFORM_SPECIFIC_H_ 19 | 20 | /* No #includes allowed here */ 21 | 22 | /* This header file contains hardware configuration information for 23 | * a Nordic NRF52840 board. 24 | */ 25 | 26 | /* ---------------------------------------------------------------- 27 | * COMPILE-TIME MACROS FOR NRF52840: UARTE 28 | * -------------------------------------------------------------- */ 29 | 30 | #ifndef CELLULAR_CFG_UART 31 | /** The UARTE HW block to use inside the NRF52840 chip. 32 | * IMPORTANT: this code provides its own UARTE driver and hence 33 | * the UARTE chosen here must be set to 0 in sdk_config.h so that 34 | * the Nordic NRF5 driver does not use it, e.g. if the 35 | * value of CELLULAR_CFG_UART is set to 0 then NRFX_UARTE0_ENABLED 36 | * must be set to 0 in sdk_config.h. 37 | */ 38 | # define CELLULAR_CFG_UART 0 39 | #endif 40 | 41 | #ifndef CELLULAR_CFG_RTS_THRESHOLD 42 | /** The buffer threshold at which RTS is de-asserted, indicating the 43 | * cellular module should stop sending data to us. Must be defined 44 | * if CELLULAR_CFG_PIN_RTS is not -1. 45 | */ 46 | # define CELLULAR_CFG_RTS_THRESHOLD 100 47 | #endif 48 | 49 | /* ---------------------------------------------------------------- 50 | * COMPILE-TIME MACROS FOR NRF52840: TIMERS/COUNTERS 51 | * -------------------------------------------------------------- */ 52 | 53 | /** The TIMER instance to use as a ticker. Chosing 1 so as not 54 | * to conflict with SOFT_DEVICE where it is used. 55 | */ 56 | #ifndef CELLULAR_PORT_TICK_TIMER_INSTANCE 57 | # define CELLULAR_PORT_TICK_TIMER_INSTANCE 1 58 | #endif 59 | 60 | /** It is a design constraint of the NRF52840 UART that, 61 | * in order to implement continuous reception, a timer instance 62 | * is also required to count the UART received characters (since 63 | * the DMA only tells you when it has finished). Up to two 64 | * instances of the UART driver may be created, this is 65 | * the timer instance that will be used if UARTE0 is selected. 66 | */ 67 | #ifndef CELLULAR_PORT_UART_COUNTER_INSTANCE_0 68 | # define CELLULAR_PORT_UART_COUNTER_INSTANCE_0 2 69 | #endif 70 | 71 | /** It is a design constraint of the NRF52840 UART that, 72 | * in order to implement continuous reception, a timer instance 73 | * is also required to count the UART received characters (since 74 | * the DMA only tells you when it has finished). Up to two 75 | * instances of the UART driver may be created, this is 76 | * the timer instance that will be used if UARTE1 is selected. 77 | */ 78 | #ifndef CELLULAR_PORT_UART_COUNTER_INSTANCE_1 79 | # define CELLULAR_PORT_UART_COUNTER_INSTANCE_1 3 80 | #endif 81 | 82 | /* ---------------------------------------------------------------- 83 | * COMPILE-TIME MACROS FOR NRF52840: PINS 84 | * -------------------------------------------------------------- */ 85 | 86 | /* NRF52840 uses a port numbering scheme with 32 GPIO lines 87 | * on each port and two ports, so GPIO 0 you will see written as 88 | * 0.00, GPIO 31 0.31, GPIO 32 1.00 and GPIO 48 1.15. 89 | * Also, if you are using the NRF52840 DK board a load of these 90 | * have pre-assigned functions so you have to read the back of 91 | * the PCB _very_ carefully to find any that are free. In 92 | * general, port 1 is freer than port 0, hence the choices below. 93 | */ 94 | 95 | #ifndef CELLULAR_CFG_PIN_ENABLE_POWER 96 | /** The NRF52840 GPIO output that enables power to the cellular module. 97 | * -1 is used where there is no such connection. 98 | */ 99 | # define CELLULAR_CFG_PIN_ENABLE_POWER -1 100 | #endif 101 | 102 | #ifndef CELLULAR_CFG_PIN_PWR_ON 103 | /** The NRF52840 GPIO output that that is connected to the PWR_ON pin of 104 | * the cellular module. 105 | */ 106 | # define CELLULAR_CFG_PIN_PWR_ON 33 // AKA 1.01 107 | #endif 108 | 109 | #ifndef CELLULAR_CFG_PIN_VINT 110 | /** The NRF52840 GPIO input that is connected to the VInt pin of the 111 | * cellular module. 112 | * -1 is used where there is no such connection. 113 | */ 114 | # define CELLULAR_CFG_PIN_VINT -1 115 | #endif 116 | 117 | #ifndef CELLULAR_CFG_PIN_TXD 118 | /** The NRF52840 GPIO output pin that sends UART data to the cellular 119 | * module. 120 | */ 121 | # define CELLULAR_CFG_PIN_TXD 34 // AKA 1.02 122 | #endif 123 | 124 | #ifndef CELLULAR_CFG_PIN_RXD 125 | /** The NRF52840 GPIO input pin that receives UART data from the cellular 126 | * module. 127 | */ 128 | # define CELLULAR_CFG_PIN_RXD 35 // AKA 1.03 129 | #endif 130 | 131 | #ifndef CELLULAR_CFG_PIN_CTS 132 | /** The NRF52840 GPIO input pin that the cellular modem will use to 133 | * indicate that data can be sent to it. 134 | * -1 is used where there is no such connection. 135 | */ 136 | # define CELLULAR_CFG_PIN_CTS -1 137 | #endif 138 | 139 | #ifndef CELLULAR_CFG_PIN_RTS 140 | /** The NRF52840 GPIO output pin that tells the cellular modem that it 141 | * can send more data to the NRF52840 UART. 142 | * -1 is used where there is no such connection. 143 | * If this is *not* -1 then be sure to set up 144 | * CELLULAR_CFG_RTS_THRESHOLD also. 145 | */ 146 | # define CELLULAR_CFG_PIN_RTS -1 147 | #endif 148 | 149 | #endif // _CELLULAR_CFG_HW_PLATFORM_SPECIFIC_H_ 150 | 151 | // End of file 152 | -------------------------------------------------------------------------------- /port/platform/nordic/nrf52840/cfg/cellular_cfg_os_platform_specific.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 u-blox Cambourne Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _CELLULAR_CFG_OS_PLATFORM_SPECIFIC_H_ 18 | #define _CELLULAR_CFG_OS_PLATFORM_SPECIFIC_H_ 19 | 20 | /* No #includes allowed here */ 21 | 22 | /* This header file contains OS configuration information for 23 | * an NRF52840 board. 24 | */ 25 | 26 | /* ---------------------------------------------------------------- 27 | * COMPILE-TIME MACROS FOR NRF52840: OS GENERIC 28 | * -------------------------------------------------------------- */ 29 | 30 | #ifndef CELLULAR_PORT_OS_PRIORITY_MIN 31 | /** The minimum task priority. 32 | * In FreeRTOS, as used on this platform, low numbers indicate 33 | * lower priority. 34 | */ 35 | # define CELLULAR_PORT_OS_PRIORITY_MIN 0 36 | #endif 37 | 38 | #ifndef CELLULAR_PORT_OS_PRIORITY_MAX 39 | /** The maximum task priority, should be less than or 40 | * equal to configMAX_PRIORITIES defined in FreeRTOSConfig.h, 41 | * which is set to 15. 42 | */ 43 | # define CELLULAR_PORT_OS_PRIORITY_MAX 15 44 | #endif 45 | 46 | /* ---------------------------------------------------------------- 47 | * COMPILE-TIME MACROS FOR NRF52840: AT CLIENT RELATED 48 | * -------------------------------------------------------------- */ 49 | 50 | #ifndef CELLULAR_CTRL_AT_TASK_URC_STACK_SIZE_BYTES 51 | /** The stack size for the AT task that handles URCs. 52 | * Note: this size worst case for unoptimised compilation 53 | * (so that a debugger can be used sensibly) under the worst compiler. 54 | */ 55 | # define CELLULAR_CTRL_AT_TASK_URC_STACK_SIZE_BYTES (1024 * 5) 56 | #endif 57 | 58 | #ifndef CELLULAR_CTRL_AT_TASK_URC_PRIORITY 59 | /** The task priority for the URC handler. 60 | */ 61 | # define CELLULAR_CTRL_AT_TASK_URC_PRIORITY (CELLULAR_PORT_OS_PRIORITY_MAX - 5) 62 | #endif 63 | 64 | #ifndef CELLULAR_CTRL_TASK_CALLBACK_STACK_SIZE_BYTES 65 | /** The stack size of the task in the context of which the callbacks 66 | * of AT command URCs will be run. 5 kbytes should be plenty of room. 67 | */ 68 | # define CELLULAR_CTRL_TASK_CALLBACK_STACK_SIZE_BYTES (1024 * 5) 69 | #endif 70 | 71 | #ifndef CELLULAR_CTRL_TASK_CALLBACK_PRIORITY 72 | /** The task priority for any callback made via 73 | * cellular_ctrl_at_callback(). 74 | */ 75 | # define CELLULAR_CTRL_TASK_CALLBACK_PRIORITY (CELLULAR_PORT_OS_PRIORITY_MIN + 2) 76 | #endif 77 | 78 | #if (CELLULAR_CTRL_TASK_CALLBACK_PRIORITY >= CELLULAR_CTRL_AT_TASK_URC_PRIORITY) 79 | # error CELLULAR_CTRL_TASK_CALLBACK_PRIORITY must be less than CELLULAR_CTRL_AT_TASK_URC_PRIORITY 80 | #endif 81 | 82 | #endif // _CELLULAR_CFG_OS_PLATFORM_SPECIFIC_H_ 83 | 84 | // End of file 85 | -------------------------------------------------------------------------------- /port/platform/nordic/nrf52840/sdk/gcc/README.md: -------------------------------------------------------------------------------- 1 | # Introduction 2 | This directory and its sub-directories contain the build infrastructure for the Nordic NRF52840 building under GCC with Make. 3 | 4 | # SDK Installation 5 | The blog post at the link below describes how to install GCC for building the Nordic platform: 6 | 7 | https://devzone.nordicsemi.com/nordic/nordic-blog/b/blog/posts/development-with-gcc-and-eclipse 8 | 9 | However it expects you to be using Eclipse; the instructions that follow are modified to work wholly from the command-line (and, in my case, on Windows). 10 | 11 | First, install the latest version of GCC for ARM from here: 12 | 13 | https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads 14 | 15 | Next obtain a version of Make and add it to your path. I obtained a Windows version from here: 16 | 17 | http://gnuwin32.sourceforge.net/packages/make.htm 18 | 19 | Install the latest version of the NRF5 SDK from here: 20 | 21 | https://www.nordicsemi.com/Software-and-Tools/Software/nRF5-SDK 22 | 23 | If you install it to the same directory as you cloned this repo with the name `nrf5`, i.e.: 24 | 25 | ``` 26 | .. 27 | . 28 | nrf5 29 | cellular 30 | ``` 31 | 32 | ...then the builds here will find it else you will need to tell `make` about its location (more on this when you get to the sub-directories). 33 | 34 | In the `components\toolchain\gcc` sub-directory of the NRF5 installation you will find two makefiles: if you are running on Linux or OS X you need to pay attention to the `.posix` one else pay attention to the `.windows` one. Edit the appropriate makefile to set the `GNU_INSTALL_ROOT` variable to the location of the `bin` directory of your GCC installation, e.g.: 35 | 36 | ``` 37 | GNU_INSTALL_ROOT := C:/Program Files (x86)/GNU Tools ARM Embedded/9 2019-q4-major/bin/ 38 | GNU_VERSION := 9.2.1 39 | GNU_PREFIX := arm-none-eabi 40 | ``` 41 | 42 | Note the use of `/` and not `\`; no quotation marks are required but a final `/` is required. 43 | 44 | You will also need to have installed the Nordic command-line tools from here if you haven't done so already, and have these on your path: 45 | 46 | https://www.nordicsemi.com/Software-and-Tools/Development-Tools/nRF-Command-Line-Tools 47 | 48 | With this done, go to the relevant sub-directory of this directory to actually build something. 49 | 50 | Note: the examples can be built and run in the same way as the unit tests, so look in the `unit_test` directory for everything. -------------------------------------------------------------------------------- /port/platform/nordic/nrf52840/sdk/gcc/unit_test/README.md: -------------------------------------------------------------------------------- 1 | # Introduction 2 | This directory contains the unit test and examples build for Nordic NRF52840 under GCC with Make. 3 | 4 | # Usage 5 | Make sure you have followed the instructions in the directory above this to install the GCC toolchain, Make and the Nordic command-line tools. 6 | 7 | You will also need a copy of Unity, the unit test framework, which can be Git cloned from here: 8 | 9 | https://github.com/ThrowTheSwitch/Unity 10 | 11 | Clone it to the same directory level as `cellular`, i.e.: 12 | 13 | ``` 14 | .. 15 | . 16 | Unity 17 | cellular 18 | ``` 19 | 20 | Note: you may put this repo in a different location but if you do so you will need to add, for instance, `UNITY_PATH=c:/Unity` on the command-line to `make`. 21 | 22 | Likewise, if you haven't installed the NRF5 SDK at that same directory level and named it `nrf5` then you will need to add, for instance, `NRF5_PATH=c:/nrf5` on the command-line to `make`. 23 | 24 | With that done `cd` to this directory and enter: 25 | 26 | `make flash CFLAGS=-DCELLULAR_CFG_MODULE_SARA_R5` 27 | 28 | ...to build and run all examples and unit tests. If you only want to run a particular example, or a particular unit test, enter instead, for instance: 29 | 30 | `make flash CFLAGS="-DCELLULAR_CFG_MODULE_SARA_R5 -DCELLULAR_CFG_TEST_FILTER=exampleThingstreamSecured"` 31 | 32 | ...to build and run just the `exampleThingstreamSecured` example, the name being taken from the second parameter of the `CELLULAR_PORT_TEST_FUNCTION` macro for the test or example you want to run. Note the use of quotation marks (otherwise the second `-D` will appear as another parameter to `make` which will just cause it to pause for 30 seconds); do NOT put quotes round the name of the example/test. You may use a partial string, for instance: 33 | 34 | `make flash CFLAGS="-DCELLULAR_CFG_MODULE_SARA_R5 -DCELLULAR_CFG_TEST_FILTER=example"` 35 | 36 | ...will build and run all the examples. 37 | 38 | Doing the above will build the code assuming a SARA-R5 module and download it to a connected NRF52840 development board. If the pins you have connected between the NRF52840 and the cellular module are different to the defaults, just add the necessary overrides to the `CFLAGS` line, e.g.: 39 | 40 | `make flash CFLAGS="-DCELLULAR_CFG_MODULE_SARA_R5 -DCELLULAR_CFG_PIN_VINT=-1"` 41 | -------------------------------------------------------------------------------- /port/platform/nordic/nrf52840/sdk/gcc/unit_test/uart_gcc_nrf52.ld: -------------------------------------------------------------------------------- 1 | /* Linker script to configure memory regions. */ 2 | 3 | SEARCH_DIR(.) 4 | GROUP(-lgcc -lc -lnosys) 5 | 6 | MEMORY 7 | { 8 | FLASH (rx) : ORIGIN = 0x0, LENGTH = 0x100000 9 | RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x40000 10 | } 11 | 12 | SECTIONS 13 | { 14 | } 15 | 16 | SECTIONS 17 | { 18 | . = ALIGN(4); 19 | .mem_section_dummy_ram : 20 | { 21 | } 22 | .log_dynamic_data : 23 | { 24 | PROVIDE(__start_log_dynamic_data = .); 25 | KEEP(*(SORT(.log_dynamic_data*))) 26 | PROVIDE(__stop_log_dynamic_data = .); 27 | } > RAM 28 | .log_filter_data : 29 | { 30 | PROVIDE(__start_log_filter_data = .); 31 | KEEP(*(SORT(.log_filter_data*))) 32 | PROVIDE(__stop_log_filter_data = .); 33 | } > RAM 34 | 35 | } INSERT AFTER .data; 36 | 37 | SECTIONS 38 | { 39 | .mem_section_dummy_rom : 40 | { 41 | } 42 | .log_const_data : 43 | { 44 | PROVIDE(__start_log_const_data = .); 45 | KEEP(*(SORT(.log_const_data*))) 46 | PROVIDE(__stop_log_const_data = .); 47 | } > FLASH 48 | .log_backends : 49 | { 50 | PROVIDE(__start_log_backends = .); 51 | KEEP(*(SORT(.log_backends*))) 52 | PROVIDE(__stop_log_backends = .); 53 | } > FLASH 54 | .nrf_balloc : 55 | { 56 | PROVIDE(__start_nrf_balloc = .); 57 | KEEP(*(.nrf_balloc)) 58 | PROVIDE(__stop_nrf_balloc = .); 59 | } > FLASH 60 | 61 | } INSERT AFTER .text 62 | 63 | 64 | INCLUDE "nrf_common.ld" 65 | -------------------------------------------------------------------------------- /port/platform/nordic/nrf52840/sdk/ses/README.md: -------------------------------------------------------------------------------- 1 | # Introduction 2 | This directory contains the build infrastructure for Nordic NRF52840 using the Segger Embedded Studio SDK. 3 | 4 | # Usage 5 | Follow the instructions to install the development tools: 6 | 7 | https://infocenter.nordicsemi.com/topic/ug_nrf52840_dk/UG/common/nordic_tools.html 8 | 9 | Make sure you install the Segger Embedded Studio SDK, the Nordic NRF5 SDK and the Nordic command-line tools. Ensure NO SPACES in the install location of the NRF5 SDK. 10 | 11 | When you install the NRF5 SDK, if you install it to the same directory as you cloned this repo with the name `nrf5`, i.e.: 12 | 13 | ``` 14 | .. 15 | . 16 | nrf5 17 | cellular 18 | ``` 19 | 20 | ...then the builds here will find it, otherwise you will need to tell the builds where you have installed it (see below). 21 | 22 | Segger Embedded Studio (SES), as far as I can tell, is unable to adopt the value of environment variables. To get configuration values into SES you must either open the IDE and set them in the `Tools`->`Options`->`Building`->`Build`->`Global Macros` box (e.g. enter `SOME_PATH=c:/my_thing`) or, more flexibly, you can start SES from the command line and specify them with a `-D` prefix e.g.: 23 | 24 | ``` 25 | "C:\Program Files\Segger\SEGGER Embedded Studio for ARM 4.50\bin\emstudio" -D SOME_PATH=c:/my_thing 26 | ``` 27 | 28 | Note that these `-D` configuration items are NOT passed on to the compilation tools like `make` would do, they only get into SES itself as "global macros". In order to make it possible to pass things through to the compilation tools the `cellular_pca10056` project file has 10 project variables named `EXTRA0` to `EXTRA9` that *do* get passed on to the compilation tools which you can define for yourself on the command line. For instance, to effect `#define CELLULAR_CFG_PIN_ENABLE_POWER=-1`, you would do the following: 29 | 30 | ``` 31 | "C:\Program Files\Segger\SEGGER Embedded Studio for ARM 4.50\bin\emstudio" -D EXTRA0="CELLULAR_CFG_PIN_ENABLE_POWER=-1" 32 | ``` 33 | 34 | If you have installed the NRF5 SDK to somewhere other than the location mentioned above, you must set the variable `NRF5_PATH` in the command line to SES, e.g. something like: 35 | 36 | ``` 37 | "C:\Program Files\Segger\SEGGER Embedded Studio for ARM 4.50\bin\emstudio" -D NRF5_PATH=c:/nrf5 38 | ``` 39 | 40 | You must also set the type of cellular module you are using by setting the SES project variable `MODULE_TYPE`, e.g. 41 | 42 | ``` 43 | "C:\Program Files\Segger\SEGGER Embedded Studio for ARM 4.50\bin\emstudio" -D MODULE_TYPE=CELLULAR_CFG_MODULE_SARA_R5 44 | ``` 45 | 46 | If you only want to run a particular example, or a particular unit test, you would use, for instance: 47 | 48 | ``` 49 | "C:\Program Files\Segger\SEGGER Embedded Studio for ARM 4.50\bin\emstudio" -D MODULE_TYPE=CELLULAR_CFG_MODULE_SARA_R5 -D EXTRA0="CELLULAR_CFG_TEST_FILTER=exampleThingstreamSecured" 50 | ``` 51 | 52 | ...to build and run just the `exampleThingstreamSecured` example, the name being taken from the second parameter of the `CELLULAR_PORT_TEST_FUNCTION` macro for the test or example you want to run. Do NOT put quotes round the name of the example/test. You may use a partial string, for instance: 53 | 54 | ``` 55 | "C:\Program Files\Segger\SEGGER Embedded Studio for ARM 4.50\bin\emstudio" -D MODULE_TYPE=CELLULAR_CFG_MODULE_SARA_R5 -D EXTRA0="CELLULAR_CFG_TEST_FILTER=example" 56 | ``` 57 | 58 | ...would build and run all of the examples. 59 | 60 | 61 | You can run all of the examples as well as all of the unit tests using the same `unit_test` build so, to run all of the examples and unit tests, `cd` to the `unit_test` sub-directory and load the project file with a line something like: 62 | 63 | ``` 64 | "C:\Program Files\Segger\SEGGER Embedded Studio for ARM 4.50\bin\emstudio" -D NRF5_PATH=c:/nrf5 -D MODULE_TYPE=CELLULAR_CFG_MODULE_SARA_R5 cellular_pca10056.emProject 65 | ``` -------------------------------------------------------------------------------- /port/platform/nordic/nrf52840/sdk/ses/unit_test/README.md: -------------------------------------------------------------------------------- 1 | # Introduction 2 | This directory contains the example and unit test builds for Nordic NRF52840 under GCC with Segger Embedded Studio (SES). 3 | 4 | # Usage 5 | Make sure you have followed the instructions in the directory above this to install the SES and the Nordic command-line tools. 6 | 7 | You will also need a copy of Unity, the unit test framework, which can be Git cloned from here: 8 | 9 | https://github.com/ThrowTheSwitch/Unity 10 | 11 | Clone it to the same directory level as `cellular`, i.e.: 12 | 13 | ``` 14 | .. 15 | . 16 | Unity 17 | cellular 18 | ``` 19 | 20 | Note: you may put this repo in a different location but if you do so you will need to specify the path of your `Unity` directory on the command-line to SES (using `/` instead of `\`), e.g.: 21 | 22 | ``` 23 | "C:\Program Files\Segger\SEGGER Embedded Studio for ARM 4.50\bin\emstudio" -D UNITY_PATH=c:/Unity 24 | ``` 25 | 26 | Otherwise follow the instructions in the directory above this to start SES and build/run the examples or unit tests on NRF52840. -------------------------------------------------------------------------------- /port/platform/nordic/nrf52840/sdk/ses/unit_test/flash_placement.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /port/platform/nordic/nrf52840/src/cellular_port.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 u-blox Cambourne Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifdef CELLULAR_CFG_OVERRIDE 18 | # include "cellular_cfg_override.h" // For a customer's configuration override 19 | #endif 20 | #include "cellular_port_clib.h" 21 | #include "cellular_port.h" 22 | #include "cellular_port_private.h" 23 | 24 | #include "FreeRTOS.h" 25 | #include "task.h" 26 | 27 | #include "nrf_drv_clock.h" 28 | #include "nrf_log.h" 29 | #include "nrf_log_ctrl.h" 30 | #include "nrf_log_default_backends.h" 31 | 32 | 33 | /* ---------------------------------------------------------------- 34 | * COMPILE-TIME MACROS 35 | * -------------------------------------------------------------- */ 36 | 37 | /* ---------------------------------------------------------------- 38 | * TYPES 39 | * -------------------------------------------------------------- */ 40 | 41 | /* ---------------------------------------------------------------- 42 | * VARIABLES 43 | * -------------------------------------------------------------- */ 44 | 45 | // Keep track of whether we've been initialised or not. 46 | static bool gInitialised = false; 47 | 48 | /* ---------------------------------------------------------------- 49 | * STATIC FUNCTIONS 50 | * -------------------------------------------------------------- */ 51 | 52 | /* ---------------------------------------------------------------- 53 | * PUBLIC FUNCTIONS 54 | * -------------------------------------------------------------- */ 55 | 56 | // Start the platform. 57 | int32_t cellularPortPlatformStart(void (*pEntryPoint)(void *), 58 | void *pParameter, 59 | size_t stackSizeBytes, 60 | int32_t priority) 61 | { 62 | CellularPortErrorCode_t errorCode = CELLULAR_PORT_INVALID_PARAMETER; 63 | TaskHandle_t taskHandle; 64 | 65 | if (pEntryPoint != NULL) { 66 | errorCode = CELLULAR_PORT_PLATFORM_ERROR; 67 | 68 | NRF_LOG_INIT(NULL); 69 | NRF_LOG_DEFAULT_BACKENDS_INIT(); 70 | 71 | #if configTICK_SOURCE == FREERTOS_USE_RTC 72 | // If the clock has not already been started, start it 73 | nrf_drv_clock_init(); 74 | #endif 75 | // Need to have the high frequency clock 76 | // running for the UART driver, otherwise 77 | // it can drop characters at 115,200 baud. 78 | // If you do NOT use the UART driver you don't 79 | // need this line: it is put here rather than 80 | // down in the UART driver as it should be the 81 | // application's responsibility to configure 82 | // clocks, not some random driver code that 83 | // has no context. 84 | nrfx_clock_hfclk_start(); 85 | 86 | // Note that stack size is in words on the native FreeRTOS 87 | // that NRF52840 uses, hence the divide by four here. 88 | if (xTaskCreate(pEntryPoint, "EntryPoint", 89 | stackSizeBytes / 4, pParameter, 90 | priority, &taskHandle) == pdPASS) { 91 | 92 | // Activate deep sleep mode. 93 | SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; 94 | 95 | // Start the scheduler. 96 | vTaskStartScheduler(); 97 | 98 | // Should never get here 99 | } 100 | } 101 | 102 | return errorCode; 103 | } 104 | 105 | // Initialise the porting layer. 106 | int32_t cellularPortInit() 107 | { 108 | CellularPortErrorCode_t errorCode = CELLULAR_PORT_SUCCESS; 109 | 110 | if (!gInitialised) { 111 | errorCode = cellularPortPrivateInit(); 112 | gInitialised = (errorCode == 0); 113 | } 114 | 115 | return errorCode; 116 | } 117 | 118 | // Deinitialise the porting layer. 119 | void cellularPortDeinit() 120 | { 121 | if (gInitialised) { 122 | cellularPortPrivateDeinit(); 123 | gInitialised = false; 124 | } 125 | } 126 | 127 | // Get the current tick converted to a time in milliseconds. 128 | int64_t cellularPortGetTickTimeMs() 129 | { 130 | int32_t tickTime = 0; 131 | 132 | if (gInitialised) { 133 | tickTime = cellularPortPrivateGetTickTimeMs(); 134 | } 135 | 136 | return tickTime; 137 | } 138 | 139 | // End of file 140 | -------------------------------------------------------------------------------- /port/platform/nordic/nrf52840/src/cellular_port_clib_platform_specific.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 u-blox Cambourne Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _CELLULAR_PORT_CLIB_PLATFORM_SPECIFIC_H_ 18 | #define _CELLULAR_PORT_CLIB_PLATFORM_SPECIFIC_H_ 19 | 20 | /** Implementations of C library functions not available on this 21 | * platform. 22 | */ 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* ---------------------------------------------------------------- 29 | * COMPILE-TIME MACROS 30 | * -------------------------------------------------------------- */ 31 | 32 | /* ---------------------------------------------------------------- 33 | * TYPES 34 | * -------------------------------------------------------------- */ 35 | 36 | /* ---------------------------------------------------------------- 37 | * FUNCTIONS 38 | * -------------------------------------------------------------- */ 39 | 40 | /** strtok(). 41 | * 42 | * @param pStr the string to search. 43 | * @param pDelimiters the set of delimiters to look for. 44 | * @param ppSave place for this function to store context. 45 | * @return the next occurrence of pDelimiter in pStr. 46 | */ 47 | char *strtok_r(char *pStr, const char *pDelimiters, char **ppSave); 48 | 49 | #ifdef __cplusplus 50 | } 51 | #endif 52 | 53 | #endif // _CELLULAR_PORT_CLIB_PLATFORM_SPECIFIC_H_ 54 | 55 | // End of file 56 | -------------------------------------------------------------------------------- /port/platform/nordic/nrf52840/src/cellular_port_debug.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 u-blox Cambourne Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifdef CELLULAR_CFG_OVERRIDE 18 | # include "cellular_cfg_override.h" // For a customer's configuration override 19 | #endif 20 | #include "cellular_port_clib.h" 21 | #include "cellular_port_debug.h" 22 | 23 | #include "nrfx.h" 24 | #include "nrf_log.h" 25 | #include "nrf_log_ctrl.h" 26 | 27 | /* ---------------------------------------------------------------- 28 | * COMPILE-TIME MACROS 29 | * -------------------------------------------------------------- */ 30 | 31 | /* ---------------------------------------------------------------- 32 | * TYPES 33 | * -------------------------------------------------------------- */ 34 | 35 | /* ---------------------------------------------------------------- 36 | * VARIABLES 37 | * -------------------------------------------------------------- */ 38 | 39 | #if NRF_LOG_ENABLED 40 | // The logging buffer. 41 | char gLogBuffer[NRF_LOG_BUFSIZE]; 42 | #endif 43 | 44 | /* ---------------------------------------------------------------- 45 | * STATIC FUNCTIONS 46 | * -------------------------------------------------------------- */ 47 | 48 | /* ---------------------------------------------------------------- 49 | * PUBLIC FUNCTIONS 50 | * -------------------------------------------------------------- */ 51 | 52 | // printf()-style logging. 53 | // Note: this cellularPort layer does not initialise logging, 54 | // the application is expected to do that 55 | void cellularPortLogF(const char *pFormat, ...) 56 | { 57 | va_list args; 58 | 59 | va_start(args, pFormat); 60 | #if NRF_LOG_ENABLED 61 | vsnprintf(gLogBuffer, sizeof(gLogBuffer), pFormat, args); 62 | NRF_LOG_RAW_INFO("%s", gLogBuffer); 63 | NRF_LOG_FLUSH(); 64 | #else 65 | vprintf(pFormat, args); 66 | #endif 67 | 68 | va_end(args); 69 | } 70 | 71 | // End of file 72 | -------------------------------------------------------------------------------- /port/platform/nordic/nrf52840/src/cellular_port_gpio.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 u-blox Cambourne Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifdef CELLULAR_CFG_OVERRIDE 18 | # include "cellular_cfg_override.h" // For a customer's configuration override 19 | #endif 20 | #include "cellular_port_clib.h" 21 | #include "cellular_port.h" 22 | #include "cellular_port_gpio.h" 23 | 24 | #include "nrf.h" 25 | #include "nrf_gpio.h" 26 | 27 | /* ---------------------------------------------------------------- 28 | * COMPILE-TIME MACROS 29 | * -------------------------------------------------------------- */ 30 | 31 | /* ---------------------------------------------------------------- 32 | * TYPES 33 | * -------------------------------------------------------------- */ 34 | 35 | /* ---------------------------------------------------------------- 36 | * VARIABLES 37 | * -------------------------------------------------------------- */ 38 | 39 | /* ---------------------------------------------------------------- 40 | * STATIC FUNCTIONS 41 | * -------------------------------------------------------------- */ 42 | 43 | /* ---------------------------------------------------------------- 44 | * PUBLIC FUNCTIONS 45 | * -------------------------------------------------------------- */ 46 | 47 | // Configure a GPIO. 48 | int32_t cellularPortGpioConfig(CellularPortGpioConfig_t *pConfig) 49 | { 50 | CellularPortErrorCode_t errorCode = CELLULAR_PORT_INVALID_PARAMETER; 51 | bool badConfig = false; 52 | nrf_gpio_pin_dir_t direction = CELLULAR_PORT_GPIO_DIRECTION_NONE; 53 | nrf_gpio_pin_input_t input = NRF_GPIO_PIN_INPUT_DISCONNECT; 54 | nrf_gpio_pin_pull_t pullMode = NRF_GPIO_PIN_NOPULL; 55 | nrf_gpio_pin_drive_t driveMode = GPIO_PIN_CNF_DRIVE_S0S1; 56 | 57 | if (pConfig != NULL) { 58 | // Set the direction 59 | switch (pConfig->direction) { 60 | case CELLULAR_PORT_GPIO_DIRECTION_NONE: 61 | // Do nothing here, disconnect is later 62 | break; 63 | case CELLULAR_PORT_GPIO_DIRECTION_INPUT: 64 | direction = NRF_GPIO_PIN_DIR_INPUT; 65 | input = NRF_GPIO_PIN_INPUT_CONNECT; 66 | break; 67 | case CELLULAR_PORT_GPIO_DIRECTION_OUTPUT: 68 | direction = NRF_GPIO_PIN_DIR_OUTPUT; 69 | break; 70 | case CELLULAR_PORT_GPIO_DIRECTION_INPUT_OUTPUT: 71 | direction = NRF_GPIO_PIN_DIR_OUTPUT; 72 | input = NRF_GPIO_PIN_INPUT_CONNECT; 73 | break; 74 | default: 75 | badConfig = true; 76 | break; 77 | } 78 | 79 | // Set pull up/down 80 | switch (pConfig->pullMode) { 81 | case CELLULAR_PORT_GPIO_PULL_MODE_NONE: 82 | // No need to do anything 83 | break; 84 | case CELLULAR_PORT_GPIO_PULL_MODE_PULL_UP: 85 | pullMode = NRF_GPIO_PIN_PULLUP; 86 | break; 87 | case CELLULAR_PORT_GPIO_PULL_MODE_PULL_DOWN: 88 | pullMode = NRF_GPIO_PIN_PULLDOWN; 89 | break; 90 | default: 91 | badConfig = true; 92 | break; 93 | } 94 | 95 | // Set the drive strength 96 | switch (pConfig->driveCapability) { 97 | case CELLULAR_PORT_GPIO_DRIVE_CAPABILITY_WEAKEST: 98 | case CELLULAR_PORT_GPIO_DRIVE_CAPABILITY_WEAK: 99 | // No need to do anything 100 | break; 101 | case CELLULAR_PORT_GPIO_DRIVE_CAPABILITY_STRONG: 102 | case CELLULAR_PORT_GPIO_DRIVE_CAPABILITY_STRONGEST: 103 | driveMode = NRF_GPIO_PIN_H0H1; 104 | break; 105 | default: 106 | badConfig = true; 107 | break; 108 | } 109 | 110 | // Set the drive mode 111 | switch (pConfig->driveMode) { 112 | case CELLULAR_PORT_GPIO_DRIVE_MODE_NORMAL: 113 | // No need to do anything 114 | break; 115 | case CELLULAR_PORT_GPIO_DRIVE_MODE_OPEN_DRAIN: 116 | switch (driveMode) { 117 | case NRF_GPIO_PIN_S0S1: 118 | driveMode = NRF_GPIO_PIN_S0D1; 119 | break; 120 | case NRF_GPIO_PIN_H0H1: 121 | driveMode = NRF_GPIO_PIN_H0D1; 122 | break; 123 | default: 124 | badConfig = true; 125 | break; 126 | } 127 | break; 128 | default: 129 | badConfig = true; 130 | break; 131 | } 132 | 133 | // Actually do the configuration 134 | if (!badConfig) { 135 | if (pConfig->direction == CELLULAR_PORT_GPIO_DIRECTION_NONE) { 136 | nrf_gpio_input_disconnect(pConfig->pin); 137 | } else { 138 | nrf_gpio_cfg(pConfig->pin, direction, input, 139 | pullMode, driveMode, 140 | NRF_GPIO_PIN_NOSENSE); 141 | } 142 | errorCode = CELLULAR_PORT_SUCCESS; 143 | } 144 | } 145 | 146 | return (int32_t) errorCode; 147 | } 148 | 149 | // Set the state of a GPIO. 150 | int32_t cellularPortGpioSet(int32_t pin, int32_t level) 151 | { 152 | if (level != 0) { 153 | nrf_gpio_pin_set(pin); 154 | } else { 155 | nrf_gpio_pin_clear(pin); 156 | } 157 | 158 | return (int32_t) CELLULAR_PORT_SUCCESS; 159 | } 160 | 161 | // Get the state of a GPIO. 162 | int32_t cellularPortGpioGet(int32_t pin) 163 | { 164 | return nrf_gpio_pin_read(pin); 165 | } 166 | 167 | // End of file 168 | -------------------------------------------------------------------------------- /port/platform/nordic/nrf52840/src/cellular_port_private.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 u-blox Cambourne Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _CELLULAR_PORT_PRIVATE_H_ 18 | #define _CELLULAR_PORT_PRIVATE_H_ 19 | 20 | /** Stuff private to the NRF52840 porting layer. 21 | */ 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* ---------------------------------------------------------------- 28 | * COMPILE-TIME MACROS 29 | * -------------------------------------------------------------- */ 30 | 31 | // The frequency to run the timer at: nice 'n slow. 32 | // IMPORTANT: if you change this value then you also 33 | // need to change the calculation in cellularPortGetTickTimeMs() 34 | // and you need to consider the effect it has on the Rx timeout 35 | // of the UART since it is also used there. Best not to change it. 36 | #define CELLULAR_PORT_TICK_TIMER_FREQUENCY_HZ NRF_TIMER_FREQ_31250Hz; 37 | 38 | // The bit-width of the timer. 39 | #define CELLULAR_PORT_TICK_TIMER_BIT_WIDTH NRF_TIMER_BIT_WIDTH_24; 40 | 41 | // The limit of the timer in normal mode. With a frequency 42 | // of 31250 Hz this results in an overflow every 9 minutes. 43 | // IMPORTANT: if you change this value then you also 44 | // need to change the calculation in cellularPortGetTickTimeMs(). 45 | #define CELLULAR_PORT_TICK_TIMER_LIMIT_NORMAL_MODE 0xFFFFFF 46 | 47 | // The number of bits represented by 48 | // CELLULAR_PORT_TICK_TIMER_LIMIT_NORMAL_MODE. 49 | #define CELLULAR_PORT_TICK_TIMER_LIMIT_NORMAL_MODE_BITS 24 50 | 51 | // The limit of the timer in UART mode. With a frequency 52 | // of 31250 Hz this results in an overflow every 66 milliseconds. The 53 | // overflow count is a 64 bit variable so that's still rather a large 54 | // number of years. 55 | // IMPORTANT: if you change this value then you also 56 | // need to change the calculation in cellularPortGetTickTimeMs() 57 | // and you need to consider the effect it has on the Rx timeout 58 | // of the UART since it is also used there. Best not to change it. 59 | #define CELLULAR_PORT_TICK_TIMER_LIMIT_UART_MODE 0x7FF 60 | 61 | // The number of bits represented by 62 | // CELLULAR_PORT_TICK_TIMER_LIMIT_UART_MODE. 63 | #define CELLULAR_PORT_TICK_TIMER_LIMIT_UART_MODE_BITS 11 64 | 65 | // The difference between the two limits above as a bit shift. 66 | #define CELLULAR_PORT_TICK_TIMER_LIMIT_DIFF (CELLULAR_PORT_TICK_TIMER_LIMIT_NORMAL_MODE_BITS - \ 67 | CELLULAR_PORT_TICK_TIMER_LIMIT_UART_MODE_BITS) 68 | 69 | /* ---------------------------------------------------------------- 70 | * TYPES 71 | * -------------------------------------------------------------- */ 72 | 73 | /* ---------------------------------------------------------------- 74 | * FUNCTIONS 75 | * -------------------------------------------------------------- */ 76 | 77 | /** Initialise the private stuff. 78 | * 79 | * @return zero on success else negative error code. 80 | */ 81 | int32_t cellularPortPrivateInit(); 82 | 83 | /** Deinitialise the private stuff. 84 | */ 85 | void cellularPortPrivateDeinit(); 86 | 87 | /** Get the current OS tick converted to a time in milliseconds. 88 | */ 89 | int64_t cellularPortPrivateGetTickTimeMs(); 90 | 91 | /** Register a callback to be called when tick timer 92 | * overflow interrupt occurs. 93 | * 94 | * @param pCb the callback, use NULL to deregister a 95 | * previous callback. This will be 96 | * called from interrupt context and 97 | * so must do virtually nothing! 98 | * @param pCbParameter a parameter which will be passed to 99 | * pCb when it is called, may be NULL. 100 | */ 101 | void cellularPortPrivateTickTimeSetInterruptCb(void (*pCb) (void *), 102 | void *pCbParameter); 103 | 104 | /** Set the tick time into a mode where it can used 105 | * as a relatively rapid ticker for UART Rx timeouts. 106 | * This function fiddles with the timer values and so 107 | * should only be called when there is no possibility that 108 | * we might also be calling cellularPortGetTickTimeMs() 109 | * or cellularPortPrivateGetTickTimeMs(). 110 | */ 111 | void cellularPortPrivateTickTimeUartMode(); 112 | 113 | /** Set the tick time back into normal slow mode. 114 | * This function fiddles with the timer values and so 115 | * should only be called when there is no possibility that 116 | * we might also be calling cellularPortGetTickTimeMs() 117 | * or cellularPortPrivateGetTickTimeMs(). 118 | */ 119 | void cellularPortPrivateTickTimeNormalMode(); 120 | 121 | #ifdef __cplusplus 122 | } 123 | #endif 124 | 125 | #endif // _CELLULAR_PORT_PRIVATE_H_ 126 | 127 | // End of file 128 | -------------------------------------------------------------------------------- /port/platform/nordic/nrf52840/test/cellular_port_test_platform_specific.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 u-blox Cambourne Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _CELLULAR_PORT_TEST_PLATFORM_SPECIFIC_H_ 18 | #define _CELLULAR_PORT_TEST_PLATFORM_SPECIFIC_H_ 19 | 20 | /* Only bring in #includes specifically related to the test framework */ 21 | 22 | #include "cellular_port_unity_addons.h" 23 | 24 | /** Porting layer for test execution on the Nordic platform. 25 | * Since test execution is often macro-ised rather than 26 | * function-calling this header file forms part of the platform 27 | * test source code rather than pretending to be a generic API. 28 | */ 29 | 30 | /* ---------------------------------------------------------------- 31 | * COMPILE-TIME MACROS: UNITY RELATED 32 | * -------------------------------------------------------------- */ 33 | 34 | /** Macro to wrap a test assertion and map it to our Unity port. 35 | */ 36 | #define CELLULAR_PORT_TEST_ASSERT(condition) CELLULAR_PORT_UNITY_TEST_ASSERT(condition) 37 | 38 | /** Macro to wrap the definition of a test function and 39 | * map it to our Unity port. 40 | */ 41 | #define CELLULAR_PORT_TEST_FUNCTION(function, name, group) CELLULAR_PORT_UNITY_TEST_FUNCTION(name, group) 42 | 43 | /* ---------------------------------------------------------------- 44 | * COMPILE-TIME MACROS: OS RELATED 45 | * -------------------------------------------------------------- */ 46 | 47 | /** The stack size to use for the test task created during OS testing. 48 | */ 49 | #define CELLULAR_PORT_TEST_OS_TASK_STACK_SIZE_BYTES (1024 * 4) 50 | 51 | /** The task priority to use for the task created during OS 52 | * testing: make sure that the priority of the task RUNNING 53 | * the tests is lower than this. 54 | */ 55 | #define CELLULAR_PORT_TEST_OS_TASK_PRIORITY (CELLULAR_PORT_OS_PRIORITY_MIN + 5) 56 | 57 | /** The stack size to use for the test task created during sockets testing. 58 | */ 59 | #define CELLULAR_PORT_TEST_SOCK_TASK_STACK_SIZE_BYTES (1024 * 5) 60 | 61 | /** The priority to use for the test task created during sockets testing; 62 | * lower priority than the URC handler. 63 | */ 64 | #define CELLULAR_PORT_TEST_SOCK_TASK_PRIORITY (CELLULAR_CTRL_AT_TASK_URC_PRIORITY - 1) 65 | 66 | /* ---------------------------------------------------------------- 67 | * COMPILE-TIME MACROS: HW RELATED 68 | * -------------------------------------------------------------- */ 69 | 70 | /** Pin A for GPIO testing: will be used as an output and 71 | * must be connected to pin B via a 1k resistor. 72 | */ 73 | #ifndef CELLULAR_PORT_TEST_PIN_A 74 | # define CELLULAR_PORT_TEST_PIN_A 38 // AKA 1.06 75 | #endif 76 | 77 | /** Pin B for GPIO testing: will be used as both an input and 78 | * and open drain output and must be connected both to pin A via 79 | * a 1k resistor and directly to pin C. 80 | */ 81 | #ifndef CELLULAR_PORT_TEST_PIN_B 82 | # define CELLULAR_PORT_TEST_PIN_B 39 // AKA 1.07 83 | #endif 84 | 85 | /** Pin C for GPIO testing: must be connected to pin B, 86 | * will be used as an input only. 87 | */ 88 | #ifndef CELLULAR_PORT_TEST_PIN_C 89 | # define CELLULAR_PORT_TEST_PIN_C 40 // AKA 1.08 90 | #endif 91 | 92 | /** UART HW block for UART driver testing. 93 | */ 94 | #ifndef CELLULAR_PORT_TEST_UART 95 | # define CELLULAR_PORT_TEST_UART 1 96 | #endif 97 | 98 | /** Handshake threshold for UART testing. 99 | */ 100 | #ifndef CELLULAR_PORT_TEST_UART_RTS_THRESHOLD 101 | # define CELLULAR_PORT_TEST_UART_RTS_THRESHOLD 0 // Not used on this platform 102 | #endif 103 | 104 | /** Tx pin for UART testing: should be connected to the Rx UART pin. 105 | */ 106 | #ifndef CELLULAR_PORT_TEST_PIN_UART_TXD 107 | # define CELLULAR_PORT_TEST_PIN_UART_TXD 42 // AKA 1.10 108 | #endif 109 | 110 | /** Rx pin for UART testing: should be connected to the Tx UART pin. 111 | */ 112 | #ifndef CELLULAR_PORT_TEST_PIN_UART_RXD 113 | # define CELLULAR_PORT_TEST_PIN_UART_RXD 43 // AKA 1.11 114 | #endif 115 | 116 | /** CTS pin for UART testing: should be connected to the RTS UART pin. 117 | */ 118 | #ifndef CELLULAR_PORT_TEST_PIN_UART_CTS 119 | # define CELLULAR_PORT_TEST_PIN_UART_CTS 44 // AKA 1.12 120 | #endif 121 | 122 | /** RTS pin for UART testing: should be connected to the CTS UART pin. 123 | */ 124 | #ifndef CELLULAR_PORT_TEST_PIN_UART_RTS 125 | # define CELLULAR_PORT_TEST_PIN_UART_RTS 45 // AKA 1.13 126 | #endif 127 | 128 | /* ---------------------------------------------------------------- 129 | * FUNCTIONS 130 | * -------------------------------------------------------------- */ 131 | 132 | #endif // _CELLULAR_PORT_TEST_PLATFORM_SPECIFIC_H_ 133 | 134 | // End of file 135 | -------------------------------------------------------------------------------- /port/platform/nordic/nrf52840/test/main_test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 u-blox Cambourne Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifdef CELLULAR_CFG_OVERRIDE 18 | # include "cellular_cfg_override.h" // For a customer's configuration override 19 | #endif 20 | #include "cellular_cfg_sw.h" 21 | #include "cellular_cfg_os_platform_specific.h" 22 | #include "cellular_cfg_test.h" 23 | #include "cellular_port_clib.h" 24 | #include "cellular_port.h" 25 | #include "cellular_port_debug.h" 26 | #include "cellular_port_test_platform_specific.h" 27 | 28 | /* ---------------------------------------------------------------- 29 | * COMPILE-TIME MACROS 30 | * -------------------------------------------------------------- */ 31 | 32 | // How much stack the task running all the tests needs in bytes. 33 | #define CELLULAR_PORT_TEST_RUNNER_TASK_STACK_SIZE_BYTES (1024 * 4) 34 | 35 | // The priority of the task running the tests: should be low. 36 | #define CELLULAR_PORT_TEST_RUNNER_TASK_PRIORITY (CELLULAR_PORT_OS_PRIORITY_MIN + 1) 37 | 38 | /* ---------------------------------------------------------------- 39 | * TYPES 40 | * -------------------------------------------------------------- */ 41 | 42 | /* ---------------------------------------------------------------- 43 | * VARIABLES 44 | * -------------------------------------------------------------- */ 45 | 46 | /* ---------------------------------------------------------------- 47 | * STATIC FUNCTIONS 48 | * -------------------------------------------------------------- */ 49 | 50 | // The task within which testing runs. 51 | static void testTask(void *pParam) 52 | { 53 | (void) pParam; 54 | 55 | cellularPortInit(); 56 | cellularPortLog("\n\nCELLULAR_TEST: test task started.\n"); 57 | 58 | UNITY_BEGIN(); 59 | 60 | cellularPortLog("CELLULAR_TEST: tests available:\n\n"); 61 | cellularPortUnityPrintAll("CELLULAR_TEST: "); 62 | cellularPortLog("CELLULAR_TEST: tests available:\n\n"); 63 | cellularPortUnityPrintAll("CELLULAR_TEST: "); 64 | #ifdef CELLULAR_CFG_TEST_FILTER 65 | cellularPortLog("CELLULAR_TEST: running tests that begin with \"%s\".\n", 66 | CELLULAR_PORT_STRINGIFY_QUOTED(CELLULAR_CFG_TEST_FILTER)); 67 | cellularPortUnityRunFiltered(CELLULAR_PORT_STRINGIFY_QUOTED(CELLULAR_CFG_TEST_FILTER), 68 | "CELLULAR_TEST: "); 69 | #else 70 | cellularPortLog("CELLULAR_TEST: running all tests.\n"); 71 | cellularPortUnityRunAll("CELLULAR_TEST: "); 72 | #endif 73 | 74 | UNITY_END(); 75 | 76 | cellularPortLog("\n\nCELLULAR_TEST: test task ended.\n"); 77 | cellularPortDeinit(); 78 | 79 | while(1){} 80 | } 81 | 82 | /* ---------------------------------------------------------------- 83 | * PUBLIC FUNCTIONS 84 | * -------------------------------------------------------------- */ 85 | 86 | // Unity setUp() function. 87 | void setUp(void) 88 | { 89 | // Nothing to do 90 | } 91 | 92 | // Unity tearDown() function. 93 | void tearDown(void) 94 | { 95 | // Nothing to do 96 | } 97 | 98 | void testFail(void) 99 | { 100 | // Nothing to do 101 | } 102 | 103 | // Entry point 104 | int main(void) 105 | { 106 | // Start the platform to run the tests 107 | cellularPortPlatformStart(testTask, NULL, 108 | CELLULAR_PORT_TEST_RUNNER_TASK_STACK_SIZE_BYTES, 109 | CELLULAR_PORT_TEST_RUNNER_TASK_PRIORITY); 110 | 111 | // Should never get here 112 | cellularPort_assert(false); 113 | 114 | return 0; 115 | } -------------------------------------------------------------------------------- /port/platform/stm/stm32f4/README.md: -------------------------------------------------------------------------------- 1 | # Introduction 2 | These directories provide the implementation of the porting layer on the STM32F4 platform plus the associated build and board configuration information: 3 | 4 | - `cfg`: contains the file `cellular_cfg_hw_platform_specific.h` which provides default configuration for a u-blox C030-R412M board that includes a SARA-R412M cellular module. Note that in order to retain the flexibility to use the same STM32F4 code with other u-blox cellular modules the module type is NOT specified in this configuration file, you must do that when you perform your build. Also in here you will find the FreeRTOS configuration header file. 5 | - `sdk/cube`: contains the files to build/test for the STM32F4 platform using the STM32Cube IDE. 6 | - `src`: contains the implementation of the porting layers for STM32F4. 7 | - `test`: contains the code that runs the unit tests for the cellular code on the STM32F4 platform. 8 | 9 | # Hardware Requirements 10 | This code was developed to run on the u-blox C030-R412M board, which includes an STM32F437VG chip, a SARA-R412M cellular module and a separate ST debug chip. However there is no reason why it would not work on any STM32F4 chip talking to another supported u-blox cellular module, see `cfg/cellular_cfg_module.h`. 11 | 12 | Note that the u-blox C030 board runs from an external 12 MHz crystal, hence the contents of `cellularPortPlatformStart()` reflect this and the value for `HSE_VALUE` of 12000000 in `stm32f4xx_hal_conf.h` reflects this; if your board is different you should amend these entries appropriately. 13 | 14 | # Chip Resource Requirements 15 | SysTick is assumed to provide a 1 ms RTOS tick which is used as a source of time for `cellularPortGetTickTimeMs()`. Note that this means that if you want to use FreeRTOS in tickless mode you will need to either find another source of tick for `cellularPortGetTickTimeMs()` or put in a call that updates `gTickTimerRtosCount` when FreeRTOS resumes after a tickless period. 16 | 17 | One UART is also required and, to go with it, a single channel of a single stream from of one of two DMA channels. See `cellular_cfg_hw_platform_specific.h` in the `cfg` directory for which UARTs are available to this driver and which DMA resources are assigned to each UART. 18 | 19 | # Downloading To The Board 20 | When the C030-R412M board is plugged into a USB port a mapped drive should appear, e.g. `D:`. Builds are downloaded by copying your compiled `.bin` file to this drive. Builds can also be downloaded using ST's (ST-Link utility)[https://www.st.com/en/development-tools/stsw-link004.html] and through the STM32Cube IDE. 21 | 22 | # Trace Output 23 | The trace output from this build is sent over SWD. Instructions for how to view the trace output in the STM32Cube IDE can be found in the `cube` sub-directory below. 24 | 25 | Alternatively, if you just want to run the target without the debugger and simply view the SWO output, the (ST-Link utility)[https://www.st.com/en/development-tools/stsw-link004.html] utility includes a "Printf via SWO Viewer" option under its "ST-LINK" menu. Set the core clock to 168 MHz, press "Start" and your debug printf()s will appear in that window. 26 | 27 | *** THE REST OF THIS A WORK IN PROGRESS *** 28 | 29 | You can also run this from the command line with something like: 30 | 31 | ``` 32 | "C:\Program Files (x86)\STMicroelectronics\STM32 ST-LINK Utility\ST-LINK Utility\ST-LINK_CLI.exe" -c SWD Freq=2 UR 33 | ``` 34 | 35 | https://arm-stm.blogspot.com/2014/12/debug-mcu-configuration-register.html 36 | 37 | (DBGMCU_CR) 38 | DBGMCU_CR is mapped on the External PPB bus at address 0xE0042004 39 | 40 | TRACE_IOEN (bit 5) and 41 | TRACE_MODE 42 | 43 | 44 | 45 | There are several steps required for enabling the SWV trace. 46 | 47 | Set DEMCR.TRCENA = 1 to enable access to the trace components' registers. 48 | 49 | Select the required pin protocol in the TPIU_SPPR register: 50 | 51 | 0 - parallel synchronous trace port (not SWV) 52 | 53 | 1 - Serial Wire Viewer, Manchester encoding 54 | 55 | 2 - Serial Wire Viewer, UART Non-Return to Zero encoding 56 | 57 | Write 0xC5ACCE55 to the ITM's CoreSight Lock Access Register (ITM_LAR) to unlock the ITM. This register is missing from some editions of the processor's Technical Reference Manual (TRM). 58 | 59 | Set ITM_TCR.ITMENA = 1 to enable the ITM, together with additional bit fields in this register to enable timestamps, synchronization packets, and others as required. 60 | 61 | Enable the individual channels as required by setting bits in ITM_TER0. You might also wish to control the privilege level of the stimulus channels by writing to the four least significant bits of ITM_TPR. 62 | 63 | Write values to your enabled stimulus channels (ITM_STIM0 to ITM_STIM31) to generate SWV trace activity. 64 | 65 | 66 | https://developer.arm.com/docs/128795835/10/enabling-itm-trace-on-serial-wire-viewer 67 | 68 | Set DEMCR (0xE000EDFC) TRCENA (bit 24) = 1 to enable access to the trace components' register: set {int}0xE000EDFC=0x01000000 69 | Select protocol "UART Non-Return to Zero encoding" in TPIU_SPPR (0xE00400F0) register: set {int}0xE00400F0=2 70 | Initiate access by writing 0xC5ACCE55 to ITM_LAR (0xE0000FB0): set {int}0xE0000FB0=0xC5ACCE55 71 | Set ITM_TCR (0xE0000E80) ITMENA (bit) and others: set {int}0xE0000E80=0x0001000f 72 | Enable channel 0 by writing 1 to ITM_TER (0xE0000E00): set {int}0xE0000E00=1 73 | 74 | 75 | 76 | Set DBGMCU_CR.TRACE_IOEN (bit 5): set {int}0xE0042004={int}0xE0042004 | 0x20 77 | Enable trace channel 0: set {int}0xE0000E00={int}0xE0000E00 | 1 78 | Set trace control: set {int}0xE0000E80={int}0xE0000E80 | 1 79 | 80 | 81 | 0xE0000FB0 ITM_LAR 82 | -------------------------------------------------------------------------------- /port/platform/stm/stm32f4/cfg/cellular_cfg_os_platform_specific.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 u-blox Cambourne Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _CELLULAR_CFG_OS_PLATFORM_SPECIFIC_H_ 18 | #define _CELLULAR_CFG_OS_PLATFORM_SPECIFIC_H_ 19 | 20 | /* No #includes allowed here */ 21 | 22 | /* This header file contains OS configuration information for 23 | * an STM32F4 processor. 24 | */ 25 | 26 | /* ---------------------------------------------------------------- 27 | * COMPILE-TIME MACROS FOR STM32F4: OS GENERIC 28 | * -------------------------------------------------------------- */ 29 | 30 | #ifndef CELLULAR_PORT_OS_PRIORITY_MIN 31 | /** The minimum task priority. 32 | * cmsis-os defines osPriorityIdle as 1. 33 | */ 34 | # define CELLULAR_PORT_OS_PRIORITY_MIN 1 35 | #endif 36 | 37 | #ifndef CELLULAR_PORT_OS_PRIORITY_MAX 38 | /** The maximum task priority, should be less than or 39 | * equal to configMAX_PRIORITIES defined in FreeRTOSConfig.h, 40 | * which is set to 15. cmsis-os defines osPriorityISR 41 | * as 56 but when this is mapped to FreeRTOS, as it is on 42 | * this platform, the range gets squished. 43 | */ 44 | # define CELLULAR_PORT_OS_PRIORITY_MAX 15 45 | #endif 46 | 47 | /* ---------------------------------------------------------------- 48 | * COMPILE-TIME MACROS FOR STM32F4: AT CLIENT RELATED 49 | * -------------------------------------------------------------- */ 50 | 51 | #ifndef CELLULAR_CTRL_AT_TASK_URC_STACK_SIZE_BYTES 52 | /** The stack size for the AT task that handles URCs. 53 | * Note: this size worst case for unoptimised compilation 54 | * (so that a debugger can be used sensibly) under the worst compiler. 55 | */ 56 | # define CELLULAR_CTRL_AT_TASK_URC_STACK_SIZE_BYTES (1024 * 5) 57 | #endif 58 | 59 | #ifndef CELLULAR_CTRL_AT_TASK_URC_PRIORITY 60 | /** The task priority for the URC handler. 61 | */ 62 | # define CELLULAR_CTRL_AT_TASK_URC_PRIORITY (CELLULAR_PORT_OS_PRIORITY_MAX - 5) 63 | #endif 64 | 65 | #ifndef CELLULAR_CTRL_TASK_CALLBACK_STACK_SIZE_BYTES 66 | /** The stack size of the task in the context of which the callbacks 67 | * of AT command URCs will be run. 5 kbytes should be plenty of room. 68 | */ 69 | # define CELLULAR_CTRL_TASK_CALLBACK_STACK_SIZE_BYTES (1024 * 5) 70 | #endif 71 | 72 | #ifndef CELLULAR_CTRL_TASK_CALLBACK_PRIORITY 73 | /** The task priority for any callback made via 74 | * cellular_ctrl_at_callback(). 75 | */ 76 | # define CELLULAR_CTRL_TASK_CALLBACK_PRIORITY (CELLULAR_PORT_OS_PRIORITY_MIN + 2) 77 | #endif 78 | 79 | #if (CELLULAR_CTRL_TASK_CALLBACK_PRIORITY >= CELLULAR_CTRL_AT_TASK_URC_PRIORITY) 80 | # error CELLULAR_CTRL_TASK_CALLBACK_PRIORITY must be less than CELLULAR_CTRL_AT_TASK_URC_PRIORITY 81 | #endif 82 | 83 | #endif // _CELLULAR_CFG_OS_PLATFORM_SPECIFIC_H_ 84 | 85 | // End of file 86 | -------------------------------------------------------------------------------- /port/platform/stm/stm32f4/sdk/cube/README.md: -------------------------------------------------------------------------------- 1 | # Introduction 2 | This directory contains the build infrastructure for STM32F4 using the STM32Cube IDE. 3 | 4 | # Usage 5 | Follow the instructions to install the STM32Cube IDE: 6 | 7 | https://www.st.com/en/development-tools/stm32cubeide.html 8 | 9 | Download a version (this code was tested with version 1.25.0) of the STM32 F4 MCU package ZIP file (containing their HAL etc.) from here: 10 | 11 | https://www.st.com/en/embedded-software/stm32cubef4.html 12 | 13 | Unzip it to the same directory as you cloned this repo with the name `STM32Cube_FW_F4`, i.e.: 14 | 15 | ``` 16 | .. 17 | . 18 | STM32Cube_FW_F4 19 | cellular 20 | ``` 21 | 22 | You may unzip it to a different location but, if you do so, when you open your chosen build you must go to `Project` -> `Properties` -> `Resource` -> `Linked Resources`, modify the path variable `STM32CUBE_FW_PATH` to point to the correct location and then refresh the project. 23 | 24 | BEFORE running the STM32Cube IDE you first need to define which module you are using (e.g. one of `CELLULAR_CFG_MODULE_SARA_R412M_02B` or `CELLULAR_CFG_MODULE_SARA_R5`). To do this, create an environment variable called `CELLULAR_FLAG0` and set it to be that module name in the form: 25 | 26 | ``` 27 | set CELLULAR_FLAG0=-DCELLULAR_CFG_MODULE_SARA_R5 28 | ``` 29 | 30 | There are ten `CELLULAR_FLAGx` variables available, 0 to 9, which you can use to override other compilation flags, so for instance if you wanted to say that there's no "enable power" capability on your board you might use: 31 | 32 | ``` 33 | set CELLULAR_FLAG0=-DCELLULAR_CFG_MODULE_SARA_R5 34 | set CELLULAR_FLAG1=-DCELLULAR_CFG_PIN_ENABLE_POWER=-1 35 | ``` 36 | 37 | Clumsy, I know, but was the only way I could find to get Eclipse to override more than one pre-processor #define from an environment variable. 38 | 39 | With that done `cd` to your chosen build under this sub-directory, load the project into the STM32Cube IDE and then follow ST's instructions to build/download/run the project. 40 | 41 | Note: the examples can be built and run in the same way as the unit tests, so look in the `unit_test` directory for everything. 42 | 43 | # Trace 44 | To view the SWO trace output in the STM32 Cube IDE, setup up the debugger as normal by pulling down the arrow beside the little button on the toolbar with the "bug" image on it, selecting "STM-Cortex-M C/C++ Application", create a new configuration and then, on the "Debugger" tab, tick the box that enables SWD, set the core clock to 168 MHz and click "Apply". 45 | 46 | You should then be able to download the Debug build from the IDE and the IDE should launch you into the debugger. To see the SWD trace output, click on "Window" -> "Show View" -> "SWV" -> "SWV ITM Data Console". The docked window that appears should have a little "spanner" icon on the far right: click on that icon and, on the set of "ITM Stimulus Ports", tick channel 0 and then press "OK". Beside the "spanner" icon is a small red button: press that to allow trace output to appear; unfortuantely it seems that this latter step has to be performed every debug session, it is not possible to automate it. -------------------------------------------------------------------------------- /port/platform/stm/stm32f4/sdk/cube/unit_test/README.md: -------------------------------------------------------------------------------- 1 | # Introduction 2 | This directory contains the examples and unit tests build for STM32F4 under the STM32Cube IDE. 3 | 4 | IMPORTANT: the STM32Cube IDE creates lots of sub-directories in here. Please ignore them, NONE of the source files/header files are down here, they are all up in the `test` sub-directory for this platform so that they can be built with other SDKs as required. Don't delete the empty directories though: if you do the STM32Cube IDE will then delete the links to the files in the `.project` file. Weird, but the only way I could find to keep the source code independent of the SDK that happens to build it. 5 | 6 | # Usage 7 | Make sure you have followed the instructions in the directory above this to install the STM32Cube IDE toolchain and STM32F4 MCU support files. 8 | 9 | You will also need a copy of Unity, the unit test framework, which can be Git cloned from here: 10 | 11 | https://github.com/ThrowTheSwitch/Unity 12 | 13 | Clone it to the same directory level as `cellular`, i.e.: 14 | 15 | ``` 16 | .. 17 | . 18 | Unity 19 | cellular 20 | ``` 21 | 22 | 23 | Note: you may put this repo in a different location but, if you do so, when you open the project in the STM32Cube IDE you must go to `Project` -> `Properties` -> `Resource` -> `Linked Resources`, modify the path variable `UNITY_PATH` to point to the correct location and then refresh the project. 24 | 25 | With that done load the project into the STM32Cube IDE to build, download and run it. 26 | 27 | By default all of the examples and tests supported by this platform will be executed. To execute just a subset set the conditional compilation flag `CELLULAR_CFG_TEST_FILTER` to the example and/or test you wish to run. For instance, to run all of the examples you would set `CELLULAR_CFG_TEST_FILTER=example`, or to run all of the porting tests `CELLULAR_CFG_TEST_FILTER=port`, or to run a particular example `CELLULAR_CFG_TEST_FILTER=examplexxx`, where `xxx` is the start of the rest of the example name. In other words, the filter is a simple partial string compare with the start of the example/test name. Note that quotation marks must NOT be used around the value part. 28 | 29 | You may set this compilation flag directly in the IDE, or you may set the compilation flag `CELLULAR_CFG_OVERRIDE` and provide it in the header file `cellular_cfg_override.h` (which you must create) or you may use the mechanism described in the directory above to pass the compilation flag into the build as an environment variable without modifying the build files at all. 30 | 31 | With that done load the project into the STM32Cube IDE and follow ST's instructions to build, download and run it. -------------------------------------------------------------------------------- /port/platform/stm/stm32f4/src/cellular_port_clib_platform_specific.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 u-blox Cambourne Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _CELLULAR_PORT_CLIB_PLATFORM_SPECIFIC_H_ 18 | #define _CELLULAR_PORT_CLIB_PLATFORM_SPECIFIC_H_ 19 | 20 | /** Implementations of C library functions not available on this 21 | * platform. 22 | */ 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* ---------------------------------------------------------------- 29 | * COMPILE-TIME MACROS 30 | * -------------------------------------------------------------- */ 31 | 32 | /* ---------------------------------------------------------------- 33 | * TYPES 34 | * -------------------------------------------------------------- */ 35 | 36 | /* ---------------------------------------------------------------- 37 | * FUNCTIONS 38 | * -------------------------------------------------------------- */ 39 | 40 | /** strtok(). 41 | * 42 | * @param pStr the string to search. 43 | * @param pDelimiters the set of delimiters to look for. 44 | * @param ppSave place for this function to store context. 45 | * @return the next occurrence of pDelimiter in pStr. 46 | */ 47 | char *strtok_r(char *pStr, const char *pDelimiters, char **ppSave); 48 | 49 | #ifdef __cplusplus 50 | } 51 | #endif 52 | 53 | #endif // _CELLULAR_PORT_CLIB_PLATFORM_SPECIFIC_H_ 54 | 55 | // End of file 56 | -------------------------------------------------------------------------------- /port/platform/stm/stm32f4/src/cellular_port_debug.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 u-blox Cambourne Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifdef CELLULAR_CFG_OVERRIDE 18 | # include "cellular_cfg_override.h" // For a customer's configuration override 19 | #endif 20 | #include "cellular_port_clib.h" 21 | #include "cellular_port_debug.h" 22 | 23 | #include "stdio.h" 24 | #include "stdarg.h" 25 | 26 | #include "stm32f437xx.h" // For ITM_SendChar() 27 | 28 | /* ---------------------------------------------------------------- 29 | * COMPILE-TIME MACROS 30 | * -------------------------------------------------------------- */ 31 | 32 | /* ---------------------------------------------------------------- 33 | * TYPES 34 | * -------------------------------------------------------------- */ 35 | 36 | /* ---------------------------------------------------------------- 37 | * VARIABLES 38 | * -------------------------------------------------------------- */ 39 | 40 | /* ---------------------------------------------------------------- 41 | * STATIC FUNCTIONS 42 | * -------------------------------------------------------------- */ 43 | 44 | /* ---------------------------------------------------------------- 45 | * PUBLIC FUNCTIONS 46 | * -------------------------------------------------------------- */ 47 | 48 | // This function will replace the weakly-linked _write() function in 49 | // syscalls.c and will send output to the RTT trace port. 50 | int _write(int file, char *pStr, int len) 51 | { 52 | (void) file; 53 | 54 | for (size_t x = 0 ; x < len ; x++) { 55 | ITM_SendChar(*pStr); 56 | pStr++; 57 | } 58 | 59 | return len; 60 | } 61 | 62 | // printf()-style logging. 63 | void cellularPortLogF(const char *pFormat, ...) 64 | { 65 | va_list args; 66 | 67 | va_start(args, pFormat); 68 | vprintf(pFormat, args); 69 | va_end(args); 70 | } 71 | 72 | // End of file 73 | -------------------------------------------------------------------------------- /port/platform/stm/stm32f4/src/cellular_port_gpio.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 u-blox Cambourne Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifdef CELLULAR_CFG_OVERRIDE 18 | # include "cellular_cfg_override.h" // For a customer's configuration override 19 | #endif 20 | #include "cellular_port_clib.h" 21 | #include "cellular_port.h" 22 | #include "cellular_port_gpio.h" 23 | 24 | #include "stm32f4xx_hal.h" 25 | #include "stm32f4xx_hal_gpio.h" 26 | 27 | #include "cellular_port_private.h" // Down here 'cos it needs GPIO_TypeDef 28 | 29 | /* ---------------------------------------------------------------- 30 | * COMPILE-TIME MACROS 31 | * -------------------------------------------------------------- */ 32 | 33 | /* ---------------------------------------------------------------- 34 | * TYPES 35 | * -------------------------------------------------------------- */ 36 | 37 | /* ---------------------------------------------------------------- 38 | * VARIABLES 39 | * -------------------------------------------------------------- */ 40 | 41 | /* ---------------------------------------------------------------- 42 | * STATIC FUNCTIONS 43 | * -------------------------------------------------------------- */ 44 | 45 | /* ---------------------------------------------------------------- 46 | * PUBLIC FUNCTIONS 47 | * -------------------------------------------------------------- */ 48 | 49 | // Configure a GPIO. 50 | int32_t cellularPortGpioConfig(CellularPortGpioConfig_t *pConfig) 51 | { 52 | CellularPortErrorCode_t errorCode = CELLULAR_PORT_INVALID_PARAMETER; 53 | bool badConfig = false; 54 | GPIO_InitTypeDef config = {0}; 55 | 56 | // Note that Pin is a bitmap 57 | config.Pin = 1U << CELLULAR_PORT_STM32F4_GPIO_PIN(pConfig->pin); 58 | config.Mode = GPIO_MODE_INPUT; 59 | config.Pull = GPIO_NOPULL; 60 | config.Speed = GPIO_SPEED_FREQ_LOW; 61 | 62 | if (pConfig != NULL) { 63 | // Set the direction and mode 64 | switch (pConfig->direction) { 65 | case CELLULAR_PORT_GPIO_DIRECTION_NONE: 66 | case CELLULAR_PORT_GPIO_DIRECTION_INPUT: 67 | // Nothing to do 68 | break; 69 | case CELLULAR_PORT_GPIO_DIRECTION_INPUT_OUTPUT: 70 | case CELLULAR_PORT_GPIO_DIRECTION_OUTPUT: 71 | switch (pConfig->driveMode) { 72 | case CELLULAR_PORT_GPIO_DRIVE_MODE_NORMAL: 73 | config.Mode = GPIO_MODE_OUTPUT_PP; 74 | break; 75 | case CELLULAR_PORT_GPIO_DRIVE_MODE_OPEN_DRAIN: 76 | config.Mode = GPIO_MODE_OUTPUT_OD; 77 | break; 78 | default: 79 | badConfig = true; 80 | break; 81 | } 82 | break; 83 | default: 84 | badConfig = true; 85 | break; 86 | } 87 | 88 | // Set pull up/down 89 | switch (pConfig->pullMode) { 90 | case CELLULAR_PORT_GPIO_PULL_MODE_NONE: 91 | // No need to do anything 92 | break; 93 | case CELLULAR_PORT_GPIO_PULL_MODE_PULL_UP: 94 | config.Pull = GPIO_PULLUP; 95 | break; 96 | case CELLULAR_PORT_GPIO_PULL_MODE_PULL_DOWN: 97 | config.Pull = GPIO_PULLDOWN; 98 | break; 99 | default: 100 | badConfig = true; 101 | break; 102 | } 103 | 104 | // Setting drive strength is not supported on this platform 105 | 106 | // Actually do the configuration 107 | if (!badConfig) { 108 | // Enable the clocks to the port for this pin 109 | cellularPortPrivateGpioEnableClock(pConfig->pin); 110 | // The GPIO init function for STM32F4 takes a pointer 111 | // to the port register, the index for which is the upper 112 | // nibble of pin (they are in banks of 16), and then 113 | // the configuration structure which has the pin number 114 | // within that port. 115 | HAL_GPIO_Init(pCellularPortPrivateGpioGetReg(pConfig->pin), 116 | &config); 117 | errorCode = CELLULAR_PORT_SUCCESS; 118 | } 119 | } 120 | 121 | return (int32_t) errorCode; 122 | } 123 | 124 | // Set the state of a GPIO. 125 | int32_t cellularPortGpioSet(int32_t pin, int32_t level) 126 | { 127 | // Enable the clocks to the port for this pin 128 | cellularPortPrivateGpioEnableClock(pin); 129 | 130 | HAL_GPIO_WritePin(pCellularPortPrivateGpioGetReg(pin), 131 | 1U << CELLULAR_PORT_STM32F4_GPIO_PIN(pin), 132 | level); 133 | 134 | return (int32_t) CELLULAR_PORT_SUCCESS; 135 | } 136 | 137 | // Get the state of a GPIO. 138 | int32_t cellularPortGpioGet(int32_t pin) 139 | { 140 | // Enable the clocks to the port for this pin 141 | cellularPortPrivateGpioEnableClock(pin); 142 | 143 | return HAL_GPIO_ReadPin(pCellularPortPrivateGpioGetReg(pin), 144 | 1U << CELLULAR_PORT_STM32F4_GPIO_PIN(pin)); 145 | } 146 | 147 | // End of file 148 | -------------------------------------------------------------------------------- /port/platform/stm/stm32f4/src/cellular_port_private.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 u-blox Cambourne Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifdef CELLULAR_CFG_OVERRIDE 18 | # include "cellular_cfg_override.h" // For a customer's configuration override 19 | #endif 20 | #include "cellular_port_clib.h" 21 | #include "cellular_port.h" 22 | 23 | #include "stm32f4xx_hal.h" 24 | #include "stm32f4xx_ll_bus.h" 25 | 26 | #include "cellular_port_private.h" // Down here 'cos it needs GPIO_TypeDef 27 | 28 | /* ---------------------------------------------------------------- 29 | * COMPILE-TIME MACROS 30 | * -------------------------------------------------------------- */ 31 | 32 | /* ---------------------------------------------------------------- 33 | * TYPES 34 | * -------------------------------------------------------------- */ 35 | 36 | /* ---------------------------------------------------------------- 37 | * VARIABLES 38 | * -------------------------------------------------------------- */ 39 | 40 | // Counter to keep track of RTOS ticks: NOT static 41 | // so that the stm32f4xx_it.c can update it. 42 | int32_t gTickTimerRtosCount; 43 | 44 | // Get the GPIOx address for a given GPIO port. 45 | static GPIO_TypeDef * const gpGpioReg[] = {GPIOA, 46 | GPIOB, 47 | GPIOC, 48 | GPIOD, 49 | GPIOE, 50 | GPIOF, 51 | GPIOG, 52 | GPIOH, 53 | GPIOI, 54 | GPIOJ, 55 | GPIOK}; 56 | 57 | // Get the LL driver peripheral number for a given GPIO port. 58 | static const int32_t gLlApbGrpPeriphGpioPort[] = {LL_AHB1_GRP1_PERIPH_GPIOA, 59 | LL_AHB1_GRP1_PERIPH_GPIOB, 60 | LL_AHB1_GRP1_PERIPH_GPIOC, 61 | LL_AHB1_GRP1_PERIPH_GPIOD, 62 | LL_AHB1_GRP1_PERIPH_GPIOE, 63 | LL_AHB1_GRP1_PERIPH_GPIOF, 64 | LL_AHB1_GRP1_PERIPH_GPIOG, 65 | LL_AHB1_GRP1_PERIPH_GPIOH, 66 | LL_AHB1_GRP1_PERIPH_GPIOI, 67 | LL_AHB1_GRP1_PERIPH_GPIOJ, 68 | LL_AHB1_GRP1_PERIPH_GPIOK}; 69 | 70 | /* ---------------------------------------------------------------- 71 | * STATIC FUNCTIONS 72 | * -------------------------------------------------------------- */ 73 | 74 | /* ---------------------------------------------------------------- 75 | * PUBLIC FUNCTIONS SPECIFIC TO THIS PORT 76 | * -------------------------------------------------------------- */ 77 | 78 | // Initalise the private stuff. 79 | int32_t cellularPortPrivateInit() 80 | { 81 | gTickTimerRtosCount = 0; 82 | return CELLULAR_PORT_SUCCESS; 83 | } 84 | 85 | // Deinitialise the private stuff. 86 | void cellularPortPrivateDeinit() 87 | { 88 | // Nothing to do 89 | } 90 | 91 | /* ---------------------------------------------------------------- 92 | * PUBLIC FUNCTIONS SPECIFIC TO THIS PORT: GET TIME TICK 93 | * -------------------------------------------------------------- */ 94 | 95 | // Get the current tick converted to a time in milliseconds. 96 | int64_t cellularPortPrivateGetTickTimeMs() 97 | { 98 | return gTickTimerRtosCount; 99 | } 100 | 101 | /* ---------------------------------------------------------------- 102 | * PUBLIC FUNCTIONS SPECIFIC TO THIS PORT: MISC 103 | * -------------------------------------------------------------- */ 104 | 105 | // Return the base address for a given GPIO pin. 106 | GPIO_TypeDef * const pCellularPortPrivateGpioGetReg(int32_t pin) 107 | { 108 | int32_t port = CELLULAR_PORT_STM32F4_GPIO_PORT(pin); 109 | 110 | cellularPort_assert(port >= 0); 111 | cellularPort_assert(port < sizeof(gpGpioReg) / sizeof(gpGpioReg[0])); 112 | 113 | return gpGpioReg[port]; 114 | } 115 | 116 | // Enable the clock to the register of the given GPIO pin. 117 | void cellularPortPrivateGpioEnableClock(int32_t pin) 118 | { 119 | int32_t port = CELLULAR_PORT_STM32F4_GPIO_PORT(pin); 120 | 121 | cellularPort_assert(port >= 0); 122 | cellularPort_assert(port < sizeof(gLlApbGrpPeriphGpioPort) / sizeof(gLlApbGrpPeriphGpioPort[0])); 123 | LL_AHB1_GRP1_EnableClock(gLlApbGrpPeriphGpioPort[port]); 124 | } 125 | 126 | // End of file 127 | -------------------------------------------------------------------------------- /port/platform/stm/stm32f4/src/cellular_port_private.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 u-blox Cambourne Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _CELLULAR_PORT_PRIVATE_H_ 18 | #define _CELLULAR_PORT_PRIVATE_H_ 19 | 20 | /** Stuff private to the STM32F4 porting layer. 21 | */ 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* ---------------------------------------------------------------- 28 | * COMPILE-TIME MACROS 29 | * -------------------------------------------------------------- */ 30 | 31 | // Get the port number of a pin, which is the upper nibble. 32 | #define CELLULAR_PORT_STM32F4_GPIO_PORT(x) ((uint16_t ) (((uint32_t) x) >> 4)) 33 | 34 | // Get the pin number of a pin, which is the lower nibble. 35 | #define CELLULAR_PORT_STM32F4_GPIO_PIN(x) ((uint16_t ) (x & 0x0f)) 36 | 37 | /* ---------------------------------------------------------------- 38 | * TYPES 39 | * -------------------------------------------------------------- */ 40 | 41 | /* ---------------------------------------------------------------- 42 | * FUNCTIONS 43 | * -------------------------------------------------------------- */ 44 | 45 | /** Initialise the private stuff. 46 | * 47 | * @return zero on success else negative error code. 48 | */ 49 | int32_t cellularPortPrivateInit(); 50 | 51 | /** Deinitialise the private stuff. 52 | */ 53 | void cellularPortPrivateDeinit(); 54 | 55 | /** Get the current OS tick converted to a time in milliseconds. 56 | */ 57 | int64_t cellularPortPrivateGetTickTimeMs(); 58 | 59 | /** Return the address of the port register for a given GPIO pin. 60 | * 61 | * @param pin the pin number. 62 | * @return the GPIO port address. 63 | * */ 64 | GPIO_TypeDef *pCellularPortPrivateGpioGetReg(int32_t pin); 65 | 66 | /** Enable the clock to the register of the given GPIO pin. 67 | * 68 | * @param pin the pin number. 69 | */ 70 | void cellularPortPrivateGpioEnableClock(int32_t pin); 71 | 72 | #ifdef __cplusplus 73 | } 74 | #endif 75 | 76 | #endif // _CELLULAR_PORT_PRIVATE_H_ 77 | 78 | // End of file 79 | -------------------------------------------------------------------------------- /port/platform/stm/stm32f4/src/stm32_assert.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32_assert.h 4 | * @brief STM32 assert file. 5 | ****************************************************************************** 6 | ** This notice applies to any and all portions of this file 7 | * that are not between comment pairs USER CODE BEGIN and 8 | * USER CODE END. Other portions of this file, whether 9 | * inserted by the user or by software development tools 10 | * are owned by their respective copyright owners. 11 | * 12 | * COPYRIGHT(c) 2018 STMicroelectronics 13 | * 14 | * Redistribution and use in source and binary forms, with or without modification, 15 | * are permitted provided that the following conditions are met: 16 | * 1. Redistributions of source code must retain the above copyright notice, 17 | * this list of conditions and the following disclaimer. 18 | * 2. Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 22 | * may be used to endorse or promote products derived from this software 23 | * without specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 28 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 31 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 33 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | * 36 | ****************************************************************************** 37 | */ 38 | 39 | /* Define to prevent recursive inclusion -------------------------------------*/ 40 | #ifndef __STM32_ASSERT_H 41 | #define __STM32_ASSERT_H 42 | 43 | #ifdef __cplusplus 44 | extern "C" { 45 | #endif 46 | 47 | /* Exported types ------------------------------------------------------------*/ 48 | /* Exported constants --------------------------------------------------------*/ 49 | /* Includes ------------------------------------------------------------------*/ 50 | /* Exported macro ------------------------------------------------------------*/ 51 | #ifdef USE_FULL_ASSERT 52 | /** 53 | * @brief The assert_param macro is used for function's parameters check. 54 | * @param expr: If expr is false, it calls assert_failed function 55 | * which reports the name of the source file and the source 56 | * line number of the call that failed. 57 | * If expr is true, it returns no value. 58 | * @retval None 59 | */ 60 | #define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__)) 61 | /* Exported functions ------------------------------------------------------- */ 62 | void assert_failed(uint8_t* file, uint32_t line); 63 | #else 64 | #define assert_param(expr) ((void)0U) 65 | #endif /* USE_FULL_ASSERT */ 66 | 67 | #ifdef __cplusplus 68 | } 69 | #endif 70 | 71 | #endif /* __STM32_ASSERT_H */ 72 | 73 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ -------------------------------------------------------------------------------- /port/platform/stm/stm32f4/src/stm32f4xx_hal_msp.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * File Name : stm32f4xx_hal_msp.c 5 | * Description : This file provides code for the MSP Initialization 6 | * and de-Initialization codes. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | *

© Copyright (c) 2020 STMicroelectronics. 11 | * All rights reserved.

12 | * 13 | * This software component is licensed by ST under BSD 3-Clause license, 14 | * the "License"; You may not use this file except in compliance with the 15 | * License. You may obtain a copy of the License at: 16 | * opensource.org/licenses/BSD-3-Clause 17 | * 18 | ****************************************************************************** 19 | */ 20 | /* USER CODE END Header */ 21 | 22 | /* Includes ------------------------------------------------------------------*/ 23 | #include "stm32f4xx_hal.h" 24 | /* USER CODE BEGIN Includes */ 25 | 26 | /* USER CODE END Includes */ 27 | 28 | /* Private typedef -----------------------------------------------------------*/ 29 | /* USER CODE BEGIN TD */ 30 | 31 | /* USER CODE END TD */ 32 | 33 | /* Private define ------------------------------------------------------------*/ 34 | /* USER CODE BEGIN Define */ 35 | 36 | /* USER CODE END Define */ 37 | 38 | /* Private macro -------------------------------------------------------------*/ 39 | /* USER CODE BEGIN Macro */ 40 | 41 | /* USER CODE END Macro */ 42 | 43 | /* Private variables ---------------------------------------------------------*/ 44 | /* USER CODE BEGIN PV */ 45 | 46 | /* USER CODE END PV */ 47 | 48 | /* Private function prototypes -----------------------------------------------*/ 49 | /* USER CODE BEGIN PFP */ 50 | 51 | /* USER CODE END PFP */ 52 | 53 | /* External functions --------------------------------------------------------*/ 54 | /* USER CODE BEGIN ExternalFunctions */ 55 | 56 | /* USER CODE END ExternalFunctions */ 57 | 58 | /* USER CODE BEGIN 0 */ 59 | 60 | /* USER CODE END 0 */ 61 | /** 62 | * Initializes the Global MSP. 63 | */ 64 | void HAL_MspInit(void) 65 | { 66 | /* USER CODE BEGIN MspInit 0 */ 67 | 68 | /* USER CODE END MspInit 0 */ 69 | 70 | __HAL_RCC_SYSCFG_CLK_ENABLE(); 71 | __HAL_RCC_PWR_CLK_ENABLE(); 72 | 73 | /* System interrupt init*/ 74 | 75 | /* USER CODE BEGIN MspInit 1 */ 76 | 77 | /* USER CODE END MspInit 1 */ 78 | } 79 | 80 | /* USER CODE BEGIN 1 */ 81 | 82 | /* USER CODE END 1 */ 83 | 84 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 85 | -------------------------------------------------------------------------------- /port/platform/stm/stm32f4/src/stm32f4xx_it.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file FreeRTOS/FreeRTOS_ThreadCreation/Src/stm32f4xx_it.c 4 | * @author MCD Application Team 5 | * @brief Main Interrupt Service Routines. 6 | * This file provides template for all exceptions handler and 7 | * peripherals interrupt service routine. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT(c) 2017 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "stm32f4xx_hal.h" 30 | #include "stm32f4xx_it.h" 31 | #include "cmsis_os.h" 32 | 33 | /* Need to update this value in cellular_port_private.c. */ 34 | extern int32_t gTickTimerRtosCount; 35 | 36 | /* Private typedef -----------------------------------------------------------*/ 37 | /* Private define ------------------------------------------------------------*/ 38 | /* Private macro -------------------------------------------------------------*/ 39 | /* Private function prototypes -----------------------------------------------*/ 40 | /* Private functions ---------------------------------------------------------*/ 41 | 42 | /******************************************************************************/ 43 | /* Cortex-M4 Processor Exceptions Handlers */ 44 | /******************************************************************************/ 45 | 46 | /** 47 | * @brief This function handles NMI exception. 48 | * @param None 49 | * @retval None 50 | */ 51 | void NMI_Handler(void) 52 | { 53 | } 54 | 55 | /** 56 | * @brief This function handles Hard Fault exception. 57 | * @param None 58 | * @retval None 59 | */ 60 | void HardFault_Handler(void) 61 | { 62 | /* Go to infinite loop when Hard Fault exception occurs */ 63 | while (1) {} 64 | } 65 | 66 | /** 67 | * @brief This function handles Memory Manage exception. 68 | * @param None 69 | * @retval None 70 | */ 71 | void MemManage_Handler(void) 72 | { 73 | /* Go to infinite loop when Memory Manage exception occurs */ 74 | while (1) {} 75 | } 76 | 77 | /** 78 | * @brief This function handles Bus Fault exception. 79 | * @param None 80 | * @retval None 81 | */ 82 | void BusFault_Handler(void) 83 | { 84 | /* Go to infinite loop when Bus Fault exception occurs */ 85 | while (1) {} 86 | } 87 | 88 | /** 89 | * @brief This function handles Usage Fault exception. 90 | * @param None 91 | * @retval None 92 | */ 93 | void UsageFault_Handler(void) 94 | { 95 | /* Go to infinite loop when Usage Fault exception occurs */ 96 | while (1) {} 97 | } 98 | 99 | /** 100 | * @brief This function handles Debug Monitor exception. 101 | * @param None 102 | * @retval None 103 | */ 104 | void DebugMon_Handler(void) 105 | { 106 | } 107 | 108 | /** 109 | * @brief This function handles SysTick Handler. 110 | * @param None 111 | * @retval None 112 | */ 113 | void SysTick_Handler(void) 114 | { 115 | gTickTimerRtosCount++; 116 | osSystickHandler(); 117 | } 118 | 119 | /******************************************************************************/ 120 | /* STM32F4xx Peripherals Interrupt Handlers */ 121 | /* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ 122 | /* available peripheral interrupt handler's name please refer to the startup */ 123 | /* file (startup_stm32f4xx.s). */ 124 | /******************************************************************************/ 125 | 126 | /** 127 | * @brief This function handles PPP interrupt request. 128 | * @param None 129 | * @retval None 130 | */ 131 | /*void PPP_IRQHandler(void) 132 | { 133 | }*/ 134 | 135 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 136 | -------------------------------------------------------------------------------- /port/platform/stm/stm32f4/src/stm32f4xx_it.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file FreeRTOS/FreeRTOS_ThreadCreation/Inc/stm32f4xx_it.h 4 | * @author MCD Application Team 5 | * @brief This file contains the headers of the interrupt handlers. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© COPYRIGHT(c) 2017 STMicroelectronics

10 | * 11 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 12 | * You may not use this file except in compliance with the License. 13 | * You may obtain a copy of the License at: 14 | * 15 | * http://www.st.com/software_license_agreement_liberty_v2 16 | * 17 | * Unless required by applicable law or agreed to in writing, software 18 | * distributed under the License is distributed on an "AS IS" BASIS, 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 | * See the License for the specific language governing permissions and 21 | * limitations under the License. 22 | * 23 | ****************************************************************************** 24 | */ 25 | 26 | /* Define to prevent recursive inclusion -------------------------------------*/ 27 | #ifndef __STM32F4xx_IT_H 28 | #define __STM32F4xx_IT_H 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | /* Includes ------------------------------------------------------------------*/ 35 | #include "stm32f4xx.h" 36 | 37 | /* Exported types ------------------------------------------------------------*/ 38 | /* Exported constants --------------------------------------------------------*/ 39 | /* Exported macro ------------------------------------------------------------*/ 40 | /* Exported functions ------------------------------------------------------- */ 41 | 42 | void NMI_Handler(void); 43 | void HardFault_Handler(void); 44 | void MemManage_Handler(void); 45 | void BusFault_Handler(void); 46 | void UsageFault_Handler(void); 47 | void SVC_Handler(void); 48 | void DebugMon_Handler(void); 49 | void PendSV_Handler(void); 50 | void SysTick_Handler(void); 51 | 52 | #ifdef __cplusplus 53 | } 54 | #endif 55 | 56 | #endif /* __STM32F4xx_IT_H */ 57 | 58 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 59 | -------------------------------------------------------------------------------- /port/platform/stm/stm32f4/src/syscalls.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file syscalls.c 4 | * @author Auto-generated by STM32CubeIDE 5 | * @brief STM32CubeIDE Minimal System calls file 6 | * 7 | * For more information about which c-functions 8 | * need which of these lowlevel functions 9 | * please consult the Newlib libc-manual 10 | ****************************************************************************** 11 | * @attention 12 | * 13 | *

© Copyright (c) 2020 STMicroelectronics. 14 | * All rights reserved.

15 | * 16 | * This software component is licensed by ST under BSD 3-Clause license, 17 | * the "License"; You may not use this file except in compliance with the 18 | * License. You may obtain a copy of the License at: 19 | * opensource.org/licenses/BSD-3-Clause 20 | * 21 | ****************************************************************************** 22 | */ 23 | 24 | /* Includes */ 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | 35 | /* Variables */ 36 | //#undef errno 37 | extern int errno; 38 | extern int __io_putchar(int ch) __attribute__((weak)); 39 | extern int __io_getchar(void) __attribute__((weak)); 40 | 41 | register char * stack_ptr asm("sp"); 42 | 43 | char *__env[1] = { 0 }; 44 | char **environ = __env; 45 | 46 | 47 | /* Functions */ 48 | void initialise_monitor_handles() 49 | { 50 | } 51 | 52 | int _getpid(void) 53 | { 54 | return 1; 55 | } 56 | 57 | int _kill(int pid, int sig) 58 | { 59 | errno = EINVAL; 60 | return -1; 61 | } 62 | 63 | void _exit (int status) 64 | { 65 | _kill(status, -1); 66 | while (1) {} /* Make sure we hang here */ 67 | } 68 | 69 | __attribute__((weak)) int _read(int file, char *ptr, int len) 70 | { 71 | int DataIdx; 72 | 73 | for (DataIdx = 0; DataIdx < len; DataIdx++) 74 | { 75 | *ptr++ = __io_getchar(); 76 | } 77 | 78 | return len; 79 | } 80 | 81 | __attribute__((weak)) int _write(int file, char *ptr, int len) 82 | { 83 | int DataIdx; 84 | 85 | for (DataIdx = 0; DataIdx < len; DataIdx++) 86 | { 87 | __io_putchar(*ptr++); 88 | } 89 | return len; 90 | } 91 | 92 | int _close(int file) 93 | { 94 | return -1; 95 | } 96 | 97 | 98 | int _fstat(int file, struct stat *st) 99 | { 100 | st->st_mode = S_IFCHR; 101 | return 0; 102 | } 103 | 104 | int _isatty(int file) 105 | { 106 | return 1; 107 | } 108 | 109 | int _lseek(int file, int ptr, int dir) 110 | { 111 | return 0; 112 | } 113 | 114 | int _open(char *path, int flags, ...) 115 | { 116 | /* Pretend like we always fail */ 117 | return -1; 118 | } 119 | 120 | int _wait(int *status) 121 | { 122 | errno = ECHILD; 123 | return -1; 124 | } 125 | 126 | int _unlink(char *name) 127 | { 128 | errno = ENOENT; 129 | return -1; 130 | } 131 | 132 | int _times(struct tms *buf) 133 | { 134 | return -1; 135 | } 136 | 137 | int _stat(char *file, struct stat *st) 138 | { 139 | st->st_mode = S_IFCHR; 140 | return 0; 141 | } 142 | 143 | int _link(char *old, char *new) 144 | { 145 | errno = EMLINK; 146 | return -1; 147 | } 148 | 149 | int _fork(void) 150 | { 151 | errno = EAGAIN; 152 | return -1; 153 | } 154 | 155 | int _execve(char *name, char **argv, char **env) 156 | { 157 | errno = ENOMEM; 158 | return -1; 159 | } 160 | -------------------------------------------------------------------------------- /port/platform/stm/stm32f4/test/STM32F437VGTX_FLASH.ld: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file LinkerScript.ld 4 | * @author Auto-generated by STM32CubeIDE 5 | * @brief Linker script for STM32F437VGTx Device from STM32F4 series 6 | * 1024Kbytes FLASH 7 | * 64Kbytes CCMRAM 8 | * 192Kbytes RAM 9 | * 10 | * Set heap size, stack size and stack location according 11 | * to application requirements. 12 | * 13 | * Set memory bank area and size if external memory is used 14 | ****************************************************************************** 15 | * @attention 16 | * 17 | *

© Copyright (c) 2020 STMicroelectronics. 18 | * All rights reserved.

19 | * 20 | * This software component is licensed by ST under BSD 3-Clause license, 21 | * the "License"; You may not use this file except in compliance with the 22 | * License. You may obtain a copy of the License at: 23 | * opensource.org/licenses/BSD-3-Clause 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Entry Point */ 29 | ENTRY(Reset_Handler) 30 | 31 | /* Highest address of the user mode stack */ 32 | _estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */ 33 | 34 | _Min_Heap_Size = 0x200; /* required amount of heap */ 35 | _Min_Stack_Size = 0x400; /* required amount of stack */ 36 | 37 | /* Memories definition */ 38 | MEMORY 39 | { 40 | CCMRAM (xrw) : ORIGIN = 0x10000000, LENGTH = 64K 41 | RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 192K 42 | FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 1024K 43 | } 44 | 45 | /* Sections */ 46 | SECTIONS 47 | { 48 | /* The startup code into "FLASH" Rom type memory */ 49 | .isr_vector : 50 | { 51 | . = ALIGN(4); 52 | KEEP(*(.isr_vector)) /* Startup code */ 53 | . = ALIGN(4); 54 | } >FLASH 55 | 56 | /* The program code and other data into "FLASH" Rom type memory */ 57 | .text : 58 | { 59 | . = ALIGN(4); 60 | *(.text) /* .text sections (code) */ 61 | *(.text*) /* .text* sections (code) */ 62 | *(.glue_7) /* glue arm to thumb code */ 63 | *(.glue_7t) /* glue thumb to arm code */ 64 | *(.eh_frame) 65 | 66 | KEEP (*(.init)) 67 | KEEP (*(.fini)) 68 | 69 | . = ALIGN(4); 70 | _etext = .; /* define a global symbols at end of code */ 71 | } >FLASH 72 | 73 | /* Constant data into "FLASH" Rom type memory */ 74 | .rodata : 75 | { 76 | . = ALIGN(4); 77 | *(.rodata) /* .rodata sections (constants, strings, etc.) */ 78 | *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ 79 | . = ALIGN(4); 80 | } >FLASH 81 | 82 | .ARM.extab : { 83 | . = ALIGN(4); 84 | *(.ARM.extab* .gnu.linkonce.armextab.*) 85 | . = ALIGN(4); 86 | } >FLASH 87 | 88 | .ARM : { 89 | . = ALIGN(4); 90 | __exidx_start = .; 91 | *(.ARM.exidx*) 92 | __exidx_end = .; 93 | . = ALIGN(4); 94 | } >FLASH 95 | 96 | .preinit_array : 97 | { 98 | . = ALIGN(4); 99 | PROVIDE_HIDDEN (__preinit_array_start = .); 100 | KEEP (*(.preinit_array*)) 101 | PROVIDE_HIDDEN (__preinit_array_end = .); 102 | . = ALIGN(4); 103 | } >FLASH 104 | 105 | .init_array : 106 | { 107 | . = ALIGN(4); 108 | PROVIDE_HIDDEN (__init_array_start = .); 109 | KEEP (*(SORT(.init_array.*))) 110 | KEEP (*(.init_array*)) 111 | PROVIDE_HIDDEN (__init_array_end = .); 112 | . = ALIGN(4); 113 | } >FLASH 114 | 115 | .fini_array : 116 | { 117 | . = ALIGN(4); 118 | PROVIDE_HIDDEN (__fini_array_start = .); 119 | KEEP (*(SORT(.fini_array.*))) 120 | KEEP (*(.fini_array*)) 121 | PROVIDE_HIDDEN (__fini_array_end = .); 122 | . = ALIGN(4); 123 | } >FLASH 124 | 125 | /* Used by the startup to initialize data */ 126 | _sidata = LOADADDR(.data); 127 | 128 | /* Initialized data sections into "RAM" Ram type memory */ 129 | .data : 130 | { 131 | . = ALIGN(4); 132 | _sdata = .; /* create a global symbol at data start */ 133 | *(.data) /* .data sections */ 134 | *(.data*) /* .data* sections */ 135 | 136 | . = ALIGN(4); 137 | _edata = .; /* define a global symbol at data end */ 138 | 139 | } >RAM AT> FLASH 140 | 141 | /* Uninitialized data section into "RAM" Ram type memory */ 142 | . = ALIGN(4); 143 | .bss : 144 | { 145 | /* This is used by the startup in order to initialize the .bss section */ 146 | _sbss = .; /* define a global symbol at bss start */ 147 | __bss_start__ = _sbss; 148 | *(.bss) 149 | *(.bss*) 150 | *(COMMON) 151 | 152 | . = ALIGN(4); 153 | _ebss = .; /* define a global symbol at bss end */ 154 | __bss_end__ = _ebss; 155 | } >RAM 156 | 157 | /* User_heap_stack section, used to check that there is enough "RAM" Ram type memory left */ 158 | ._user_heap_stack : 159 | { 160 | . = ALIGN(8); 161 | PROVIDE ( end = . ); 162 | PROVIDE ( _end = . ); 163 | . = . + _Min_Heap_Size; 164 | . = . + _Min_Stack_Size; 165 | . = ALIGN(8); 166 | } >RAM 167 | 168 | /* Remove information from the compiler libraries */ 169 | /DISCARD/ : 170 | { 171 | libc.a ( * ) 172 | libm.a ( * ) 173 | libgcc.a ( * ) 174 | } 175 | 176 | .ARM.attributes 0 : { *(.ARM.attributes) } 177 | } 178 | -------------------------------------------------------------------------------- /port/platform/stm/stm32f4/test/STM32F437VGTX_RAM.ld: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file LinkerScript.ld 4 | * @author Auto-generated by STM32CubeIDE 5 | * @brief Linker script for STM32F437VGTx Device from STM32F4 series 6 | * 1024Kbytes FLASH 7 | * 64Kbytes CCMRAM 8 | * 192Kbytes RAM 9 | * 10 | * Set heap size, stack size and stack location according 11 | * to application requirements. 12 | * 13 | * Set memory bank area and size if external memory is used 14 | ****************************************************************************** 15 | * @attention 16 | * 17 | *

© Copyright (c) 2020 STMicroelectronics. 18 | * All rights reserved.

19 | * 20 | * This software component is licensed by ST under BSD 3-Clause license, 21 | * the "License"; You may not use this file except in compliance with the 22 | * License. You may obtain a copy of the License at: 23 | * opensource.org/licenses/BSD-3-Clause 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Entry Point */ 29 | ENTRY(Reset_Handler) 30 | 31 | /* Highest address of the user mode stack */ 32 | _estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */ 33 | 34 | _Min_Heap_Size = 0x200; /* required amount of heap */ 35 | _Min_Stack_Size = 0x400; /* required amount of stack */ 36 | 37 | /* Memories definition */ 38 | MEMORY 39 | { 40 | CCMRAM (xrw) : ORIGIN = 0x10000000, LENGTH = 64K 41 | RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 192K 42 | FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 1024K 43 | } 44 | 45 | /* Sections */ 46 | SECTIONS 47 | { 48 | /* The startup code into "RAM" Ram type memory */ 49 | .isr_vector : 50 | { 51 | . = ALIGN(4); 52 | KEEP(*(.isr_vector)) /* Startup code */ 53 | . = ALIGN(4); 54 | } >RAM 55 | 56 | /* The program code and other data into "RAM" Ram type memory */ 57 | .text : 58 | { 59 | . = ALIGN(4); 60 | *(.text) /* .text sections (code) */ 61 | *(.text*) /* .text* sections (code) */ 62 | *(.glue_7) /* glue arm to thumb code */ 63 | *(.glue_7t) /* glue thumb to arm code */ 64 | *(.eh_frame) 65 | 66 | KEEP (*(.init)) 67 | KEEP (*(.fini)) 68 | 69 | . = ALIGN(4); 70 | _etext = .; /* define a global symbols at end of code */ 71 | } >RAM 72 | 73 | /* Constant data into "RAM" Ram type memory */ 74 | .rodata : 75 | { 76 | . = ALIGN(4); 77 | *(.rodata) /* .rodata sections (constants, strings, etc.) */ 78 | *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ 79 | . = ALIGN(4); 80 | } >RAM 81 | 82 | .ARM.extab : { 83 | . = ALIGN(4); 84 | *(.ARM.extab* .gnu.linkonce.armextab.*) 85 | . = ALIGN(4); 86 | } >RAM 87 | 88 | .ARM : { 89 | . = ALIGN(4); 90 | __exidx_start = .; 91 | *(.ARM.exidx*) 92 | __exidx_end = .; 93 | . = ALIGN(4); 94 | } >RAM 95 | 96 | .preinit_array : 97 | { 98 | . = ALIGN(4); 99 | PROVIDE_HIDDEN (__preinit_array_start = .); 100 | KEEP (*(.preinit_array*)) 101 | PROVIDE_HIDDEN (__preinit_array_end = .); 102 | . = ALIGN(4); 103 | } >RAM 104 | 105 | .init_array : 106 | { 107 | . = ALIGN(4); 108 | PROVIDE_HIDDEN (__init_array_start = .); 109 | KEEP (*(SORT(.init_array.*))) 110 | KEEP (*(.init_array*)) 111 | PROVIDE_HIDDEN (__init_array_end = .); 112 | . = ALIGN(4); 113 | } >RAM 114 | 115 | .fini_array : 116 | { 117 | . = ALIGN(4); 118 | PROVIDE_HIDDEN (__fini_array_start = .); 119 | KEEP (*(SORT(.fini_array.*))) 120 | KEEP (*(.fini_array*)) 121 | PROVIDE_HIDDEN (__fini_array_end = .); 122 | . = ALIGN(4); 123 | } >RAM 124 | 125 | /* Used by the startup to initialize data */ 126 | _sidata = LOADADDR(.data); 127 | 128 | /* Initialized data sections into "RAM" Ram type memory */ 129 | .data : 130 | { 131 | . = ALIGN(4); 132 | _sdata = .; /* create a global symbol at data start */ 133 | *(.data) /* .data sections */ 134 | *(.data*) /* .data* sections */ 135 | 136 | . = ALIGN(4); 137 | _edata = .; /* define a global symbol at data end */ 138 | 139 | } >RAM 140 | 141 | /* Uninitialized data section into "RAM" Ram type memory */ 142 | . = ALIGN(4); 143 | .bss : 144 | { 145 | /* This is used by the startup in order to initialize the .bss section */ 146 | _sbss = .; /* define a global symbol at bss start */ 147 | __bss_start__ = _sbss; 148 | *(.bss) 149 | *(.bss*) 150 | *(COMMON) 151 | 152 | . = ALIGN(4); 153 | _ebss = .; /* define a global symbol at bss end */ 154 | __bss_end__ = _ebss; 155 | } >RAM 156 | 157 | /* User_heap_stack section, used to check that there is enough "RAM" Ram type memory left */ 158 | ._user_heap_stack : 159 | { 160 | . = ALIGN(8); 161 | PROVIDE ( end = . ); 162 | PROVIDE ( _end = . ); 163 | . = . + _Min_Heap_Size; 164 | . = . + _Min_Stack_Size; 165 | . = ALIGN(8); 166 | } >RAM 167 | 168 | /* Remove information from the compiler libraries */ 169 | /DISCARD/ : 170 | { 171 | libc.a ( * ) 172 | libm.a ( * ) 173 | libgcc.a ( * ) 174 | } 175 | 176 | .ARM.attributes 0 : { *(.ARM.attributes) } 177 | } 178 | -------------------------------------------------------------------------------- /port/platform/stm/stm32f4/test/cellular_port_test_platform_specific.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 u-blox Cambourne Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _CELLULAR_PORT_TEST_PLATFORM_SPECIFIC_H_ 18 | #define _CELLULAR_PORT_TEST_PLATFORM_SPECIFIC_H_ 19 | 20 | /* Only bring in #includes specifically related to the test framework */ 21 | 22 | #include "cellular_port_unity_addons.h" 23 | 24 | /** Porting layer for test execution on the STM32 platform. 25 | * Since test execution is often macro-ised rather than 26 | * function-calling this header file forms part of the platform 27 | * test source code rather than pretending to be a generic API. 28 | */ 29 | 30 | /* ---------------------------------------------------------------- 31 | * COMPILE-TIME MACROS: UNITY RELATED 32 | * -------------------------------------------------------------- */ 33 | 34 | /** Macro to wrap a test assertion and map it to our Unity port. 35 | */ 36 | #define CELLULAR_PORT_TEST_ASSERT(condition) CELLULAR_PORT_UNITY_TEST_ASSERT(condition) 37 | 38 | /** Macro to wrap the definition of a test function and 39 | * map it to our Unity port. 40 | */ 41 | #define CELLULAR_PORT_TEST_FUNCTION(function, name, group) CELLULAR_PORT_UNITY_TEST_FUNCTION(name, group) 42 | 43 | /* ---------------------------------------------------------------- 44 | * COMPILE-TIME MACROS: OS RELATED 45 | * -------------------------------------------------------------- */ 46 | 47 | /** The stack size to use for the test task created during OS testing. 48 | */ 49 | #define CELLULAR_PORT_TEST_OS_TASK_STACK_SIZE_BYTES (1024 * 3) 50 | 51 | /** The task priority to use for the task created during. 52 | * testing. 53 | */ 54 | #define CELLULAR_PORT_TEST_OS_TASK_PRIORITY (CELLULAR_PORT_OS_PRIORITY_MIN + 5) 55 | 56 | /** The stack size to use for the test task created during sockets testing. 57 | */ 58 | #define CELLULAR_PORT_TEST_SOCK_TASK_STACK_SIZE_BYTES (1024 * 5) 59 | 60 | /** The priority to use for the test task created during sockets testing; 61 | * lower priority than the URC handler. 62 | */ 63 | #define CELLULAR_PORT_TEST_SOCK_TASK_PRIORITY (CELLULAR_CTRL_AT_TASK_URC_PRIORITY - 1) 64 | 65 | /* ---------------------------------------------------------------- 66 | * COMPILE-TIME MACROS: HW RELATED 67 | * -------------------------------------------------------------- */ 68 | 69 | /** Pin A for GPIO testing: will be used as an output and 70 | * must be connected to pin B via a 1k resistor. 71 | */ 72 | #ifndef CELLULAR_PORT_TEST_PIN_A 73 | # define CELLULAR_PORT_TEST_PIN_A 0x05 // AKA PA_5 or D5 on a C030 board 74 | #endif 75 | 76 | /** Pin B for GPIO testing: will be used as both an input and 77 | * and open drain output and must be connected both to pin A via 78 | * a 1k resistor and directly to pin C. 79 | */ 80 | #ifndef CELLULAR_PORT_TEST_PIN_B 81 | # define CELLULAR_PORT_TEST_PIN_B 0x18 // AKA PB_8 or D6 on a C030 board 82 | #endif 83 | 84 | /** Pin C for GPIO testing: must be connected to pin B, 85 | * will be used as an input only. 86 | */ 87 | #ifndef CELLULAR_PORT_TEST_PIN_C 88 | # define CELLULAR_PORT_TEST_PIN_C 0x1f // AKA PB_15 or D7 on a C030 board 89 | #endif 90 | 91 | /** UART HW block for UART driver testing. 92 | * Note: make sure that the corresponding 93 | * CELLULAR_CFG_UARTx_AVAILABLE for this UART is 94 | * set to 1 in cellular_cfg_hw_platform_specific.h 95 | */ 96 | #ifndef CELLULAR_PORT_TEST_UART 97 | # define CELLULAR_PORT_TEST_UART 3 // UART3 98 | #endif 99 | 100 | /** Handshake threshold for UART testing. 101 | */ 102 | #ifndef CELLULAR_PORT_TEST_UART_RTS_THRESHOLD 103 | # define CELLULAR_PORT_TEST_UART_RTS_THRESHOLD 0 // Not used on this platform 104 | #endif 105 | 106 | /** Tx pin for UART testing: should be connected to the Rx UART pin. 107 | */ 108 | #ifndef CELLULAR_PORT_TEST_PIN_UART_TXD 109 | # define CELLULAR_PORT_TEST_PIN_UART_TXD 0x38 // UART3 TX, PD_8 or D1 on a C030 board 110 | #endif 111 | 112 | /** Rx pin for UART testing: should be connected to the Tx UART pin. 113 | */ 114 | #ifndef CELLULAR_PORT_TEST_PIN_UART_RXD 115 | # define CELLULAR_PORT_TEST_PIN_UART_RXD 0x39 // UART3 RX, PD_9 or D0 on a C030 board 116 | #endif 117 | 118 | /** CTS pin for UART testing: should be connected to the RTS UART pin. 119 | */ 120 | #ifndef CELLULAR_PORT_TEST_PIN_UART_CTS 121 | # define CELLULAR_PORT_TEST_PIN_UART_CTS 0x3b // UART3 CTS, PD_11 or D2 on a C030 board 122 | #endif 123 | 124 | /** RTS pin for UART testing: should be connected to the CTS UART pin. 125 | */ 126 | #ifndef CELLULAR_PORT_TEST_PIN_UART_RTS 127 | # define CELLULAR_PORT_TEST_PIN_UART_RTS 0x1e // UART3 RTS, PB_14 or D3 on a C030 board 128 | #endif 129 | 130 | /* ---------------------------------------------------------------- 131 | * FUNCTIONS 132 | * -------------------------------------------------------------- */ 133 | 134 | #endif // _CELLULAR_PORT_TEST_PLATFORM_SPECIFIC_H_ 135 | 136 | // End of file 137 | -------------------------------------------------------------------------------- /port/platform/stm/stm32f4/test/main_test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 u-blox Cambourne Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifdef CELLULAR_CFG_OVERRIDE 18 | # include "cellular_cfg_override.h" // For a customer's configuration override 19 | #endif 20 | #include "cellular_cfg_sw.h" 21 | #include "cellular_cfg_os_platform_specific.h" 22 | #include "cellular_cfg_test.h" 23 | #include "cellular_port_clib.h" 24 | #include "cellular_port.h" 25 | #include "cellular_port_debug.h" 26 | #include "cellular_port_test_platform_specific.h" 27 | 28 | #include "cmsis_os.h" 29 | 30 | /* ---------------------------------------------------------------- 31 | * COMPILE-TIME MACROS 32 | * -------------------------------------------------------------- */ 33 | 34 | // How much stack the task running all the tests needs in bytes. 35 | #define CELLULAR_PORT_TEST_RUNNER_TASK_STACK_SIZE_BYTES (1024 * 4) 36 | 37 | // The priority of the task running the tests: should be low. 38 | #define CELLULAR_PORT_TEST_RUNNER_TASK_PRIORITY (CELLULAR_PORT_OS_PRIORITY_MIN + 1) 39 | 40 | /* ---------------------------------------------------------------- 41 | * TYPES 42 | * -------------------------------------------------------------- */ 43 | 44 | /* ---------------------------------------------------------------- 45 | * VARIABLES 46 | * -------------------------------------------------------------- */ 47 | 48 | /* ---------------------------------------------------------------- 49 | * STATIC FUNCTIONS 50 | * -------------------------------------------------------------- */ 51 | 52 | // The task within which testing runs. 53 | static void testTask(void *pParam) 54 | { 55 | (void) pParam; 56 | 57 | cellularPortInit(); 58 | cellularPortLog("\n\nCELLULAR_TEST: test task started.\n"); 59 | 60 | UNITY_BEGIN(); 61 | 62 | cellularPortLog("CELLULAR_TEST: tests available:\n\n"); 63 | cellularPortUnityPrintAll("CELLULAR_TEST: "); 64 | #ifdef CELLULAR_CFG_TEST_FILTER 65 | cellularPortLog("CELLULAR_TEST: running tests that begin with \"%s\".\n", 66 | CELLULAR_PORT_STRINGIFY_QUOTED(CELLULAR_CFG_TEST_FILTER)); 67 | cellularPortUnityRunFiltered(CELLULAR_PORT_STRINGIFY_QUOTED(CELLULAR_CFG_TEST_FILTER), 68 | "CELLULAR_TEST: "); 69 | #else 70 | cellularPortLog("CELLULAR_TEST: running all tests.\n"); 71 | cellularPortUnityRunAll("CELLULAR_TEST: "); 72 | #endif 73 | 74 | UNITY_END(); 75 | 76 | cellularPortLog("\n\nCELLULAR_TEST: test task ended.\n"); 77 | cellularPortDeinit(); 78 | 79 | while(1){} 80 | } 81 | 82 | /* ---------------------------------------------------------------- 83 | * PUBLIC FUNCTIONS 84 | * -------------------------------------------------------------- */ 85 | 86 | // Unity setUp() function. 87 | void setUp(void) 88 | { 89 | // Nothing to do 90 | } 91 | 92 | // Unity tearDown() function. 93 | void tearDown(void) 94 | { 95 | // Nothing to do 96 | } 97 | 98 | void testFail(void) 99 | { 100 | 101 | } 102 | 103 | // Entry point 104 | int main(void) 105 | { 106 | // Execute the test task 107 | cellularPortPlatformStart(testTask, NULL, 108 | CELLULAR_PORT_TEST_RUNNER_TASK_STACK_SIZE_BYTES, 109 | CELLULAR_PORT_TEST_RUNNER_TASK_PRIORITY); 110 | 111 | // Should never get here 112 | cellularPort_assert(false); 113 | 114 | return 0; 115 | } 116 | -------------------------------------------------------------------------------- /sock/README.md: -------------------------------------------------------------------------------- 1 | IMPORTANT: this API is still in the process of definition, anything may change, beware! We aim to have it settled by the middle of 2020, COVID 19 permitting. 2 | 3 | # Introduction 4 | These directories provide a driver that implements the user data (sockets) interface to a cellular module. The API presented is a Berkeley sockets API, similar to that of LWIP, allowing the files here to replace LWIP, providing a cellular-based sockets interface through the IP stack inside the cellular module instead. 5 | 6 | The files under the `ctrl` directory provide the actual AT interface to the cellular module and hence are required by this driver (and those of `port`, see next section) to achieve a usable binary image. 7 | 8 | # Usage 9 | The directories include only the API and pure C source files that make no reference to a platform, a C library or an operating system. They rely upon the `port` directory to map to a target platform and provide the necessary build/test infrastructure for that target platform; see the relevant platform directory under `port` for build and usage information. 10 | 11 | # Testing 12 | The `test` directory contains generic tests for the `sock` API. Please refer to the relevant platform directory of the `port` component for instructions on how to build and run the tests. --------------------------------------------------------------------------------