diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 46e2facbde..0073b79d99 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -13,7 +13,7 @@ RUN apt-get update -qq \ python3-pip \ tar \ unzip \ - wget \ + wget \ curl \ dos2unix \ clang-format-12 \ @@ -23,15 +23,15 @@ RUN apt-get update -qq \ # aarch64 packages libffi-dev \ libssl-dev \ - python3-dev \ + python3-dev \ rustc \ && rm -rf /var/cache/apt/* /var/lib/apt/lists/*; - -#SET LOCALE + +#SET LOCALE RUN locale-gen en_US.UTF-8 ENV LANG en_US.UTF-8 ENV LANGUAGE en_US:en -ENV LC_ALL en_US.UTF-8 +ENV LC_ALL en_US.UTF-8 RUN pip3 install adafruit-nrfutil # required for McuBoot @@ -47,7 +47,7 @@ RUN chmod +x create_build_openocd.sh # Lets get each in a separate docker layer for better downloads # GCC # RUN bash -c "source /opt/build.sh; GetGcc;" -RUN wget https://developer.arm.com/-/media/Files/downloads/gnu-rm/9-2020q2/gcc-arm-none-eabi-9-2020-q2-update-x86_64-linux.tar.bz2 -O - | tar -xj -C /opt +RUN wget https://developer.arm.com/-/media/Files/downloads/gnu-rm/10.3-2021.10/gcc-arm-none-eabi-10.3-2021.10-x86_64-linux.tar.bz2 -O - | tar -xj -C /opt # NrfSdk # RUN bash -c "source /opt/build.sh; GetNrfSdk;" RUN wget -q "https://developer.nordicsemi.com/nRF5_SDK/nRF5_SDK_v15.x.x/nRF5_SDK_15.3.0_59ac345.zip" -O /tmp/nRF5_SDK_15.3.0_59ac345 @@ -61,5 +61,5 @@ RUN pip3 install -r ./mcuboot/scripts/requirements.txt RUN adduser infinitime ENV NRF5_SDK_PATH /opt/nRF5_SDK_15.3.0_59ac345 -ENV ARM_NONE_EABI_TOOLCHAIN_PATH /opt/gcc-arm-none-eabi-9-2020-q2-update +ENV ARM_NONE_EABI_TOOLCHAIN_PATH /opt/gcc-arm-none-eabi-10.3-2021.10 ENV SOURCES_DIR /workspaces/InfiniTime diff --git a/.devcontainer/build.sh b/.devcontainer/build.sh index 5dcdf91dc0..cbc3f57cc7 100644 --- a/.devcontainer/build.sh +++ b/.devcontainer/build.sh @@ -12,7 +12,7 @@ export BUILD_DIR="${BUILD_DIR:=$SOURCES_DIR/build}" export OUTPUT_DIR="${OUTPUT_DIR:=$BUILD_DIR/output}" export BUILD_TYPE=${BUILD_TYPE:=Release} -export GCC_ARM_VER=${GCC_ARM_VER:="gcc-arm-none-eabi-9-2020-q2-update"} +export GCC_ARM_VER=${GCC_ARM_VER:="gcc-arm-none-eabi-10.3-2021.10"} export NRF_SDK_VER=${NRF_SDK_VER:="nRF5_SDK_15.3.0_59ac345"} MACHINE="$(uname -m)" @@ -22,7 +22,7 @@ main() { local target="$1" mkdir -p "$TOOLS_DIR" - + [[ ! -d "$TOOLS_DIR/$GCC_ARM_VER" ]] && GetGcc [[ ! -d "$TOOLS_DIR/$NRF_SDK_VER" ]] && GetNrfSdk [[ ! -d "$TOOLS_DIR/mcuboot" ]] && GetMcuBoot @@ -31,7 +31,7 @@ main() { CmakeGenerate CmakeBuild $target - BUILD_RESULT=$? + BUILD_RESULT=$? if [ "$DISABLE_POSTBUILD" != "true" -a "$BUILD_RESULT" == 0 ]; then source "$BUILD_DIR/post_build.sh" fi @@ -71,8 +71,8 @@ CmakeBuild() { local target="$1" [[ -n "$target" ]] && target="--target $target" if cmake --build "$BUILD_DIR" --config $BUILD_TYPE $target -- -j$(nproc) - then return 0; else return 1; + then return 0; else return 1; fi } -[[ $SOURCED == "false" ]] && main "$@" || echo "Sourced!" \ No newline at end of file +[[ $SOURCED == "false" ]] && main "$@" || echo "Sourced!" diff --git a/.devcontainer/create_build_openocd.sh b/.devcontainer/create_build_openocd.sh index c5bff5c89b..dee35aabb3 100644 --- a/.devcontainer/create_build_openocd.sh +++ b/.devcontainer/create_build_openocd.sh @@ -1,3 +1,3 @@ #!/bin/bash rm -rf build/ -cmake -G 'Unix Makefiles' -DCMAKE_BUILD_TYPE=Release -DUSE_OPENOCD=1 -DARM_NONE_EABI_TOOLCHAIN_PATH=/opt/gcc-arm-none-eabi-9-2020-q2-update -DNRF5_SDK_PATH=/opt/nRF5_SDK_15.3.0_59ac345 -S . -Bbuild \ No newline at end of file +cmake -G 'Unix Makefiles' -DCMAKE_BUILD_TYPE=Release -DUSE_OPENOCD=1 -DARM_NONE_EABI_TOOLCHAIN_PATH=/opt/gcc-arm-none-eabi-10.3-2021.10 -DNRF5_SDK_PATH=/opt/nRF5_SDK_15.3.0_59ac345 -S . -Bbuild diff --git a/.devcontainer/make_build_dir.sh b/.devcontainer/make_build_dir.sh index 76240037c2..27076cb531 100644 --- a/.devcontainer/make_build_dir.sh +++ b/.devcontainer/make_build_dir.sh @@ -1,2 +1,2 @@ #!/bin/bash -cmake -G 'Unix Makefiles' -DCMAKE_BUILD_TYPE=Release -DUSE_OPENOCD=1 -DARM_NONE_EABI_TOOLCHAIN_PATH=/opt/gcc-arm-none-eabi-9-2020-q2-update -DNRF5_SDK_PATH=/opt/nRF5_SDK_15.3.0_59ac345 ${SOURCES_DIR} +cmake -G 'Unix Makefiles' -DCMAKE_BUILD_TYPE=Release -DUSE_OPENOCD=1 -DARM_NONE_EABI_TOOLCHAIN_PATH=/opt/gcc-arm-none-eabi-10.3-2021.10 -DNRF5_SDK_PATH=/opt/nRF5_SDK_15.3.0_59ac345 ${SOURCES_DIR} diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3b753a374c..b4905f71d9 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -32,24 +32,24 @@ jobs: - name: Install cmake uses: lukka/get-cmake@v3.18.3 - - name: Check cache for Embedded Arm Toolchain arm-none-eabi-gcc - id: cache-toolchain - uses: actions/cache@v2 - env: - cache-name: cache-toolchain-9-2020-q2 - with: - path: ${{ runner.temp }}/arm-none-eabi - key: ${{ runner.os }}-build-${{ env.cache-name }} - restore-keys: ${{ runner.os }}-build-${{ env.cache-name }} - - - name: Install Embedded Arm Toolchain arm-none-eabi-gcc - if: steps.cache-toolchain.outputs.cache-hit != 'true' # Install toolchain if not found in cache - uses: fiam/arm-none-eabi-gcc@v1.0.4 + #- name: Check cache for Embedded Arm Toolchain arm-none-eabi-gcc + # id: cache-toolchain + # uses: actions/cache@v2 + # env: + # cache-name: cache-toolchain-10.3-2021.10 + # with: + # path: ${{ runner.temp }}/arm-none-eabi + # key: ${{ runner.os }}-build-${{ env.cache-name }} + # restore-keys: ${{ runner.os }}-build-${{ env.cache-name }} + + - name: Install Embedded ARM Toolchain arm-none-eabi-gcc + if: steps.cache-toolchain.outputs.cache-hit != 'true' # Install toolchain if not found in cache + uses: carlosperate/arm-none-eabi-gcc-action@v1.3.0 with: - # GNU Embedded Toolchain for Arm release name, in the V-YYYY-qZ format (e.g. "9-2019-q4") - release: 9-2020-q2 - # Directory to unpack GCC to. Defaults to a temporary directory. - directory: ${{ runner.temp }}/arm-none-eabi + # GNU Embedded Toolchain for ARM release name, in the V-YYYY-qZ format (e.g. "9-2019-q4") + release: 10.3-2021.10 + # Enviroment variable where to store the toolchain's path + path-env-var: ARM_NONE_EABI_GCC_PATH - name: Check cache for nRF5 SDK id: cache-nrf5sdk @@ -113,7 +113,7 @@ jobs: run: | mkdir -p build cd build - cmake -DARM_NONE_EABI_TOOLCHAIN_PATH=${{ runner.temp }}/arm-none-eabi -DNRF5_SDK_PATH=${{ runner.temp }}/nrf5_sdk -DUSE_OPENOCD=1 -DBUILD_DFU=1 ../ + cmake -DARM_NONE_EABI_TOOLCHAIN_PATH=$(dirname "$ARM_NONE_EABI_GCC_PATH") -DNRF5_SDK_PATH=${{ runner.temp }}/nrf5_sdk -DUSE_OPENOCD=1 -DBUILD_DFU=1 ../ ######################################################################################### # Make and Upload DFU Package diff --git a/.vscode/launch.json b/.vscode/launch.json index 3d9aa78921..080ed04651 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -52,13 +52,12 @@ "servertype": "openocd", "runToMain": true, // Only use armToolchainPath if your arm-none-eabi-gdb is not in your path (some GCC packages does not contain arm-none-eabi-gdb) - "armToolchainPath": "${workspaceRoot}/../gcc-arm-none-eabi-9-2020-q2-update/bin", + "armToolchainPath": "${workspaceRoot}/../gcc-arm-none-eabi-10.3-2021.10/bin", "svdFile": "${workspaceRoot}/nrf52.svd", "configFiles": [ "interface/stlink.cfg", "target/nrf52.cfg" - ], + ] } - ] } diff --git a/doc/MemoryAnalysis.md b/doc/MemoryAnalysis.md index 7304e3f320..5684ad32c3 100644 --- a/doc/MemoryAnalysis.md +++ b/doc/MemoryAnalysis.md @@ -51,12 +51,12 @@ Puncover is really easy to install: - `python -m virtualenv venv` - `source venv/bin/activate` - Install : `pip install .` - - Run : `puncover --gcc_tools_base=/path/to/gcc-arm-none-eabi-9-2020-q2-update/bin/arm-none-eabi- --elf_file /path/to/build/directory/src/pinetime-app-1.1.0.out --src_root /path/to/sources --build_dir /path/to/build/directory` + - Run : `puncover --gcc_tools_base=/path/to/gcc-arm-none-eabi-10.3-2021.10/bin/arm-none-eabi- --elf_file /path/to/build/directory/src/pinetime-app-1.1.0.out --src_root /path/to/sources --build_dir /path/to/build/directory` - Replace - * `/path/to/gcc-arm-none-eabi-9-2020-q2-update/bin` with the path to your gcc-arm-none-eabi toolchain + * `/path/to/gcc-arm-none-eabi-10.3-2021.10/bin` with the path to your gcc-arm-none-eabi toolchain * `/path/to/build/directory/src/pinetime-app-1.1.0.out` with the path to the binary generated by GCC (.out file) * `/path/to/sources` with the path to the root folder of the sources (checkout directory) - * `/path/to/build/directory` with the path to the build directory + * `/path/to/build/directory` with the path to the build directory - Launch a browser at http://localhost:5000/ ### Analysis @@ -285,5 +285,3 @@ auto nb = uxTaskGetSystemState(tasksStatus, 10, NULL); for (int i = 0; i < nb; i++) { NRF_LOG_INFO("Task [%s] - %d", tasksStatus[i].pcTaskName, tasksStatus[i].usStackHighWaterMark); ``` - - diff --git a/doc/buildAndProgram.md b/doc/buildAndProgram.md index 3686871a4c..ce3fe99ca6 100644 --- a/doc/buildAndProgram.md +++ b/doc/buildAndProgram.md @@ -27,12 +27,12 @@ CMake configures the project according to variables you specify the command line Variable | Description | Example| ----------|-------------|--------| -**ARM_NONE_EABI_TOOLCHAIN_PATH**|path to the toolchain directory|`-DARM_NONE_EABI_TOOLCHAIN_PATH=/home/jf/nrf52/gcc-arm-none-eabi-9-2020-q2-update/`| +**ARM_NONE_EABI_TOOLCHAIN_PATH**|path to the toolchain directory|`-DARM_NONE_EABI_TOOLCHAIN_PATH=/home/jf/nrf52/gcc-arm-none-eabi-10.3-2021.10/`| **NRF5_SDK_PATH**|path to the NRF52 SDK|`-DNRF5_SDK_PATH=/home/jf/nrf52/Pinetime/sdk`| **USE_JLINK, USE_GDB_CLIENT and USE_OPENOCD**|Enable *JLink* mode, *GDB Client* (Black Magic Probe) mode or *OpenOCD* mode (set the one you want to use to `1`)|`-DUSE_JLINK=1` **CMAKE_BUILD_TYPE (\*)**| Build type (Release or Debug). Release is applied by default if this variable is not specified.|`-DCMAKE_BUILD_TYPE=Debug` **NRFJPROG**|Path to the NRFJProg executable. Used only if `USE_JLINK` is 1.|`-DNRFJPROG=/opt/nrfjprog/nrfjprog` -**GDB_CLIENT_BIN_PATH**|Path to arm-none-eabi-gdb executable. Used only if `USE_GDB_CLIENT` is 1.|`-DGDB_CLIENT_BIN_PATH=/home/jf/nrf52/gcc-arm-none-eabi-9-2019-q4-major/bin/arm-none-eabi-gdb` +**GDB_CLIENT_BIN_PATH**|Path to arm-none-eabi-gdb executable. Used only if `USE_GDB_CLIENT` is 1.|`-DGDB_CLIENT_BIN_PATH=/home/jf/nrf52/gcc-arm-none-eabi-10.3-2021.10/bin/arm-none-eabi-gdb` **GDB_CLIENT_TARGET_REMOTE**|Target remote connection string. Used only if `USE_GDB_CLIENT` is 1.|`-DGDB_CLIENT_TARGET_REMOTE=/dev/ttyACM0` **BUILD_DFU (\*\*)**|Build DFU files while building (needs [adafruit-nrfutil](https://github.com/adafruit/Adafruit_nRF52_nrfutil)).|`-DBUILD_DFU=1` **WATCH_COLMI_P8**|Use pin configuration for Colmi P8 watch|`-DWATCH_COLMI_P8=1` diff --git a/doc/buildWithVScode.md b/doc/buildWithVScode.md index 23c9714586..84fd34ec15 100644 --- a/doc/buildWithVScode.md +++ b/doc/buildWithVScode.md @@ -6,9 +6,9 @@ The .VS Code folder contains configuration files for developing InfiniTime with To support as many setups as possible the VS Code configuration files expect there to be certain environment variables to be set. - Variable | Description | Example +Variable | Description | Example ----------|-------------|-------- -**ARM_NONE_EABI_TOOLCHAIN_PATH**|path to the toolchain directory|`export ARM_NONE_EABI_TOOLCHAIN_PATH=/opt/gcc-arm-none-eabi-9-2020-q2-update` +**ARM_NONE_EABI_TOOLCHAIN_PATH**|path to the toolchain directory|`export ARM_NONE_EABI_TOOLCHAIN_PATH=/opt/gcc-arm-none-eabi-10.3-2021.10` **NRF5_SDK_PATH**|path to the NRF52 SDK|`export NRF5_SDK_PATH=/opt/nRF5_SDK_15.3.0_59ac345` ## VS Code Extensions @@ -47,6 +47,3 @@ To use the DevContainer configuration on Ubuntu based systems two changes need t 3. To start debugging launch openocd on your host system with the appropriate configuration, for example with a stlink-v2 the command is: ``openocd -f interface/stlink.cfg -f target/nrf52.cfg``. This launches openocd with the default ports ``3333``, ``4444`` and ``6666``. 4. In VsCode go to the Debug pane on the left of the screen and select the configuration ``Debug - Openocd docker Remote`` and hit the play button on the left. - - - diff --git a/docker/build.sh b/docker/build.sh index d86e7c21d6..ac9ebb2b49 100755 --- a/docker/build.sh +++ b/docker/build.sh @@ -12,7 +12,7 @@ export BUILD_DIR="${BUILD_DIR:=$SOURCES_DIR/build}" export OUTPUT_DIR="${OUTPUT_DIR:=$BUILD_DIR/output}" export BUILD_TYPE=${BUILD_TYPE:=Release} -export GCC_ARM_VER=${GCC_ARM_VER:="gcc-arm-none-eabi-9-2020-q2-update"} +export GCC_ARM_VER=${GCC_ARM_VER:="gcc-arm-none-eabi-10.3-2021.10"} export NRF_SDK_VER=${NRF_SDK_VER:="nRF5_SDK_15.3.0_59ac345"} MACHINE="$(uname -m)" @@ -22,7 +22,7 @@ main() { local target="$1" mkdir -p "$TOOLS_DIR" - + [[ ! -d "$TOOLS_DIR/$GCC_ARM_VER" ]] && GetGcc [[ ! -d "$TOOLS_DIR/$NRF_SDK_VER" ]] && GetNrfSdk [[ ! -d "$TOOLS_DIR/mcuboot" ]] && GetMcuBoot @@ -31,7 +31,7 @@ main() { CmakeGenerate CmakeBuild $target - BUILD_RESULT=$? + BUILD_RESULT=$? if [ "$DISABLE_POSTBUILD" != "true" -a "$BUILD_RESULT" == 0 ]; then source "$BUILD_DIR/post_build.sh" fi @@ -72,8 +72,8 @@ CmakeBuild() { local target="$1" [[ -n "$target" ]] && target="--target $target" if cmake --build "$BUILD_DIR" --config $BUILD_TYPE $target -- -j$(nproc) - then return 0; else return 1; + then return 0; else return 1; fi } -[[ $SOURCED == "false" ]] && main "$@" || echo "Sourced!" \ No newline at end of file +[[ $SOURCED == "false" ]] && main "$@" || echo "Sourced!" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 809544c92f..a58c942241 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -802,8 +802,7 @@ link_directories( ../ ) - -set(COMMON_FLAGS -MP -MD -mthumb -mabi=aapcs -Wall -Wextra -Warray-bounds=2 -Wformat=2 -Wformat-overflow=2 -Wformat-truncation=2 -Wformat-nonliteral -ftree-vrp -Wno-unused-parameter -Wno-missing-field-initializers -Wno-unknown-pragmas -Wno-expansion-to-defined -g3 -ffunction-sections -fdata-sections -fno-strict-aliasing -fno-builtin --short-enums -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -Wreturn-type -Werror=return-type -fstack-usage -fno-exceptions -fno-non-call-exceptions) +set(COMMON_FLAGS -MP -MD -mthumb -mabi=aapcs -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -flto -Wl,-flto -fuse-linker-plugin -Wl,-fuse-linker-plugin -fstack-usage -ftree-vrp -fstrict-aliasing -fshort-enums -fno-fat-lto-objects -fno-exceptions -fno-non-call-exceptions -fno-builtin -Wall -Wextra -Warray-bounds=2 -Wformat=2 -Wformat-overflow=2 -Wformat-truncation=2 -Wformat-nonliteral -Wreturn-type -Wno-unknown-pragmas -Werror=return-type -Os -g3) add_definitions(-DCONFIG_GPIO_AS_PINRESET) add_definitions(-DNIMBLE_CFG_CONTROLLER) add_definitions(-DOS_CPUTIME_FREQ) @@ -820,6 +819,10 @@ if (NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE "Release") endif () +if (CMAKE_BUILD_TYPE MATCHES Release) + set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE) +endif () + # NRF SDK add_library(nrf-sdk STATIC ${SDK_SOURCE_FILES}) target_include_directories(nrf-sdk SYSTEM PUBLIC . ../) @@ -837,10 +840,10 @@ add_library(nimble STATIC ${NIMBLE_SRC} ${TINYCRYPT_SRC}) target_include_directories(nimble SYSTEM PUBLIC . ../) target_include_directories(nimble SYSTEM PUBLIC ${INCLUDES_FROM_LIBS}) target_compile_options(nimble PRIVATE - $<$,$>: ${COMMON_FLAGS} -Og -g3 -Wno-unused-but-set-variable -Wno-maybe-uninitialized> - $<$,$>: ${COMMON_FLAGS} -Os -Wno-unused-but-set-variable -Wno-maybe-uninitialized> - $<$,$>: ${COMMON_FLAGS} -Og -g3 -Wno-unused-but-set-variable -Wno-maybe-uninitialized -fno-rtti> - $<$,$>: ${COMMON_FLAGS} -Os -Wno-unused-but-set-variable -Wno-maybe-uninitialized -fno-rtti> + $<$,$>: ${COMMON_FLAGS} -Og -g3 -Wno-unused-parameter -Wno-unused-but-set-variable -Wno-maybe-uninitialized> + $<$,$>: ${COMMON_FLAGS} -Os -Wno-unused-parameter -Wno-unused-but-set-variable -Wno-maybe-uninitialized> + $<$,$>: ${COMMON_FLAGS} -Og -g3 -Wno-unused-parameter -Wno-unused-but-set-variable -Wno-maybe-uninitialized -fno-rtti> + $<$,$>: ${COMMON_FLAGS} -Os -Wno-unused-parameter -Wno-unused-but-set-variable -Wno-maybe-uninitialized -fno-rtti> $<$: -MP -MD -x assembler-with-cpp> ) @@ -893,7 +896,8 @@ set(EXECUTABLE_FILE_NAME ${EXECUTABLE_NAME}-${pinetime_VERSION_MAJOR}.${pinetime set(NRF5_LINKER_SCRIPT "${CMAKE_SOURCE_DIR}/gcc_nrf52.ld") add_executable(${EXECUTABLE_NAME} ${SOURCE_FILES}) set_target_properties(${EXECUTABLE_NAME} PROPERTIES OUTPUT_NAME ${EXECUTABLE_FILE_NAME}) -target_link_libraries(${EXECUTABLE_NAME} nimble nrf-sdk lvgl littlefs QCBOR) +target_link_libraries(${EXECUTABLE_NAME} nimble lvgl littlefs QCBOR nrf-sdk) +target_link_options(${EXECUTABLE_NAME} PUBLIC -Os -fno-fat-lto-objects -fuse-linker-plugin -Wl,-z,now) target_compile_options(${EXECUTABLE_NAME} PUBLIC $<$,$>: ${COMMON_FLAGS} -Wextra -Wformat -Wno-missing-field-initializers -Wno-unused-parameter -Og -g3> $<$,$>: ${COMMON_FLAGS} -Wextra -Wformat -Wno-missing-field-initializers -Wno-unused-parameter -Os> @@ -922,8 +926,9 @@ set(IMAGE_MCUBOOT_FILE_NAME ${EXECUTABLE_MCUBOOT_NAME}-image-${pinetime_VERSION_ set(DFU_MCUBOOT_FILE_NAME ${EXECUTABLE_MCUBOOT_NAME}-dfu-${pinetime_VERSION_MAJOR}.${pinetime_VERSION_MINOR}.${pinetime_VERSION_PATCH}.zip) set(NRF5_LINKER_SCRIPT_MCUBOOT "${CMAKE_SOURCE_DIR}/gcc_nrf52-mcuboot.ld") add_executable(${EXECUTABLE_MCUBOOT_NAME} ${SOURCE_FILES}) -target_link_libraries(${EXECUTABLE_MCUBOOT_NAME} nimble nrf-sdk lvgl littlefs QCBOR) set_target_properties(${EXECUTABLE_MCUBOOT_NAME} PROPERTIES OUTPUT_NAME ${EXECUTABLE_MCUBOOT_FILE_NAME}) +target_link_libraries(${EXECUTABLE_MCUBOOT_NAME} nimble lvgl littlefs QCBOR nrf-sdk) +target_link_options(${EXECUTABLE_MCUBOOT_NAME} PUBLIC -Os -fno-fat-lto-objects -fuse-linker-plugin -Wl,-z,now) target_compile_options(${EXECUTABLE_MCUBOOT_NAME} PUBLIC $<$,$>: ${COMMON_FLAGS} -Og -g3> $<$,$>: ${COMMON_FLAGS} -Os> @@ -952,13 +957,14 @@ if(BUILD_DFU) COMMAND adafruit-nrfutil dfu genpkg --dev-type 0x0052 --application ${IMAGE_MCUBOOT_FILE_NAME} ${DFU_MCUBOOT_FILE_NAME} COMMENT "post build (DFU) steps for ${EXECUTABLE_MCUBOOT_FILE_NAME}" ) -endif() +endif () # InfiniTime recovery firmware (autonomous) set(EXECUTABLE_RECOVERY_NAME "pinetime-recovery") set(EXECUTABLE_RECOVERY_FILE_NAME ${EXECUTABLE_RECOVERY_NAME}-${pinetime_VERSION_MAJOR}.${pinetime_VERSION_MINOR}.${pinetime_VERSION_PATCH}) add_executable(${EXECUTABLE_RECOVERY_NAME} ${RECOVERY_SOURCE_FILES}) -target_link_libraries(${EXECUTABLE_RECOVERY_NAME} nimble nrf-sdk littlefs QCBOR) +target_link_libraries(${EXECUTABLE_RECOVERY_NAME} nimble lvgl littlefs QCBOR nrf-sdk) +target_link_options(${EXECUTABLE_RECOVERY_NAME} PUBLIC -Os -fno-fat-lto-objects -fuse-linker-plugin -Wl,-z,now) set_target_properties(${EXECUTABLE_RECOVERY_NAME} PROPERTIES OUTPUT_NAME ${EXECUTABLE_RECOVERY_FILE_NAME}) target_compile_definitions(${EXECUTABLE_RECOVERY_NAME} PUBLIC "PINETIME_IS_RECOVERY") target_compile_options(${EXECUTABLE_RECOVERY_NAME} PUBLIC @@ -988,7 +994,8 @@ set(EXECUTABLE_RECOVERY_MCUBOOT_FILE_NAME ${EXECUTABLE_RECOVERY_MCUBOOT_NAME}-${ set(IMAGE_RECOVERY_MCUBOOT_FILE_NAME ${EXECUTABLE_RECOVERY_MCUBOOT_NAME}-image-${pinetime_VERSION_MAJOR}.${pinetime_VERSION_MINOR}.${pinetime_VERSION_PATCH}.bin) set(DFU_RECOVERY_MCUBOOT_FILE_NAME ${EXECUTABLE_RECOVERY_MCUBOOT_NAME}-dfu-${pinetime_VERSION_MAJOR}.${pinetime_VERSION_MINOR}.${pinetime_VERSION_PATCH}.zip) add_executable(${EXECUTABLE_RECOVERY_MCUBOOT_NAME} ${RECOVERY_SOURCE_FILES}) -target_link_libraries(${EXECUTABLE_RECOVERY_MCUBOOT_NAME} nimble nrf-sdk littlefs QCBOR) +target_link_libraries(${EXECUTABLE_RECOVERY_MCUBOOT_NAME} nimble lvgl littlefs QCBOR nrf-sdk) +target_link_options(${EXECUTABLE_RECOVERY_MCUBOOT_NAME} PUBLIC -Os -fno-fat-lto-objects -fuse-linker-plugin -Wl,-z,now) set_target_properties(${EXECUTABLE_RECOVERY_MCUBOOT_NAME} PROPERTIES OUTPUT_NAME ${EXECUTABLE_RECOVERY_MCUBOOT_FILE_NAME}) target_compile_definitions(${EXECUTABLE_RECOVERY_MCUBOOT_NAME} PUBLIC "PINETIME_IS_RECOVERY") target_compile_options(${EXECUTABLE_RECOVERY_MCUBOOT_NAME} PUBLIC diff --git a/src/FreeRTOS/port.c b/src/FreeRTOS/port.c index 5b5b4f176e..803919304e 100644 --- a/src/FreeRTOS/port.c +++ b/src/FreeRTOS/port.c @@ -73,26 +73,25 @@ void vPortStartFirstTask( void ) #ifdef SOFTDEVICE_PRESENT ::"i"(configKERNEL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS)) #endif - ); + " .ltorg \n"); } /*-----------------------------------------------------------*/ -void vPortSVCHandler( void ) -{ - __asm volatile ( - " ldr r3, =pxCurrentTCB \n" /* Restore the context. */ - " ldr r1, [r3] \n" /* Use pxCurrentTCBConst to get the pxCurrentTCB address. */ - " ldr r0, [r1] \n" /* The first item in pxCurrentTCB is the task top of stack. */ - " ldmia r0!, {r4-r11, r14} \n" /* Pop the registers that are not automatically saved on exception entry and the critical nesting count. */ - " msr psp, r0 \n" /* Restore the task stack pointer. */ - " isb \n" - " mov r0, #0 \n" - " msr basepri, r0 \n" - " bx r14 \n" - " \n" - " .align 2 \n" - ); +void __attribute__((used)) vPortSVCHandler(void) { + __asm volatile(" ldr r3, =pxCurrentTCB \n" /* Restore the context. */ + " ldr r1, [r3] \n" /* Use pxCurrentTCBConst to get the pxCurrentTCB address. */ + " ldr r0, [r1] \n" /* The first item in pxCurrentTCB is the task top of stack. */ + " ldmia r0!, {r4-r11, r14} \n" /* Pop the registers that are not automatically saved on exception entry and the + critical nesting count. */ + " msr psp, r0 \n" /* Restore the task stack pointer. */ + " isb \n" + " mov r0, #0 \n" + " msr basepri, r0 \n" + " bx r14 \n" + " \n" + " .align 2 \n" + " .ltorg \n"); } /*-----------------------------------------------------------*/ @@ -132,17 +131,16 @@ void xPortPendSVHandler( void ) " \n" " ldmia r0!, {r4-r11, r14} \n" /* Pop the core registers. */ " \n" - " tst r14, #0x10 \n" /* Is the task using the FPU context? If so, pop the high vfp registers too. */ - " it eq \n" - " vldmiaeq r0!, {s16-s31} \n" - " \n" - " msr psp, r0 \n" - " isb \n" - " \n" - " \n" - " bx r14 \n" - " \n" - " .align 2 \n" - ::"i"(configMAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS)) - ); + " tst r14, #0x10 \n" /* Is the task using the FPU context? If so, pop the high vfp registers too. */ + " it eq \n" + " vldmiaeq r0!, {s16-s31} \n" + " \n" + " msr psp, r0 \n" + " isb \n" + " \n" + " \n" + " bx r14 \n" + " \n" + " .align 2 \n" + " .ltorg \n" ::"i"(configMAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS))); } diff --git a/src/components/heartrate/Ppg.h b/src/components/heartrate/Ppg.h index ed79b08220..c6e07cb049 100644 --- a/src/components/heartrate/Ppg.h +++ b/src/components/heartrate/Ppg.h @@ -1,5 +1,7 @@ #pragma once +#include +#include #include #include "components/heartrate/Biquad.h" #include "components/heartrate/Ptagc.h" diff --git a/src/components/motor/MotorController.cpp b/src/components/motor/MotorController.cpp index c794a02c99..8be3f139ff 100644 --- a/src/components/motor/MotorController.cpp +++ b/src/components/motor/MotorController.cpp @@ -1,7 +1,7 @@ #include "components/motor/MotorController.h" #include #include "systemtask/SystemTask.h" -#include "app_timer.h" +#include #include "drivers/PinMap.h" APP_TIMER_DEF(shortVibTimer); diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index f050e65d4c..e9d1a5156b 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -1,3 +1,6 @@ +#include +#include + #include "displayapp/DisplayApp.h" #include #include "displayapp/screens/HeartRate.h" @@ -130,7 +133,7 @@ void DisplayApp::Start(System::BootErrors error) { } } -void DisplayApp::Process(void* instance) { +[[noreturn]] void DisplayApp::Process(void* instance) { auto* app = static_cast(instance); NRF_LOG_INFO("displayapp task started!"); app->InitHw(); diff --git a/src/displayapp/DisplayApp.h b/src/displayapp/DisplayApp.h index 39fe631455..65dd9a9ae6 100644 --- a/src/displayapp/DisplayApp.h +++ b/src/displayapp/DisplayApp.h @@ -108,7 +108,7 @@ namespace Pinetime { TouchEvents returnTouchEvent = TouchEvents::None; TouchEvents GetGesture(); - static void Process(void* instance); + [[noreturn]] static void Process(void* instance); void InitHw(); void Refresh(); void ReturnApp(Apps app, DisplayApp::FullRefreshDirections direction, TouchEvents touchEvent); diff --git a/src/displayapp/DisplayAppRecovery.cpp b/src/displayapp/DisplayAppRecovery.cpp index fd7017a451..22afab66e4 100644 --- a/src/displayapp/DisplayAppRecovery.cpp +++ b/src/displayapp/DisplayAppRecovery.cpp @@ -25,7 +25,6 @@ DisplayApp::DisplayApp(Drivers::St7789& lcd, Pinetime::Controllers::AlarmController& alarmController, Pinetime::Controllers::TouchHandler& touchHandler) : lcd {lcd}, bleController {bleController} { - } void DisplayApp::Start() { @@ -34,7 +33,7 @@ void DisplayApp::Start() { APP_ERROR_HANDLER(NRF_ERROR_NO_MEM); } -void DisplayApp::Process(void* instance) { +[[noreturn]] void DisplayApp::Process(void* instance) { auto* app = static_cast(instance); NRF_LOG_INFO("displayapp task started!"); @@ -120,5 +119,4 @@ void DisplayApp::PushMessage(Display::Messages msg) { } void DisplayApp::Register(Pinetime::System::SystemTask* systemTask) { - } diff --git a/src/displayapp/DisplayAppRecovery.h b/src/displayapp/DisplayAppRecovery.h index 86e956d133..2b62491af1 100644 --- a/src/displayapp/DisplayAppRecovery.h +++ b/src/displayapp/DisplayAppRecovery.h @@ -59,13 +59,15 @@ namespace Pinetime { Pinetime::Controllers::AlarmController& alarmController, Pinetime::Controllers::TouchHandler& touchHandler); void Start(); - void Start(Pinetime::System::BootErrors){ Start(); }; + void Start(Pinetime::System::BootErrors) { + Start(); + }; void PushMessage(Pinetime::Applications::Display::Messages msg); void Register(Pinetime::System::SystemTask* systemTask); private: TaskHandle_t taskHandle; - static void Process(void* instance); + [[noreturn]] static void Process(void* instance); void DisplayLogo(uint16_t color); void DisplayOtaProgress(uint8_t percent, uint16_t color); void InitHw(); diff --git a/src/main.cpp b/src/main.cpp index 53f78ce8a1..5eed8e8809 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -57,6 +57,9 @@ Pinetime::Logging::NrfLogger logger; Pinetime::Logging::DummyLogger logger; #endif +#pragma clang diagnostic push +#pragma ide diagnostic ignored "OCInconsistentNamingInspection" + static constexpr uint8_t touchPanelTwiAddress = 0x15; static constexpr uint8_t motionSensorTwiAddress = 0x18; static constexpr uint8_t heartRateSensorTwiAddress = 0x44; @@ -156,16 +159,15 @@ Pinetime::System::SystemTask systemTask(spi, touchHandler, buttonHandler); -/* Variable Declarations for variables in noinit SRAM +/* Variable Declarations for variables in noinit SRAM Increment NoInit_MagicValue upon adding variables to this area */ -extern uint32_t __start_noinit_data; -extern uint32_t __stop_noinit_data; +extern uint32_t __start_noinit_data; // NOLINT(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp) +extern uint32_t __stop_noinit_data; // NOLINT(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp) static constexpr uint32_t NoInit_MagicValue = 0xDEAD0000; uint32_t NoInit_MagicWord __attribute__((section(".noinit"))); std::chrono::time_point NoInit_BackUpTime __attribute__((section(".noinit"))); - void nrfx_gpiote_evt_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) { if (pin == Pinetime::PinMap::Cst816sIrq) { systemTask.OnTouchEvent(); @@ -208,25 +210,25 @@ void SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQHandler(void) { } } -static void (*radio_isr_addr)(void); -static void (*rng_isr_addr)(void); -static void (*rtc0_isr_addr)(void); +static void __attribute__((used)) (*radio_isr_addr)(void); +static void __attribute__((used)) (*rng_isr_addr)(void); +static void __attribute__((used)) (*rtc0_isr_addr)(void); /* Some interrupt handlers required for NimBLE radio driver */ extern "C" { -void RADIO_IRQHandler(void) { +void __attribute__((used)) RADIO_IRQHandler(void) { ((void (*)(void)) radio_isr_addr)(); } -void RNG_IRQHandler(void) { +void __attribute__((used)) RNG_IRQHandler(void) { ((void (*)(void)) rng_isr_addr)(); } -void RTC0_IRQHandler(void) { +void __attribute__((used)) RTC0_IRQHandler(void) { ((void (*)(void)) rtc0_isr_addr)(); } -void WDT_IRQHandler(void) { +void __attribute__((used)) WDT_IRQHandler(void) { nrf_wdt_event_clear(NRF_WDT_EVENT_TIMEOUT); } @@ -251,7 +253,7 @@ uint32_t npl_freertos_hw_enter_critical(void) { } void npl_freertos_hw_exit_critical(uint32_t ctx) { - if (!ctx) { + if (ctx == 0u) { __enable_irq(); } } @@ -265,13 +267,16 @@ struct ble_npl_eventq* nimble_port_get_dflt_eventq(void) { void nimble_port_run(void) { struct ble_npl_event* ev; - while (1) { +#pragma clang diagnostic push +#pragma ide diagnostic ignored "EndlessLoop" + while (true) { ev = ble_npl_eventq_get(&g_eventq_dflt, BLE_NPL_TIME_FOREVER); ble_npl_event_run(ev); } +#pragma clang diagnostic pop } -void BleHost(void*) { +void BleHost(void* /*unused*/) { nimble_port_run(); } @@ -284,7 +289,7 @@ void nimble_port_init(void) { ble_store_ram_init(); int res; - res = hal_timer_init(5, NULL); + res = hal_timer_init(5, nullptr); ASSERT(res == 0); res = os_cputime_init(32768); ASSERT(res == 0); @@ -299,7 +304,14 @@ void nimble_port_ll_task_func(void* args) { } } -int main(void) { +/** + * This is for fooling LTO to not remove a function referenced in inline asm + */ +static __attribute__((used)) void TaskSwitchDummy() { + vTaskSwitchContext(); +} + +[[noreturn]] int main() { logger.Init(); nrf_drv_clock_init(); @@ -324,12 +336,11 @@ int main(void) { // retrieve version stored by bootloader Pinetime::BootloaderVersion::SetVersion(NRF_TIMER2->CC[0]); - if (NoInit_MagicWord == NoInit_MagicValue) { dateTimeController.SetCurrentTime(NoInit_BackUpTime); } else { - //Clear Memory to known state - memset(&__start_noinit_data,0,(uintptr_t)&__stop_noinit_data-(uintptr_t)&__start_noinit_data); + // Clear Memory to known state + memset(&__start_noinit_data, 0, (uintptr_t) &__stop_noinit_data - (uintptr_t) &__start_noinit_data); NoInit_MagicWord = NoInit_MagicValue; } @@ -341,7 +352,11 @@ int main(void) { vTaskStartScheduler(); - for (;;) { + // Yes, this should never be called, never is here, but it MUST be kept. + TaskSwitchDummy(); + + while (true) { APP_ERROR_HANDLER(NRF_ERROR_FORBIDDEN); } } +#pragma clang diagnostic pop // This is for OCInconsistentNamingInspection diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index a95d479dec..c710089aa1 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -115,7 +115,7 @@ SystemTask::SystemTask(Drivers::SpiMaster& spi, void SystemTask::Start() { systemTasksMsgQueue = xQueueCreate(10, 1); - if (pdPASS != xTaskCreate(SystemTask::Process, "MAIN", 350, this, 0, &taskHandle)) { + if (pdPASS != xTaskCreate(SystemTask::Process, "MAIN", 385, this, 0, &taskHandle)) { APP_ERROR_HANDLER(NRF_ERROR_NO_MEM); } } @@ -343,18 +343,19 @@ void SystemTask::Work() { xTimerStart(dimTimer, 0); break; case Messages::StartFileTransfer: - NRF_LOG_INFO("[systemtask] FS Started"); + NRF_LOG_INFO("[systemtask] FS Started"); doNotGoToSleep = true; - if (isSleeping && !isWakingUp) + if (isSleeping && !isWakingUp) { GoToRunning(); - //TODO add intent of fs access icon or something + } + // TODO add intent of fs access icon or something break; case Messages::StopFileTransfer: NRF_LOG_INFO("[systemtask] FS Stopped"); doNotGoToSleep = false; xTimerStart(dimTimer, 0); - //TODO add intent of fs access icon or something - break; + // TODO add intent of fs access icon or something + break; case Messages::OnTouchEvent: if (touchHandler.GetNewTouchInfo()) { touchHandler.UpdateLvglTouchPoint();