Initial commit

This commit is contained in:
JF 2019-11-17 20:47:04 +01:00
commit 2ea27e0cda
26 changed files with 14461 additions and 0 deletions

19
CMakeLists.txt Normal file
View file

@ -0,0 +1,19 @@
cmake_minimum_required(VERSION 3.15)
project(pinetime C CXX ASM)
set(NRF_TARGET "nrf52")
if (NOT ARM_NONE_EABI_TOOLCHAIN_PATH)
message(FATAL_ERROR "The path to the toolchain (arm-non-eabi) must be specified on the command line (add -DARM_NONE_EABI_TOOLCHAIN_PATH=<path>")
endif ()
if (NOT NRF5_SDK_PATH)
message(FATAL_ERROR "The path to the NRF52 SDK must be specified on the command line (add -DNRF52_SDK_PATH=<path>")
endif ()
if (NOT NRFJPROG)
message(FATAL_ERROR "the path to the tool nrfjprog must be specified on the command line (add -DNRFJPROG=<path>")
endif ()
include("cmake-nRF5x/CMake_nRF5x.cmake")
add_subdirectory(src)

50
README.md Normal file
View file

@ -0,0 +1,50 @@
# nrf52-baseproject
This is a CMake project that configure everything needed to build applications for the NRF52 MCU. It configures the toolchain (arm-none-eabi) and the NRF52 SDK.
The CMake files are taken from https://github.com/Polidea/cmake-nRF5x
I tested this project (compile only) with the following versions:
* gcc-arm-none-eabi-8-2019-q3-update (from https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads)
* nRF5_SDK_15.3.0_59ac345 (from https://www.nordicsemi.com/Software-and-Tools/Software/nRF5-SDK)
I've tested this project on the NRF52-DK board.
## How to use it
* Download and unzip arm-none-eabi and NRF52 SDK
* Clone this repo
* Call CMake with the following command line argument
- -DARM_NONE_EABI_TOOLCHAIN_PATH=[Path to the toolchain]
- -DNRF5_SDK_PATH=[Path to the SDK]
- -DNRFJPROG=[Path to NRFJProg]
```
$ mkdir build
$ cd build
$ cmake -DCMAKE_BUILD_TYPE=Debug -DARM_NONE_EABI_TOOLCHAIN_PATH=... -DNRF5_SDK_PATH=... -DNRFJPROG=... ../
```
* Make
```
$ make -j
```
## RTT
RTT is a feature from Segger's JLink devices that allows bidirectionnal communication between the debugger and the target.
This feature can be used to get the logs from the embedded software on the development computer.
* Program the MCU with the code (see above)
* Start JLinkExe
```
$ JLinkExe -device nrf52 -if swd -speed 4000 -autoconnect 1
```
* Start JLinkRTTClient
```
$ JLinkRTTClient
```

2
cmake-nRF5x/.gitignore vendored Executable file
View file

@ -0,0 +1,2 @@
.idea
cmake-build-debug

580
cmake-nRF5x/CMake_nRF5x.cmake Executable file
View file

@ -0,0 +1,580 @@
cmake_minimum_required(VERSION 3.6)
# check if all the necessary tools paths have been provided.
if (NOT NRF5_SDK_PATH)
message(FATAL_ERROR "The path to the nRF5 SDK (NRF5_SDK_PATH) must be set.")
endif ()
if (NOT NRFJPROG)
message(FATAL_ERROR "The path to the nrfjprog utility (NRFJPROG) must be set.")
endif ()
# convert toolchain path to bin path
if(DEFINED ARM_NONE_EABI_TOOLCHAIN_PATH)
set(ARM_NONE_EABI_TOOLCHAIN_BIN_PATH ${ARM_NONE_EABI_TOOLCHAIN_PATH}/bin)
endif()
# check if the nRF target has been set
if (NRF_TARGET MATCHES "nrf51")
elseif (NRF_TARGET MATCHES "nrf52")
elseif (NOT NRF_TARGET)
message(FATAL_ERROR "nRF target must be defined")
else ()
message(FATAL_ERROR "Only nRF51 and rRF52 boards are supported right now")
endif ()
# must be set in file (not macro) scope (in macro would point to parent CMake directory)
set(DIR_OF_nRF5x_CMAKE ${CMAKE_CURRENT_LIST_DIR})
macro(nRF5x_toolchainSetup)
include(${DIR_OF_nRF5x_CMAKE}/arm-gcc-toolchain.cmake)
endmacro()
macro(nRF5x_setup)
if(NOT DEFINED ARM_GCC_TOOLCHAIN)
message(FATAL_ERROR "The toolchain must be set up before calling this macro")
endif()
# fix on macOS: prevent cmake from adding implicit parameters to Xcode
set(CMAKE_OSX_SYSROOT "/")
set(CMAKE_OSX_DEPLOYMENT_TARGET "")
# language standard/version settings
set(CMAKE_C_STANDARD 99)
set(CMAKE_CXX_STANDARD 11)
# CPU specyfic settings
if (NRF_TARGET MATCHES "nrf51")
# nRF51 (nRF51-DK => PCA10028)
if(NOT DEFINED NRF5_LINKER_SCRIPT)
set(NRF5_LINKER_SCRIPT "${CMAKE_SOURCE_DIR}/gcc_nrf51.ld")
endif()
set(CPU_FLAGS "-mcpu=cortex-m0 -mfloat-abi=soft")
add_definitions(-DBOARD_PCA10028 -DNRF51 -DNRF51422)
add_definitions(-DSOFTDEVICE_PRESENT -DS130 -DNRF_SD_BLE_API_VERSION=2 -DSWI_DISABLE0 -DBLE_STACK_SUPPORT_REQD)
include_directories(
"${NRF5_SDK_PATH}/components/softdevice/s130/headers"
"${NRF5_SDK_PATH}/components/softdevice/s130/headers/nrf51"
)
list(APPEND SDK_SOURCE_FILES
"${NRF5_SDK_PATH}/modules/nrfx/mdk/system_nrf51.c"
"${NRF5_SDK_PATH}/modules/nrfx/mdk/gcc_startup_nrf51.S"
)
set(SOFTDEVICE_PATH "${NRF5_SDK_PATH}/components/softdevice/s130/hex/s130_nrf51_2.0.0_softdevice.hex")
elseif (NRF_TARGET MATCHES "nrf52")
# nRF52 (nRF52-DK => PCA10040)
if(NOT DEFINED NRF5_LINKER_SCRIPT)
set(NRF5_LINKER_SCRIPT "${CMAKE_SOURCE_DIR}/gcc_nrf52.ld")
endif()
set(CPU_FLAGS "-mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16")
add_definitions(-DNRF52 -DNRF52832 -DNRF52832_XXAA -DNRF52_PAN_74 -DNRF52_PAN_64 -DNRF52_PAN_12 -DNRF52_PAN_58 -DNRF52_PAN_54 -DNRF52_PAN_31 -DNRF52_PAN_51 -DNRF52_PAN_36 -DNRF52_PAN_15 -DNRF52_PAN_20 -DNRF52_PAN_55 -DBOARD_PCA10040)
add_definitions(-DSOFTDEVICE_PRESENT -DS132 -DSWI_DISABLE0 -DBLE_STACK_SUPPORT_REQD -DNRF_SD_BLE_API_VERSION=6)
add_definitions(-DFREERTOS)
add_definitions(-DDEBUG_NRF_USER)
add_definitions(-D__STARTUP_CLEAR_BSS)
add_definitions(-D__HEAP_SIZE=8192)
add_definitions(-D__STACK_SIZE=2048)
include_directories(
"${NRF5_SDK_PATH}/components/softdevice/s132/headers"
"${NRF5_SDK_PATH}/components/softdevice/s132/headers/nrf52"
)
list(APPEND SDK_SOURCE_FILES
"${NRF5_SDK_PATH}/modules/nrfx/mdk/system_nrf52.c"
"${NRF5_SDK_PATH}/modules/nrfx/mdk/gcc_startup_nrf52.S"
)
set(SOFTDEVICE_PATH "${NRF5_SDK_PATH}/components/softdevice/s132/hex/s132_nrf52_6.1.1_softdevice.hex")
endif ()
set(COMMON_FLAGS "-MP -MD -mthumb -mabi=aapcs -Wall -g3 -ffunction-sections -fdata-sections -fno-strict-aliasing -fno-builtin --short-enums ${CPU_FLAGS}")
# compiler/assambler/linker flags
set(CMAKE_C_FLAGS "${COMMON_FLAGS}")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 -g3")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3")
set(CMAKE_CXX_FLAGS "${COMMON_FLAGS}")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g3")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
set(CMAKE_ASM_FLAGS "-MP -MD -std=c99 -x assembler-with-cpp")
set(CMAKE_EXE_LINKER_FLAGS "-mthumb -mabi=aapcs -std=gnu++98 -std=c99 -L ${NRF5_SDK_PATH}/modules/nrfx/mdk -T${NRF5_LINKER_SCRIPT} ${CPU_FLAGS} -Wl,--gc-sections --specs=nano.specs -lc -lnosys -lm")
# note: we must override the default cmake linker flags so that CMAKE_C_FLAGS are not added implicitly
set(CMAKE_C_LINK_EXECUTABLE "${CMAKE_C_COMPILER} <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_C_COMPILER} <LINK_FLAGS> <OBJECTS> -lstdc++ -o <TARGET> <LINK_LIBRARIES>")
# basic board definitions and drivers
include_directories(
"${NRF5_SDK_PATH}/components"
"${NRF5_SDK_PATH}/components/boards"
"${NRF5_SDK_PATH}/components/softdevice/common"
"${NRF5_SDK_PATH}/integration/nrfx"
"${NRF5_SDK_PATH}/integration/nrfx/legacy"
"${NRF5_SDK_PATH}/modules/nrfx"
"${NRF5_SDK_PATH}/modules/nrfx/drivers/include"
"${NRF5_SDK_PATH}/modules/nrfx/hal"
"${NRF5_SDK_PATH}/modules/nrfx/mdk"
)
list(APPEND SDK_SOURCE_FILES
"${NRF5_SDK_PATH}/components/boards/boards.c"
"${NRF5_SDK_PATH}/integration/nrfx/legacy/nrf_drv_clock.c"
"${NRF5_SDK_PATH}/modules/nrfx/drivers/src/nrfx_clock.c"
"${NRF5_SDK_PATH}/modules/nrfx/drivers/src/nrfx_gpiote.c"
"${NRF5_SDK_PATH}/modules/nrfx/soc/nrfx_atomic.c"
)
# freertos SRC
list(APPEND SDK_SOURCE_FILES
${NRF5_SDK_PATH}/external/freertos/source/croutine.c
${NRF5_SDK_PATH}/external/freertos/source/event_groups.c
${NRF5_SDK_PATH}/external/freertos/source/portable/MemMang/heap_1.c
${NRF5_SDK_PATH}/external/freertos/source/list.c
${NRF5_SDK_PATH}/external/freertos/portable/GCC/nrf52/port.c
${NRF5_SDK_PATH}/external/freertos/portable/CMSIS/nrf52/port_cmsis.c
${NRF5_SDK_PATH}/external/freertos/portable/CMSIS/nrf52/port_cmsis_systick.c
${NRF5_SDK_PATH}/external/freertos/source/queue.c
${NRF5_SDK_PATH}/external/freertos/source/stream_buffer.c
${NRF5_SDK_PATH}/external/freertos/source/tasks.c
${NRF5_SDK_PATH}/external/freertos/source/timers.c
${NRF5_SDK_PATH}/components/libraries/timer/app_timer_freertos.c
)
# freertos include
include_directories(
${NRF5_SDK_PATH}/external/freertos/source/include
${NRF5_SDK_PATH}/external/freertos/portable/CMSIS/nrf52
${NRF5_SDK_PATH}/external/freertos/portable/GCC/nrf52
)
# toolchain specific
include_directories(
"${NRF5_SDK_PATH}/components/toolchain/cmsis/include"
)
# libraries include
include_directories(
"${NRF5_SDK_PATH}/components/libraries/atomic"
"${NRF5_SDK_PATH}/components/libraries/atomic_fifo"
"${NRF5_SDK_PATH}/components/libraries/atomic_flags"
"${NRF5_SDK_PATH}/components/libraries/balloc"
"${NRF5_SDK_PATH}/components/libraries/bootloader/ble_dfu"
"${NRF5_SDK_PATH}/components/libraries/cli"
"${NRF5_SDK_PATH}/components/libraries/crc16"
"${NRF5_SDK_PATH}/components/libraries/crc32"
"${NRF5_SDK_PATH}/components/libraries/crypto"
"${NRF5_SDK_PATH}/components/libraries/csense"
"${NRF5_SDK_PATH}/components/libraries/csense_drv"
"${NRF5_SDK_PATH}/components/libraries/delay"
"${NRF5_SDK_PATH}/components/libraries/ecc"
"${NRF5_SDK_PATH}/components/libraries/experimental_section_vars"
"${NRF5_SDK_PATH}/components/libraries/experimental_task_manager"
"${NRF5_SDK_PATH}/components/libraries/fds"
"${NRF5_SDK_PATH}/components/libraries/fstorage"
"${NRF5_SDK_PATH}/components/libraries/gfx"
"${NRF5_SDK_PATH}/components/libraries/gpiote"
"${NRF5_SDK_PATH}/components/libraries/hardfault"
"${NRF5_SDK_PATH}/components/libraries/hci"
"${NRF5_SDK_PATH}/components/libraries/led_softblink"
"${NRF5_SDK_PATH}/components/libraries/log"
"${NRF5_SDK_PATH}/components/libraries/log/src"
"${NRF5_SDK_PATH}/components/libraries/low_power_pwm"
"${NRF5_SDK_PATH}/components/libraries/mem_manager"
"${NRF5_SDK_PATH}/components/libraries/memobj"
"${NRF5_SDK_PATH}/components/libraries/mpu"
"${NRF5_SDK_PATH}/components/libraries/mutex"
"${NRF5_SDK_PATH}/components/libraries/pwm"
"${NRF5_SDK_PATH}/components/libraries/pwr_mgmt"
"${NRF5_SDK_PATH}/components/libraries/queue"
"${NRF5_SDK_PATH}/components/libraries/ringbuf"
"${NRF5_SDK_PATH}/components/libraries/scheduler"
"${NRF5_SDK_PATH}/components/libraries/sdcard"
"${NRF5_SDK_PATH}/components/libraries/slip"
"${NRF5_SDK_PATH}/components/libraries/sortlist"
"${NRF5_SDK_PATH}/components/libraries/spi_mngr"
"${NRF5_SDK_PATH}/components/libraries/stack_guard"
"${NRF5_SDK_PATH}/components/libraries/strerror"
"${NRF5_SDK_PATH}/components/libraries/svc"
"${NRF5_SDK_PATH}/components/libraries/timer"
"${NRF5_SDK_PATH}/components/libraries/twi_mngr"
"${NRF5_SDK_PATH}/components/libraries/twi_sensor"
"${NRF5_SDK_PATH}/components/libraries/usbd"
"${NRF5_SDK_PATH}/components/libraries/usbd/class/audio"
"${NRF5_SDK_PATH}/components/libraries/usbd/class/cdc"
"${NRF5_SDK_PATH}/components/libraries/usbd/class/cdc/acm"
"${NRF5_SDK_PATH}/components/libraries/usbd/class/hid"
"${NRF5_SDK_PATH}/components/libraries/usbd/class/hid/generic"
"${NRF5_SDK_PATH}/components/libraries/usbd/class/hid/kbd"
"${NRF5_SDK_PATH}/components/libraries/usbd/class/hid/mouse"
"${NRF5_SDK_PATH}/components/libraries/usbd/class/msc"
"${NRF5_SDK_PATH}/components/libraries/util"
)
# librarires sources
list(APPEND SDK_SOURCE_FILES
"${NRF5_SDK_PATH}/components/libraries/atomic/nrf_atomic.c"
"${NRF5_SDK_PATH}/components/libraries/balloc/nrf_balloc.c"
"${NRF5_SDK_PATH}/components/libraries/util/nrf_assert.c"
"${NRF5_SDK_PATH}/components/libraries/util/app_error.c"
"${NRF5_SDK_PATH}/components/libraries/util/app_error_weak.c"
"${NRF5_SDK_PATH}/components/libraries/util/app_error_handler_gcc.c"
"${NRF5_SDK_PATH}/components/libraries/util/app_util_platform.c"
"${NRF5_SDK_PATH}/components/libraries/log/src/nrf_log_backend_rtt.c"
"${NRF5_SDK_PATH}/components/libraries/log/src/nrf_log_backend_serial.c"
# "${NRF5_SDK_PATH}/components/libraries/log/src/nrf_log_backend_uart.c"
"${NRF5_SDK_PATH}/components/libraries/log/src/nrf_log_default_backends.c"
"${NRF5_SDK_PATH}/components/libraries/log/src/nrf_log_frontend.c"
"${NRF5_SDK_PATH}/components/libraries/log/src/nrf_log_str_formatter.c"
"${NRF5_SDK_PATH}/components/libraries/memobj/nrf_memobj.c"
"${NRF5_SDK_PATH}/components/libraries/ringbuf/nrf_ringbuf.c"
"${NRF5_SDK_PATH}/components/libraries/strerror/nrf_strerror.c"
)
# Segger RTT
include_directories(
"${NRF5_SDK_PATH}/external/segger_rtt/"
)
#segger rtt
list(APPEND SDK_SOURCE_FILES
"${NRF5_SDK_PATH}/external/segger_rtt/SEGGER_RTT_Syscalls_GCC.c"
"${NRF5_SDK_PATH}/external/segger_rtt/SEGGER_RTT.c"
"${NRF5_SDK_PATH}/external/segger_rtt/SEGGER_RTT_printf.c"
)
# Other external
include_directories(
"${NRF5_SDK_PATH}/external/fprintf/"
# "${NRF5_SDK_PATH}/external/utf_converter/"
)
list(APPEND SDK_SOURCE_FILES
"${NRF5_SDK_PATH}/external/utf_converter/utf.c"
"${NRF5_SDK_PATH}/external/fprintf/nrf_fprintf.c"
"${NRF5_SDK_PATH}/external/fprintf/nrf_fprintf_format.c"
)
#BLE S132
include_directories(
"${NRF5_SDK_PATH}/components/ble/common"
"${NRF5_SDK_PATH}/components/ble/ble_advertising"
"${NRF5_SDK_PATH}/components/ble/ble_services/ble_bas"
"${NRF5_SDK_PATH}/components/ble/ble_services/ble_hrs"
"${NRF5_SDK_PATH}/components/ble/ble_services/ble_dis"
"${NRF5_SDK_PATH}/components/ble/nrf_ble_gatt"
"${NRF5_SDK_PATH}/components/libraries/sensorsim"
"${NRF5_SDK_PATH}/components/ble/peer_manager"
"${NRF5_SDK_PATH}/components/ble/nrf_ble_qwr"
)
LIST(APPEND SDK_SOURCE_FILES
"${NRF5_SDK_PATH}//components/ble/common/ble_srv_common.c"
"${NRF5_SDK_PATH}/components/ble/ble_advertising/ble_advertising.c"
"${NRF5_SDK_PATH}/components/ble/common/ble_advdata.c"
"${NRF5_SDK_PATH}/components/ble/ble_services/ble_bas/ble_bas.c"
"${NRF5_SDK_PATH}/components/ble/ble_services/ble_hrs/ble_hrs.c"
"${NRF5_SDK_PATH}/components/ble/ble_services/ble_dis/ble_dis.c"
"${NRF5_SDK_PATH}/components/ble/nrf_ble_gatt/nrf_ble_gatt.c"
"${NRF5_SDK_PATH}/components/libraries/sensorsim/sensorsim.c"
"${NRF5_SDK_PATH}/components/ble/peer_manager/peer_manager.c"
"${NRF5_SDK_PATH}/components/ble/nrf_ble_qwr/nrf_ble_qwr.c"
"${NRF5_SDK_PATH}/components/ble/common/ble_conn_state.c"
"${NRF5_SDK_PATH}/components/ble/peer_manager/auth_status_tracker.c"
"${NRF5_SDK_PATH}/components/ble/peer_manager/gatt_cache_manager.c"
"${NRF5_SDK_PATH}/components/ble/peer_manager/gatts_cache_manager.c"
"${NRF5_SDK_PATH}/components/ble/peer_manager/id_manager.c"
"${NRF5_SDK_PATH}/components/ble/peer_manager/peer_data_storage.c"
"${NRF5_SDK_PATH}/components/ble/peer_manager/peer_database.c"
"${NRF5_SDK_PATH}/components/ble/peer_manager/peer_id.c"
"${NRF5_SDK_PATH}/components/ble/peer_manager/peer_manager.c"
"${NRF5_SDK_PATH}/components/ble/peer_manager/peer_manager_handler.c"
"${NRF5_SDK_PATH}/components/ble/peer_manager/pm_buffer.c"
"${NRF5_SDK_PATH}/components/ble/peer_manager/security_dispatcher.c"
"${NRF5_SDK_PATH}/components/ble/peer_manager/security_manager.c"
"${NRF5_SDK_PATH}/components/ble/common/ble_conn_state.c"
"${NRF5_SDK_PATH}/components/ble/common/ble_conn_params.c"
"${NRF5_SDK_PATH}/components/ble/common/ble_conn_state.c"
"${NRF5_SDK_PATH}/components/libraries/atomic_flags/nrf_atflags.c"
"${NRF5_SDK_PATH}/components/libraries/fds/fds.c"
"${NRF5_SDK_PATH}/components/libraries/fstorage/nrf_fstorage.c"
"${NRF5_SDK_PATH}/components/libraries/fstorage/nrf_fstorage_sd.c"
"${NRF5_SDK_PATH}/components/libraries/atomic_fifo/nrf_atfifo.c"
"${NRF5_SDK_PATH}/components/softdevice/common/nrf_sdh.c"
"${NRF5_SDK_PATH}/components/softdevice/common/nrf_sdh_ble.c"
"${NRF5_SDK_PATH}/components/softdevice/common/nrf_sdh_freertos.c"
"${NRF5_SDK_PATH}/components/softdevice/common/nrf_sdh_soc.c"
"${NRF5_SDK_PATH}/components/libraries/experimental_section_vars/nrf_section_iter.c"
"${NRF5_SDK_PATH}/components/libraries/bsp/bsp_btn_ble.c"
"${NRF5_SDK_PATH}/components/libraries/hardfault/hardfault_implementation.c"
"${NRF5_SDK_PATH}/components/libraries/hardfault/nrf52/handler/hardfault_handler_gcc.c"
)
# adds target for erasing and flashing the board with a softdevice
add_custom_target(FLASH_SOFTDEVICE ALL
COMMAND ${NRFJPROG} --program ${SOFTDEVICE_PATH} -f ${NRF_TARGET} --sectorerase
COMMAND sleep 0.5s
COMMAND ${NRFJPROG} --reset -f ${NRF_TARGET}
COMMENT "flashing SoftDevice"
)
add_custom_target(FLASH_ERASE ALL
COMMAND ${NRFJPROG} --eraseall -f ${NRF_TARGET}
COMMENT "erasing flashing"
)
if(${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Darwin")
set(TERMINAL "open")
elseif(${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Windows")
set(TERMINAL "sh")
else()
set(TERMINAL "gnome-terminal")
endif()
add_custom_target(START_JLINK ALL
COMMAND ${TERMINAL} "${DIR_OF_nRF5x_CMAKE}/runJLinkGDBServer-${NRF_TARGET}"
COMMAND ${TERMINAL} "${DIR_OF_nRF5x_CMAKE}/runJLinkExe-${NRF_TARGET}"
COMMAND sleep 2s
COMMAND ${TERMINAL} "${DIR_OF_nRF5x_CMAKE}/runJLinkRTTClient"
COMMENT "started JLink commands"
)
endmacro(nRF5x_setup)
# adds a target for comiling and flashing an executable
macro(nRF5x_addExecutable EXECUTABLE_NAME SOURCE_FILES)
# executable
add_executable(${EXECUTABLE_NAME} ${SDK_SOURCE_FILES} ${SOURCE_FILES})
set_target_properties(${EXECUTABLE_NAME} PROPERTIES SUFFIX ".out")
set_target_properties(${EXECUTABLE_NAME} PROPERTIES LINK_FLAGS "-Wl,-Map=${EXECUTABLE_NAME}.map")
# additional POST BUILD setps to create the .bin and .hex files
add_custom_command(TARGET ${EXECUTABLE_NAME}
POST_BUILD
COMMAND ${CMAKE_SIZE_UTIL} ${EXECUTABLE_NAME}.out
COMMAND ${CMAKE_OBJCOPY} -O binary ${EXECUTABLE_NAME}.out "${EXECUTABLE_NAME}.bin"
COMMAND ${CMAKE_OBJCOPY} -O ihex ${EXECUTABLE_NAME}.out "${EXECUTABLE_NAME}.hex"
COMMENT "post build steps for ${EXECUTABLE_NAME}")
# custom target for flashing the board
add_custom_target("FLASH_${EXECUTABLE_NAME}" ALL
DEPENDS ${EXECUTABLE_NAME}
COMMAND ${NRFJPROG} --program ${EXECUTABLE_NAME}.hex -f ${NRF_TARGET} --sectorerase
COMMAND sleep 0.5s
COMMAND ${NRFJPROG} --reset -f ${NRF_TARGET}
COMMENT "flashing ${EXECUTABLE_NAME}.hex"
)
endmacro()
# adds app-level scheduler library
macro(nRF5x_addAppScheduler)
include_directories(
"${NRF5_SDK_PATH}/components/libraries/scheduler"
)
list(APPEND SDK_SOURCE_FILES
"${NRF5_SDK_PATH}/components/libraries/scheduler/app_scheduler.c"
)
endmacro(nRF5x_addAppScheduler)
# adds app-level FIFO libraries
macro(nRF5x_addAppFIFO)
include_directories(
"${NRF5_SDK_PATH}/components/libraries/fifo"
)
list(APPEND SDK_SOURCE_FILES
"${NRF5_SDK_PATH}/components/libraries/fifo/app_fifo.c"
)
endmacro(nRF5x_addAppFIFO)
# adds app-level Timer libraries
macro(nRF5x_addAppTimer)
list(APPEND SDK_SOURCE_FILES
"${NRF5_SDK_PATH}/components/libraries/timer/app_timer.c"
)
endmacro(nRF5x_addAppTimer)
# adds app-level UART libraries
macro(nRF5x_addAppUART)
include_directories(
"${NRF5_SDK_PATH}/components/libraries/uart"
)
list(APPEND SDK_SOURCE_FILES
"${NRF5_SDK_PATH}/components/libraries/uart/app_uart_fifo.c"
)
endmacro(nRF5x_addAppUART)
# adds app-level Button library
macro(nRF5x_addAppButton)
include_directories(
"${NRF5_SDK_PATH}/components/libraries/button"
)
list(APPEND SDK_SOURCE_FILES
"${NRF5_SDK_PATH}/components/libraries/button/app_button.c"
)
endmacro(nRF5x_addAppButton)
# adds app-level GPIOTE library
macro(nRF5x_addAppGpiote)
include_directories(
"${NRF5_SDK_PATH}/components/libraries/gpiote"
)
list(APPEND SDK_SOURCE_FILES
"${NRF5_SDK_PATH}/components/libraries/gpiote/app_gpiote.c"
)
endmacro(nRF5x_addAppGpiote)
# adds BSP (board support package) library
macro(nRF5x_addBSP WITH_BLE_BTN WITH_ANT_BTN WITH_NFC)
include_directories(
"${NRF5_SDK_PATH}/components/libraries/bsp"
)
list(APPEND SDK_SOURCE_FILES
"${NRF5_SDK_PATH}/components/libraries/bsp/bsp.c"
)
if (${WITH_BLE_BTN})
list(APPEND SDK_SOURCE_FILES
"${NRF5_SDK_PATH}/components/libraries/bsp/bsp_btn_ble.c"
)
endif ()
if (${WITH_ANT_BTN})
list(APPEND SDK_SOURCE_FILES
"${NRF5_SDK_PATH}/components/libraries/bsp/bsp_btn_ant.c"
)
endif ()
if (${WITH_NFC})
list(APPEND SDK_SOURCE_FILES
"${NRF5_SDK_PATH}/components/libraries/bsp/bsp_nfc.c"
)
endif ()
endmacro(nRF5x_addBSP)
# adds Bluetooth Low Energy GATT support library
macro(nRF5x_addBLEGATT)
include_directories(
"${NRF5_SDK_PATH}/components/ble/nrf_ble_gatt"
)
list(APPEND SDK_SOURCE_FILES
"${NRF5_SDK_PATH}/components/ble/nrf_ble_gatt/nrf_ble_gatt.c"
)
endmacro(nRF5x_addBLEGATT)
# adds Bluetooth Low Energy advertising support library
macro(nRF5x_addBLEAdvertising)
include_directories(
"${NRF5_SDK_PATH}/components/ble/ble_advertising"
)
list(APPEND SDK_SOURCE_FILES
"${NRF5_SDK_PATH}/components/ble/ble_advertising/ble_advertising.c"
)
endmacro(nRF5x_addBLEAdvertising)
# adds Bluetooth Low Energy advertising support library
macro(nRF5x_addBLEPeerManager)
include_directories(
"${NRF5_SDK_PATH}/components/ble/peer_manager"
)
list(APPEND SDK_SOURCE_FILES
"${NRF5_SDK_PATH}/components/ble/peer_manager/auth_status_tracker.c"
"${NRF5_SDK_PATH}/components/ble/peer_manager/gatt_cache_manager.c"
"${NRF5_SDK_PATH}/components/ble/peer_manager/gatts_cache_manager.c"
"${NRF5_SDK_PATH}/components/ble/peer_manager/id_manager.c"
"${NRF5_SDK_PATH}/components/ble/peer_manager/nrf_ble_lesc.c"
"${NRF5_SDK_PATH}/components/ble/peer_manager/peer_data_storage.c"
"${NRF5_SDK_PATH}/components/ble/peer_manager/peer_database.c"
"${NRF5_SDK_PATH}/components/ble/peer_manager/peer_id.c"
"${NRF5_SDK_PATH}/components/ble/peer_manager/peer_manager.c"
"${NRF5_SDK_PATH}/components/ble/peer_manager/peer_manager_handler.c"
"${NRF5_SDK_PATH}/components/ble/peer_manager/pm_buffer.c"
"${NRF5_SDK_PATH}/components/ble/peer_manager/security_dispatcher.c"
"${NRF5_SDK_PATH}/components/ble/peer_manager/security_manager.c"
)
endmacro(nRF5x_addBLEPeerManager)
# adds app-level FDS (flash data storage) library
macro(nRF5x_addAppFDS)
include_directories(
"${NRF5_SDK_PATH}/components/libraries/fds"
"${NRF5_SDK_PATH}/components/libraries/fstorage"
"${NRF5_SDK_PATH}/components/libraries/experimental_section_vars"
)
list(APPEND SDK_SOURCE_FILES
"${NRF5_SDK_PATH}/components/libraries/fds/fds.c"
"${NRF5_SDK_PATH}/components/libraries/fstorage/nrf_fstorage.c"
"${NRF5_SDK_PATH}/components/libraries/fstorage/nrf_fstorage_sd.c"
"${NRF5_SDK_PATH}/components/libraries/fstorage/nrf_fstorage_nvmc.c"
)
endmacro(nRF5x_addAppFDS)
# adds NFC library
# macro(nRF5x_addNFC)
# # NFC includes
# include_directories(
# "${NRF5_SDK_PATH}/components/nfc/ndef/conn_hand_parser"
# "${NRF5_SDK_PATH}/components/nfc/ndef/conn_hand_parser/ac_rec_parser"
# "${NRF5_SDK_PATH}/components/nfc/ndef/conn_hand_parser/ble_oob_advdata_parser"
# "${NRF5_SDK_PATH}/components/nfc/ndef/conn_hand_parser/le_oob_rec_parser"
# "${NRF5_SDK_PATH}/components/nfc/ndef/connection_handover/ac_rec"
# "${NRF5_SDK_PATH}/components/nfc/ndef/connection_handover/ble_oob_advdata"
# "${NRF5_SDK_PATH}/components/nfc/ndef/connection_handover/ble_pair_lib"
# "${NRF5_SDK_PATH}/components/nfc/ndef/connection_handover/ble_pair_msg"
# "${NRF5_SDK_PATH}/components/nfc/ndef/connection_handover/common"
# "${NRF5_SDK_PATH}/components/nfc/ndef/connection_handover/ep_oob_rec"
# "${NRF5_SDK_PATH}/components/nfc/ndef/connection_handover/hs_rec"
# "${NRF5_SDK_PATH}/components/nfc/ndef/connection_handover/le_oob_rec"
# "${NRF5_SDK_PATH}/components/nfc/ndef/generic/message"
# "${NRF5_SDK_PATH}/components/nfc/ndef/generic/record"
# "${NRF5_SDK_PATH}/components/nfc/ndef/launchapp"
# "${NRF5_SDK_PATH}/components/nfc/ndef/parser/message"
# "${NRF5_SDK_PATH}/components/nfc/ndef/parser/record"
# "${NRF5_SDK_PATH}/components/nfc/ndef/text"
# "${NRF5_SDK_PATH}/components/nfc/ndef/uri"
# "${NRF5_SDK_PATH}/components/nfc/t2t_lib"
# "${NRF5_SDK_PATH}/components/nfc/t2t_parser"
# "${NRF5_SDK_PATH}/components/nfc/t4t_lib"
# "${NRF5_SDK_PATH}/components/nfc/t4t_parser/apdu"
# "${NRF5_SDK_PATH}/components/nfc/t4t_parser/cc_file"
# "${NRF5_SDK_PATH}/components/nfc/t4t_parser/hl_detection_procedure"
# "${NRF5_SDK_PATH}/components/nfc/t4t_parser/tlv"
# )
#
# list(APPEND SDK_SOURCE_FILES
# "${NRF5_SDK_PATH}/components/nfc"
# )
#
# endmacro(nRF5x_addNFC)
macro(nRF5x_addBLEService NAME)
include_directories(
"${NRF5_SDK_PATH}/components/ble/ble_services/${NAME}"
)
list(APPEND SDK_SOURCE_FILES
"${NRF5_SDK_PATH}/components/ble/ble_services/${NAME}/${NAME}.c"
)
endmacro(nRF5x_addBLEService)

21
cmake-nRF5x/LICENSE Normal file
View file

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2017 Polidea
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View file

@ -0,0 +1,52 @@
# check if already run. Changing the compiler var can cause reconfigure so don't want to do it again
if(DEFINED ARM_GCC_TOOLCHAIN)
return()
endif()
set(ARM_GCC_TOOLCHAIN TRUE)
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR ARM)
set(TOOLCHAIN_PREFIX arm-none-eabi-)
if (NOT DEFINED ARM_NONE_EABI_TOOLCHAIN_BIN_PATH)
if(MINGW OR CYGWIN OR WIN32)
set(UTIL_SEARCH_CMD where)
elseif(UNIX OR APPLE)
set(UTIL_SEARCH_CMD which)
endif()
execute_process(
COMMAND ${UTIL_SEARCH_CMD} ${TOOLCHAIN_PREFIX}gcc
OUTPUT_VARIABLE BINUTILS_PATH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
get_filename_component(ARM_NONE_EABI_TOOLCHAIN_BIN_PATH ${BINUTILS_PATH} DIRECTORY)
endif ()
# Without that flag CMake is not able to pass test compilation check
if (${CMAKE_VERSION} VERSION_EQUAL "3.6.0" OR ${CMAKE_VERSION} VERSION_GREATER "3.6")
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
else()
set(CMAKE_EXE_LINKER_FLAGS_INIT "--specs=nosys.specs")
endif()
set(TOOLCHAIN_PATH_AND_PREFIX ${ARM_NONE_EABI_TOOLCHAIN_BIN_PATH}/${TOOLCHAIN_PREFIX})
set(CMAKE_C_COMPILER ${TOOLCHAIN_PATH_AND_PREFIX}gcc)
set(CMAKE_ASM_COMPILER ${CMAKE_C_COMPILER})
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PATH_AND_PREFIX}c++)
set(CMAKE_AR ${TOOLCHAIN_PATH_AND_PREFIX}ar)
set(CMAKE_RANLIB ${TOOLCHAIN_PATH_AND_PREFIX}ranlib)
set(CMAKE_OBJCOPY ${TOOLCHAIN_PATH_AND_PREFIX}objcopy CACHE INTERNAL "objcopy tool")
set(CMAKE_SIZE_UTIL ${TOOLCHAIN_PATH_AND_PREFIX}size CACHE INTERNAL "size tool")
set(CMAKE_SYSROOT ${ARM_NONE_EABI_TOOLCHAIN_BIN_PATH})
set(CMAKE_FIND_ROOT_PATH ${ARM_NONE_EABI_TOOLCHAIN_BIN_PATH})
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

View file

@ -0,0 +1,18 @@
cmake_minimum_required(VERSION 3.12)
set(NRF_TARGET nrf52)
if (NOT DEFINED ARM_NONE_EABI_TOOLCHAIN_PATH)
set(ARM_NONE_EABI_TOOLCHAIN_PATH "/usr/local/bin")
endif ()
set(NRF5_SDK_PATH "${CMAKE_CURRENT_LIST_DIR}/../../toolchains/nRF5/nRF5_SDK")
set(NRFJPROG "${CMAKE_CURRENT_LIST_DIR}/../../toolchains/nRF5/nrfjprog/nrfjprog")
include("${CMAKE_CURRENT_LIST_DIR}/../CMake_nRF5x.cmake")
nRF5x_toolchainSetup()
project(ExampleProject C)
add_subdirectory(src)

View file

@ -0,0 +1,3 @@
# Example
This is an example to build the blinky project. It assumes nRF5 SDK is in `../../toolchains/nRF5/nRF5_SDK`. If not, modify `CMakeLists.txt`

View file

@ -0,0 +1,39 @@
cmake_minimum_required(VERSION 3.12)
project(BlinkyExample C ASM)
# define some variables just for this example to determine file locations
set(NRF_PROJECT_NAME ble_app_blinky)
set(NRF_BOARD pca10040)
set(NRF_SOFTDEVICE s132)
# define some convenience variables to point to example project directories
set(NRF_PROJECT_PATH ${NRF5_SDK_PATH}/examples/ble_peripheral/${NRF_PROJECT_NAME})
set(NRF_PROJECT_DEVICE_PATH ${NRF_PROJECT_PATH}/${NRF_BOARD}/${NRF_SOFTDEVICE})
# you can specify the location of the linker script if desired instead of using a specific file name
set(NRF5_LINKER_SCRIPT ${NRF_PROJECT_DEVICE_PATH}/armgcc/${NRF_PROJECT_NAME}_gcc_${NRF_TARGET}.ld)
nRF5x_setup()
nRF5x_addAppScheduler()
nRF5x_addAppFIFO()
nRF5x_addAppTimer()
nRF5x_addAppUART()
nRF5x_addAppButton()
nRF5x_addBSP(TRUE FALSE FALSE)
nRF5x_addBLEGATT()
nRF5x_addBLEService(ble_lbs)
add_definitions(-DCONFIG_GPIO_AS_PINRESET)
# usually you would include files in this directory here, like so:
#include_directories(.)
#list(APPEND SOURCE_FILES main.c)
# for example projects we include the example source files
include_directories(${NRF_PROJECT_DEVICE_PATH}/config)
list(APPEND SOURCE_FILES ${NRF_PROJECT_PATH}/main.c)
nRF5x_addExecutable(BlinkyExample "${SOURCE_FILES}")

152
cmake-nRF5x/readme.md Executable file
View file

@ -0,0 +1,152 @@
# cmake-nRF5x
Cmake script for projects targeting Nordic Semiconductor nRF5x series devices using the GCC toolchain from ARM.
# Dependencies
The script makes use of the following tools:
- nRF5x SDK by Nordic Semiconductor - SoC specific drivers and libraries (also includes a lot of examples)
- JLink by Segger - interface software for the JLink familiy of programmers
- nrfjprog by Nordic Semiconductor - Wrapper utility around JLink
- arm-non-eabi-gcc by ARM and the GCC Team - compiler toolchain for embedded (= bare metal) ARM chips
# Setup
1. Download this repo (or add as submodule) to the directory `cmake-nRF5x` in your project
1. Search the SDK `example` directory for a `sdk_config.h`, `main.c` and a linker script (normally named `<project_name>_gcc_<chip familly>.ld`) that fits your chip and project needs.
1. Copy the `sdk_config.h` and the project `main.c` into a new directory `src`. Modify them as required for your project.
1. Copy the linker script into the root of your project. Rename it to just `gcc_<chip familly>.ld` For example:
```
gcc_nrf51.ld
gcc_nrf52.ld
```
1. Create a new `CMakeLists.txt` file at the same level. Add the project standard cmake project header
A typical file may look like this:
```
cmake_minimum_required(VERSION 3.6)
set(NRF_TARGET "nrf52")
# optional, won't be used if passing toolchain on command line (see below)
if (NOT DEFINED ARM_NONE_EABI_TOOLCHAIN_PATH)
set(ARM_NONE_EABI_TOOLCHAIN_PATH "/usr/local/bin")
endif ()
set(NRF5_SDK_PATH "${CMAKE_SOURCE_DIR}/toolchains/nRF5/nRF5_SDK")
set(NRFJPROG "${CMAKE_SOURCE_DIR}/toolchains/nRF5/nrfjprog/nrfjprog")
include("cmake-nRF5x/CMake_nRF5x.cmake")
# must be called before first project call or add_subdirectory unless passing on command line
nRF5x_toolchainSetup()
project(YourProjectName C ASM)
nRF5x_setup()
nRF5x_addAppScheduler()
nRF5x_addAppFIFO()
nRF5x_addAppTimer()
nRF5x_addAppUART()
nRF5x_addAppButton()
nRF5x_addBSP(TRUE FALSE FALSE)
nRF5x_addBLEGATT()
nRF5x_addBLEService(ble_bas)
add_definitions(-DCONFIG_GPIO_AS_PINRESET)
include_directories("./src")
list(APPEND SOURCE_FILES "./src/main.c")
nRF5x_addExecutable(${PROJECT_NAME} "${SOURCE_FILES}")
```
Adjust as needed for your project.
_Note_: you can add `CXX` between `C ASM` to add c++ support
1. Optionally add additional libraries:
Only the most common drivers and libraries are wrapped with cmake macros.
To include BLE services, use `nRF5x_addBLEService(<service name>)`.
For other SDK libraries you can use `include_directories` and `list(APPEND SDK_SOURCE_FILES ...)` to add them. For example:
```cmake
include_directories(
"${NRF5_SDK_PATH}/<library header directory path>"
)
list(APPEND SDK_SOURCE_FILES
"${NRF5_SDK_PATH}/<library source file path>"
)
```
# Build
After setup you can use cmake as usual:
1. Generate the actual build files (out-of-source builds are strongly recomended):
```commandline
cmake -H. -B"cmake-build" -G "Unix Makefiles"
```
You can optionally pass the toolchain to `cmake` when configuring:
```
-DCMAKE_TOOLCHAIN_PATH=cmake-nRF5x/arm-gcc-toolchain.cmake
```
but if you do so you must ensure the toolchain binaries are available in your environment PATH (i.e. work on the command line without specifying absolute path)
2. Build your app:
```commandline
cmake --build "cmake-build" --target <your project name>
```
# Flash
In addition to the build target (named like your project) the script adds some support targets:
`FLASH_SOFTDEVICE` To flash a nRF softdevice to the SoC (typically done only once for each SoC)
```commandline
cmake --build "cmake-build" --target FLASH_SOFTDEVICE
```
`FLASH_<your project name>` To flash your application (this will also rebuild your App first)
```commandline
cmake --build "cmake-build" --target FLASH_<your project name>
```
`FLASH_ERASE` To completely erase the SoC flash
```commandline
cmake --build "cmake-build" --target FLASH_ERASE
```
# JLink Applications
To start the gdb server and RTT terminal, build the target `START_JLINK`:
```commandline
cmake --build "cmake-build" --target START_JLINK
```
# License
MIT for the `CMake_nRF5x.cmake` file.
Please note that the nRF5x SDK by Nordic Semiconductor is covered by it's own license and shouldn't be re-distributed.

3
cmake-nRF5x/runJLinkExe-nrf51 Executable file
View file

@ -0,0 +1,3 @@
#!/bin/bash
JLinkExe -device nrf51 -if swd -speed 4000 -autoconnect 1

3
cmake-nRF5x/runJLinkExe-nrf52 Executable file
View file

@ -0,0 +1,3 @@
#!/bin/bash
JLinkExe -device nrf52 -if swd -speed 4000 -autoconnect 1

View file

@ -0,0 +1,3 @@
#!/bin/bash
JLinkGDBServer -device nrf51 -strict -timeout 0 -nogui -if swd -speed 1000 -endian little

View file

@ -0,0 +1,3 @@
#!/bin/bash
JLinkGDBServer -device nrf52 -strict -timeout 0 -nogui -if swd -speed 1000 -endian little

3
cmake-nRF5x/runJLinkRTTClient Executable file
View file

@ -0,0 +1,3 @@
#!/bin/bash
JLinkRTTClient

136
gcc_nrf52.ld Normal file
View file

@ -0,0 +1,136 @@
/* Linker script to configure memory regions. */
SEARCH_DIR(.)
GROUP(-lgcc -lc -lnosys)
MEMORY
{
FLASH (rx) : ORIGIN = 0x26000, LENGTH = 0x5a000
RAM (rwx) : ORIGIN = 0x200057b8, LENGTH = 0xa848
}
SECTIONS
{
}
SECTIONS
{
. = ALIGN(4);
.mem_section_dummy_ram :
{
}
.cli_sorted_cmd_ptrs :
{
PROVIDE(__start_cli_sorted_cmd_ptrs = .);
KEEP(*(.cli_sorted_cmd_ptrs))
PROVIDE(__stop_cli_sorted_cmd_ptrs = .);
} > RAM
.fs_data :
{
PROVIDE(__start_fs_data = .);
KEEP(*(.fs_data))
PROVIDE(__stop_fs_data = .);
} > RAM
.log_dynamic_data :
{
PROVIDE(__start_log_dynamic_data = .);
KEEP(*(SORT(.log_dynamic_data*)))
PROVIDE(__stop_log_dynamic_data = .);
} > RAM
.log_filter_data :
{
PROVIDE(__start_log_filter_data = .);
KEEP(*(SORT(.log_filter_data*)))
PROVIDE(__stop_log_filter_data = .);
} > RAM
} INSERT AFTER .data;
SECTIONS
{
.mem_section_dummy_rom :
{
}
.sdh_soc_observers :
{
PROVIDE(__start_sdh_soc_observers = .);
KEEP(*(SORT(.sdh_soc_observers*)))
PROVIDE(__stop_sdh_soc_observers = .);
} > FLASH
.sdh_ble_observers :
{
PROVIDE(__start_sdh_ble_observers = .);
KEEP(*(SORT(.sdh_ble_observers*)))
PROVIDE(__stop_sdh_ble_observers = .);
} > FLASH
.sdh_req_observers :
{
PROVIDE(__start_sdh_req_observers = .);
KEEP(*(SORT(.sdh_req_observers*)))
PROVIDE(__stop_sdh_req_observers = .);
} > FLASH
.sdh_state_observers :
{
PROVIDE(__start_sdh_state_observers = .);
KEEP(*(SORT(.sdh_state_observers*)))
PROVIDE(__stop_sdh_state_observers = .);
} > FLASH
.sdh_stack_observers :
{
PROVIDE(__start_sdh_stack_observers = .);
KEEP(*(SORT(.sdh_stack_observers*)))
PROVIDE(__stop_sdh_stack_observers = .);
} > FLASH
.nrf_queue :
{
PROVIDE(__start_nrf_queue = .);
KEEP(*(.nrf_queue))
PROVIDE(__stop_nrf_queue = .);
} > FLASH
.nrf_balloc :
{
PROVIDE(__start_nrf_balloc = .);
KEEP(*(.nrf_balloc))
PROVIDE(__stop_nrf_balloc = .);
} > FLASH
.cli_command :
{
PROVIDE(__start_cli_command = .);
KEEP(*(.cli_command))
PROVIDE(__stop_cli_command = .);
} > FLASH
.crypto_data :
{
PROVIDE(__start_crypto_data = .);
KEEP(*(SORT(.crypto_data*)))
PROVIDE(__stop_crypto_data = .);
} > FLASH
.pwr_mgmt_data :
{
PROVIDE(__start_pwr_mgmt_data = .);
KEEP(*(SORT(.pwr_mgmt_data*)))
PROVIDE(__stop_pwr_mgmt_data = .);
} > FLASH
.log_const_data :
{
PROVIDE(__start_log_const_data = .);
KEEP(*(SORT(.log_const_data*)))
PROVIDE(__stop_log_const_data = .);
} > FLASH
.log_backends :
{
PROVIDE(__start_log_backends = .);
KEEP(*(SORT(.log_backends*)))
PROVIDE(__stop_log_backends = .);
} > FLASH
.nrf_balloc :
{
PROVIDE(__start_nrf_balloc = .);
KEEP(*(.nrf_balloc))
PROVIDE(__stop_nrf_balloc = .);
} > FLASH
} INSERT AFTER .text
INCLUDE "nrf_common.ld"

23
src/BlinkApp/BlinkApp.cpp Normal file
View file

@ -0,0 +1,23 @@
#include "BlinkApp.h"
#include <FreeRTOS.h>
#include <task.h>
#include <libraries/log/nrf_log.h>
#include <boards.h>
using namespace Pinetime::Applications;
void BlinkApp::Start() {
if (pdPASS != xTaskCreate(BlinkApp::Process, "BlinkApp", 256, this, 0, &taskHandle))
APP_ERROR_HANDLER(NRF_ERROR_NO_MEM);
}
void BlinkApp::Process(void *instance) {
auto* app = static_cast<BlinkApp*>(instance);
NRF_LOG_INFO("BlinkApp task started!");
while (1) {
NRF_LOG_INFO("BlinkApp task running!");
bsp_board_led_invert(0);
vTaskDelay(1000);
}
}

15
src/BlinkApp/BlinkApp.h Normal file
View file

@ -0,0 +1,15 @@
#pragma once
#include <FreeRTOS.h>
#include <task.h>
namespace Pinetime {
namespace Applications {
class BlinkApp {
public:
void Start();
private:
TaskHandle_t taskHandle;
static void Process(void* instance);
};
}
}

42
src/CMakeLists.txt Normal file
View file

@ -0,0 +1,42 @@
cmake_minimum_required(VERSION 3.12)
project(pinetime-app C CXX ASM)
# define some variables just for this example to determine file locations
set(NRF_PROJECT_NAME pinetime-app)
set(NRF_BOARD pca10040)
#set(NRF_SOFTDEVICE s132)
nRF5x_toolchainSetup()
nRF5x_setup()
#nRF5x_addAppScheduler()
#nRF5x_addAppFIFO()
#nRF5x_addAppTimer()
#nRF5x_addAppUART()
nRF5x_addAppButton()
nRF5x_addBSP(FALSE FALSE FALSE)
nRF5x_addAppGpiote()
#nRF5x_addBLEGATT()
#
#nRF5x_addBLEService(ble_lbs)
add_definitions(-DCONFIG_GPIO_AS_PINRESET)
add_definitions(-DDEBUG)
include_directories(.)
list(APPEND SOURCE_FILES
Logging/NrfLogger.cpp
BlinkApp/BlinkApp.cpp
main.cpp
)
set(INCLUDE_FILES
Logging/Logger.h
Logging/NrfLogger.h
BlinkApp/BlinkApp.h
)
nRF5x_addExecutable(pinetime-app "${SOURCE_FILES}")

207
src/FreeRTOSConfig.h Normal file
View file

@ -0,0 +1,207 @@
/*
* FreeRTOS Kernel V10.0.0
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software. If you wish to use our Amazon
* FreeRTOS name, please do so in a fair use way that does not cause confusion.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://www.FreeRTOS.org
* http://aws.amazon.com/freertos
*
* 1 tab == 4 spaces!
*/
#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H
#ifdef SOFTDEVICE_PRESENT
#include "nrf_soc.h"
#endif
#include "app_util_platform.h"
/*-----------------------------------------------------------
* Possible configurations for system timer
*/
#define FREERTOS_USE_RTC 0 /**< Use real time clock for the system */
#define FREERTOS_USE_SYSTICK 1 /**< Use SysTick timer for system */
/*-----------------------------------------------------------
* Application specific definitions.
*
* These definitions should be adjusted for your particular hardware and
* application requirements.
*
* THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE
* FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE.
*
* See http://www.freertos.org/a00110.html.
*----------------------------------------------------------*/
#define configTICK_SOURCE FREERTOS_USE_RTC
#define configUSE_PREEMPTION 1
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 1
#define configUSE_TICKLESS_IDLE 1
#define configUSE_TICKLESS_IDLE_SIMPLE_DEBUG 1 /* See into vPortSuppressTicksAndSleep source code for explanation */
#define configCPU_CLOCK_HZ ( SystemCoreClock )
#define configTICK_RATE_HZ 1024
#define configMAX_PRIORITIES ( 3 )
#define configMINIMAL_STACK_SIZE ( 60 )
#define configTOTAL_HEAP_SIZE ( 24000 )
#define configMAX_TASK_NAME_LEN ( 4 )
#define configUSE_16_BIT_TICKS 0
#define configIDLE_SHOULD_YIELD 1
#define configUSE_MUTEXES 1
#define configUSE_RECURSIVE_MUTEXES 1
#define configUSE_COUNTING_SEMAPHORES 1
#define configUSE_ALTERNATIVE_API 0 /* Deprecated! */
#define configQUEUE_REGISTRY_SIZE 2
#define configUSE_QUEUE_SETS 0
#define configUSE_TIME_SLICING 0
#define configUSE_NEWLIB_REENTRANT 0
#define configENABLE_BACKWARD_COMPATIBILITY 1
/* Hook function related definitions. */
#define configUSE_IDLE_HOOK 1
#define configUSE_TICK_HOOK 0
#define configCHECK_FOR_STACK_OVERFLOW 2
#define configUSE_MALLOC_FAILED_HOOK 0
/* Run time and task stats gathering related definitions. */
#define configGENERATE_RUN_TIME_STATS 0
#define configUSE_TRACE_FACILITY 0
#define configUSE_STATS_FORMATTING_FUNCTIONS 0
/* Co-routine definitions. */
#define configUSE_CO_ROUTINES 0
#define configMAX_CO_ROUTINE_PRIORITIES ( 2 )
/* Software timer definitions. */
#define configUSE_TIMERS 1
#define configTIMER_TASK_PRIORITY ( 0 )
#define configTIMER_QUEUE_LENGTH 32
#define configTIMER_TASK_STACK_DEPTH ( 120 )
/* Tickless Idle configuration. */
#define configEXPECTED_IDLE_TIME_BEFORE_SLEEP 2
/* Tickless idle/low power functionality. */
/* Define to trap errors during development. */
#if defined(DEBUG_NRF) || defined(DEBUG_NRF_USER)
#define configASSERT( x ) ASSERT(x)
#endif
/* FreeRTOS MPU specific definitions. */
#define configINCLUDE_APPLICATION_DEFINED_PRIVILEGED_FUNCTIONS 1
/* Optional functions - most linkers will remove unused functions anyway. */
#define INCLUDE_vTaskPrioritySet 1
#define INCLUDE_uxTaskPriorityGet 1
#define INCLUDE_vTaskDelete 1
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_xResumeFromISR 1
#define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1
#define INCLUDE_xTaskGetSchedulerState 1
#define INCLUDE_xTaskGetCurrentTaskHandle 1
#define INCLUDE_uxTaskGetStackHighWaterMark 1
#define INCLUDE_xTaskGetIdleTaskHandle 1
#define INCLUDE_xTimerGetTimerDaemonTaskHandle 1
#define INCLUDE_pcTaskGetTaskName 1
#define INCLUDE_eTaskGetState 1
#define INCLUDE_xEventGroupSetBitFromISR 1
#define INCLUDE_xTimerPendFunctionCall 1
/* The lowest interrupt priority that can be used in a call to a "set priority"
function. */
#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 0xf
/* The highest interrupt priority that can be used by any interrupt service
routine that makes calls to interrupt safe FreeRTOS API functions. DO NOT CALL
INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER
PRIORITY THAN THIS! (higher priorities are lower numeric values. */
#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY _PRIO_APP_HIGH
/* Interrupt priorities used by the kernel port layer itself. These are generic
to all Cortex-M ports, and do not rely on any particular library functions. */
#define configKERNEL_INTERRUPT_PRIORITY configLIBRARY_LOWEST_INTERRUPT_PRIORITY
/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!!
See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */
#define configMAX_SYSCALL_INTERRUPT_PRIORITY configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY
/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS
standard names - or at least those used in the unmodified vector table. */
#define vPortSVCHandler SVC_Handler
#define xPortPendSVHandler PendSV_Handler
/*-----------------------------------------------------------
* Settings that are generated automatically
* basing on the settings above
*/
#if (configTICK_SOURCE == FREERTOS_USE_SYSTICK)
// do not define configSYSTICK_CLOCK_HZ for SysTick to be configured automatically
// to CPU clock source
#define xPortSysTickHandler SysTick_Handler
#elif (configTICK_SOURCE == FREERTOS_USE_RTC)
#define configSYSTICK_CLOCK_HZ ( 32768UL )
#define xPortSysTickHandler RTC1_IRQHandler
#else
#error Unsupported configTICK_SOURCE value
#endif
/* Code below should be only used by the compiler, and not the assembler. */
#if !(defined(__ASSEMBLY__) || defined(__ASSEMBLER__))
#include "nrf.h"
#include "nrf_assert.h"
/* This part of definitions may be problematic in assembly - it uses definitions from files that are not assembly compatible. */
/* Cortex-M specific definitions. */
#ifdef __NVIC_PRIO_BITS
/* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */
#define configPRIO_BITS __NVIC_PRIO_BITS
#else
#error "This port requires __NVIC_PRIO_BITS to be defined"
#endif
/* Access to current system core clock is required only if we are ticking the system by systimer */
#if (configTICK_SOURCE == FREERTOS_USE_SYSTICK)
#include <stdint.h>
extern uint32_t SystemCoreClock;
#endif
#endif /* !assembler */
/** Implementation note: Use this with caution and set this to 1 ONLY for debugging
* ----------------------------------------------------------
* Set the value of configUSE_DISABLE_TICK_AUTO_CORRECTION_DEBUG to below for enabling or disabling RTOS tick auto correction:
* 0. This is default. If the RTC tick interrupt is masked for more than 1 tick by higher priority interrupts, then most likely
* one or more RTC ticks are lost. The tick interrupt inside RTOS will detect this and make a correction needed. This is needed
* for the RTOS internal timers to be more accurate.
* 1. The auto correction for RTOS tick is disabled even though few RTC tick interrupts were lost. This feature is desirable when debugging
* the RTOS application and stepping though the code. After stepping when the application is continued in debug mode, the auto-corrections of
* RTOS tick might cause asserts. Setting configUSE_DISABLE_TICK_AUTO_CORRECTION_DEBUG to 1 will make RTC and RTOS go out of sync but could be
* convenient for debugging.
*/
#define configUSE_DISABLE_TICK_AUTO_CORRECTION_DEBUG 0
#endif /* FREERTOS_CONFIG_H */

13
src/Logging/DummyLogger.h Normal file
View file

@ -0,0 +1,13 @@
#pragma once
#include "Logger.h"
namespace Pinetime {
namespace Logging{
class DummyLogger : public Logger {
public:
void Init() override {}
void Resume() override {}
};
}
}

11
src/Logging/Logger.h Normal file
View file

@ -0,0 +1,11 @@
#pragma once
namespace Pinetime {
namespace Logging {
class Logger {
public:
virtual void Init() = 0;
virtual void Resume() = 0;
};
}
}

32
src/Logging/NrfLogger.cpp Normal file
View file

@ -0,0 +1,32 @@
#include <libraries/log/nrf_log_ctrl.h>
#include <libraries/log/nrf_log_default_backends.h>
#include <FreeRTOS.h>
#include <task.h>
#include <libraries/log/nrf_log.h>
#include "NrfLogger.h"
using namespace Pinetime::Logging;
void NrfLogger::Init() {
auto result = NRF_LOG_INIT(nullptr);
APP_ERROR_CHECK(result);
NRF_LOG_DEFAULT_BACKENDS_INIT();
if (pdPASS != xTaskCreate(NrfLogger::Process, "LOGGER", 512, nullptr, 0, &m_logger_thread))
APP_ERROR_HANDLER(NRF_ERROR_NO_MEM);
}
void NrfLogger::Process(void*) {
NRF_LOG_INFO("Logger task started!");
while (1) {
NRF_LOG_FLUSH();
vTaskSuspend(nullptr);
}
}
void NrfLogger::Resume() {
vTaskResume(m_logger_thread);
}

17
src/Logging/NrfLogger.h Normal file
View file

@ -0,0 +1,17 @@
#pragma once
#include "Logger.h"
namespace Pinetime {
namespace Logging{
class NrfLogger : public Logger {
public:
void Init() override;
void Resume() override;
private:
static void Process(void*);
TaskHandle_t m_logger_thread;
};
}
}

76
src/main.cpp Normal file
View file

@ -0,0 +1,76 @@
#include <FreeRTOS.h>
#include <task.h>
#include <libraries/log/nrf_log.h>
#include <BlinkApp/BlinkApp.h>
#include <boards.h>
#include <libraries/bsp/bsp.h>
#include <legacy/nrf_drv_clock.h>
#include <libraries/timer/app_timer.h>
#include <libraries/gpiote/app_gpiote.h>
#if NRF_LOG_ENABLED
#include "Logging/NrfLogger.h"
Pinetime::Logging::NrfLogger logger;
#else
#include "Logging/DummyLogger.h"
Pinetime::Logging::DummyLogger logger;
#endif
Pinetime::Applications::BlinkApp blinkApp;
TaskHandle_t systemThread;
extern "C" {
void vApplicationIdleHook() {
logger.Resume();
}
void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed portCHAR *pcTaskName ) {
bsp_board_led_on(3);
}
}
static void bsp_event_handler(bsp_event_t event)
{
switch (event)
{
case BSP_EVENT_KEY_0:
NRF_LOG_INFO("Button pressed");
break;
default:
break;
}
}
void SystemTask(void *) {
APP_GPIOTE_INIT(2);
app_timer_init();
bsp_board_init(BSP_INIT_LEDS|BSP_INIT_BUTTONS);
bsp_init(BSP_INIT_LEDS | BSP_INIT_BUTTONS, bsp_event_handler);
blinkApp.Start();
while (1) {
vTaskSuspend(nullptr);
}
}
int main(void) {
logger.Init();
nrf_drv_clock_init();
if (pdPASS != xTaskCreate(SystemTask, "MAIN", 256, nullptr, 0, &systemThread))
APP_ERROR_HANDLER(NRF_ERROR_NO_MEM);
vTaskStartScheduler();
for (;;) {
APP_ERROR_HANDLER(NRF_ERROR_FORBIDDEN);
}
}

12938
src/sdk_config.h Normal file

File diff suppressed because it is too large Load diff