Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ed7017c69d | |||
| c2c3ea10b9 | |||
| 49e251cf54 | |||
| f8972a3a58 | |||
| 5a5ba7e215 | |||
| b02fd4c33f | |||
| 33dfa5692d | |||
| 76cdaa4abf | |||
| d0950ba6e0 | |||
| 5a1b8cb193 | |||
| 9f510d5095 | |||
| 6a296b6b17 | |||
| d19d4e08cf | |||
| c2f018bd8e | |||
| 80fb19859f | |||
| e9788b10df |
+2
-3
@@ -17,6 +17,7 @@ ColumnLimit: 0
|
|||||||
BreakBeforeBraces: Custom
|
BreakBeforeBraces: Custom
|
||||||
NamespaceIndentation: All
|
NamespaceIndentation: All
|
||||||
TabWidth: 4
|
TabWidth: 4
|
||||||
|
UseTab: Never
|
||||||
IndentCaseLabels: true
|
IndentCaseLabels: true
|
||||||
AlignAfterOpenBracket: Align
|
AlignAfterOpenBracket: Align
|
||||||
PointerAlignment: Right
|
PointerAlignment: Right
|
||||||
@@ -24,12 +25,12 @@ AlignOperands: true
|
|||||||
AllowAllParametersOfDeclarationOnNextLine: false
|
AllowAllParametersOfDeclarationOnNextLine: false
|
||||||
AllowShortLoopsOnASingleLine: true
|
AllowShortLoopsOnASingleLine: true
|
||||||
AllowShortIfStatementsOnASingleLine: true
|
AllowShortIfStatementsOnASingleLine: true
|
||||||
|
AllowShortFunctionsOnASingleLine: None
|
||||||
BinPackArguments: false
|
BinPackArguments: false
|
||||||
BinPackParameters: false
|
BinPackParameters: false
|
||||||
BreakBeforeBinaryOperators: None
|
BreakBeforeBinaryOperators: None
|
||||||
BreakBeforeTernaryOperators: false
|
BreakBeforeTernaryOperators: false
|
||||||
BreakAfterJavaFieldAnnotations: true
|
BreakAfterJavaFieldAnnotations: true
|
||||||
AlignConsecutiveAssignments: true
|
|
||||||
AlignTrailingComments: true
|
AlignTrailingComments: true
|
||||||
BreakConstructorInitializers: AfterColon
|
BreakConstructorInitializers: AfterColon
|
||||||
AlignConsecutiveMacros:
|
AlignConsecutiveMacros:
|
||||||
@@ -50,6 +51,4 @@ AlignConsecutiveBitFields:
|
|||||||
AlignCompound: true
|
AlignCompound: true
|
||||||
PadOperators: true
|
PadOperators: true
|
||||||
AlignEscapedNewlines: Right
|
AlignEscapedNewlines: Right
|
||||||
BinPackArguments: false
|
|
||||||
BinPackParameters: false
|
|
||||||
...
|
...
|
||||||
|
|||||||
@@ -2,3 +2,4 @@
|
|||||||
/.visualgdb/
|
/.visualgdb/
|
||||||
/VisualGDB/
|
/VisualGDB/
|
||||||
*.vgdbsettings.*.user
|
*.vgdbsettings.*.user
|
||||||
|
/build/
|
||||||
|
|||||||
Vendored
+76
@@ -0,0 +1,76 @@
|
|||||||
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"cwd": "${workspaceRoot}",
|
||||||
|
"executable": "${command:cmake.launchTargetPath}",
|
||||||
|
"name": "(Ubuntu) launch & debug",
|
||||||
|
"request": "launch",
|
||||||
|
"type": "cortex-debug",
|
||||||
|
"servertype": "jlink",
|
||||||
|
"serverpath": "/opt/SEGGER/JLink/JLinkGDBServerCLExe",
|
||||||
|
"serverArgs": [
|
||||||
|
"-halt",
|
||||||
|
"-ir",
|
||||||
|
"-vd",
|
||||||
|
"-strict",
|
||||||
|
],
|
||||||
|
"rttConfig": {
|
||||||
|
"enabled": true,
|
||||||
|
"address": "auto",
|
||||||
|
"decoders": [
|
||||||
|
{
|
||||||
|
"label": "",
|
||||||
|
"port": 0,
|
||||||
|
"type": "console"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
},
|
||||||
|
"armToolchainPath": "/opt/arm-none-eabi/bin",
|
||||||
|
"device": "NRF52840_XXAA",
|
||||||
|
"interface": "swd",
|
||||||
|
"rtos": "FreeRTOS",
|
||||||
|
"svdFile": "${workspaceRoot}/../bmd380_sdk/modules/nrfx/mdk/nrf52840.svd",
|
||||||
|
"runToEntryPoint": "main",
|
||||||
|
"preLaunchTask": "CMake: build",
|
||||||
|
"serialNumber": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cwd": "${workspaceRoot}",
|
||||||
|
"executable": "${command:cmake.launchTargetPath}",
|
||||||
|
"name": "(Windows) launch & debug",
|
||||||
|
"request": "launch",
|
||||||
|
"type": "cortex-debug",
|
||||||
|
"servertype": "jlink",
|
||||||
|
"serverpath": "C:/Program Files/SEGGER/JLink/JLinkGDBServerCL.exe",
|
||||||
|
"serverArgs": [
|
||||||
|
"-halt",
|
||||||
|
"-ir",
|
||||||
|
"-vd",
|
||||||
|
"-strict",
|
||||||
|
],
|
||||||
|
"rttConfig": {
|
||||||
|
"enabled": true,
|
||||||
|
"address": "auto",
|
||||||
|
"decoders": [
|
||||||
|
{
|
||||||
|
"label": "",
|
||||||
|
"port": 0,
|
||||||
|
"type": "console"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
},
|
||||||
|
"armToolchainPath": "C:/sysgcc/arm-eabi/bin",
|
||||||
|
"device": "NRF52840_XXAA",
|
||||||
|
"interface": "swd",
|
||||||
|
"rtos": "FreeRTOS",
|
||||||
|
"svdFile": "${workspaceRoot}/../bmd380_sdk/modules/nrfx/mdk/nrf52840.svd",
|
||||||
|
"runToEntryPoint": "main",
|
||||||
|
"preLaunchTask": "CMake: build",
|
||||||
|
"serialNumber": ""
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
Vendored
+15
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"editor.formatOnSave": false,
|
||||||
|
"[c]": {
|
||||||
|
"editor.defaultFormatter": "xaver.clang-format",
|
||||||
|
"editor.formatOnSave": true
|
||||||
|
},
|
||||||
|
"[cpp]": {
|
||||||
|
"editor.defaultFormatter": "xaver.clang-format",
|
||||||
|
"editor.formatOnSave": true
|
||||||
|
},
|
||||||
|
"[python]": {
|
||||||
|
"editor.defaultFormatter": "ms-python.black-formatter",
|
||||||
|
"editor.formatOnSave": true
|
||||||
|
}
|
||||||
|
}
|
||||||
Vendored
+33
@@ -0,0 +1,33 @@
|
|||||||
|
{
|
||||||
|
"version": "2.0.0",
|
||||||
|
"tasks": [
|
||||||
|
{
|
||||||
|
"type": "cmake",
|
||||||
|
"label": "CMake: build",
|
||||||
|
"command": "build",
|
||||||
|
"targets": [
|
||||||
|
"all"
|
||||||
|
],
|
||||||
|
"preset": "${command:cmake.activeBuildPresetName}",
|
||||||
|
"group": {
|
||||||
|
"kind": "build"
|
||||||
|
},
|
||||||
|
"problemMatcher": [],
|
||||||
|
"detail": "CMake template build task"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "cmake",
|
||||||
|
"label": "CMake: clean rebuild",
|
||||||
|
"command": "cleanRebuild",
|
||||||
|
"targets": [
|
||||||
|
"all"
|
||||||
|
],
|
||||||
|
"group": {
|
||||||
|
"isDefault": true,
|
||||||
|
"kind": "build"
|
||||||
|
},
|
||||||
|
"problemMatcher": [],
|
||||||
|
"detail": "CMake template clean rebuild task"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
+212
@@ -0,0 +1,212 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.15.3)
|
||||||
|
|
||||||
|
# Verbose output (optional)
|
||||||
|
set(CMAKE_VERBOSE_MAKEFILE ON)
|
||||||
|
|
||||||
|
# Toolchain must be set before project()
|
||||||
|
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/cmake/arm-none-eabi-gcc.cmake)
|
||||||
|
include(${CMAKE_TOOLCHAIN_FILE})
|
||||||
|
|
||||||
|
# Project setup
|
||||||
|
project(bmd380_central
|
||||||
|
VERSION 1.0.0
|
||||||
|
LANGUAGES C ASM
|
||||||
|
)
|
||||||
|
set(EXECUTABLE ${PROJECT_NAME}.elf)
|
||||||
|
set(NRF_SDK_DIR ${CMAKE_SOURCE_DIR}/../bmd380_sdk)
|
||||||
|
#set(LINKER_FILE ${CMAKE_SOURCE_DIR}/linkscripts/nRF52840_XXAA_s140.lds)
|
||||||
|
set(LINKER_FILE ${CMAKE_SOURCE_DIR}/linkscripts/nRF52840_XXAA_S140_reserve.lds)
|
||||||
|
set(LINKER_DIR ${CMAKE_SOURCE_DIR}/linkscripts)
|
||||||
|
set(NRF_SDK_LINKER_DIR ${NRF_SDK_DIR}/modules/nrfx/mdk)
|
||||||
|
set(SD_LINKER_DIR ${CMAKE_SOURCE_DIR}/SoftdeviceLibraries/hard)
|
||||||
|
|
||||||
|
|
||||||
|
set(CMAKE_C_STANDARD 99)
|
||||||
|
set(CMAKE_C_STANDARD_REQUIRED ON)
|
||||||
|
set(CMAKE_C_EXTENSIONS ON)
|
||||||
|
# Define the build type
|
||||||
|
if(NOT CMAKE_BUILD_TYPE)
|
||||||
|
set(CMAKE_BUILD_TYPE "Debug")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
message(STATUS "Using toolchain file: ${CMAKE_TOOLCHAIN_FILE}")
|
||||||
|
|
||||||
|
set(COMMON_COMPILE_OPT
|
||||||
|
-mcpu=cortex-m4
|
||||||
|
-mfpu=fpv4-sp-d16
|
||||||
|
-mfloat-abi=hard
|
||||||
|
-mthumb
|
||||||
|
-fdata-sections
|
||||||
|
-ffunction-sections
|
||||||
|
-Wall
|
||||||
|
-Os
|
||||||
|
-g3
|
||||||
|
-std=gnu99
|
||||||
|
-Wno-unused-variable
|
||||||
|
-Wno-pointer-sign
|
||||||
|
-Wno-array-bounds
|
||||||
|
)
|
||||||
|
|
||||||
|
set(COMMON_COMPILE_DEF
|
||||||
|
-DDEBUG=1
|
||||||
|
-DNRF52840_XXAA
|
||||||
|
-DS140_reserve
|
||||||
|
-DCONFIG_GPIO_AS_PINRESET
|
||||||
|
-DRESETHNRF_DFU_SETTINGS_VERSION=2
|
||||||
|
-DNRF_SD_BLE_API_VERSION=7
|
||||||
|
-D__STACK_SIZE=1024
|
||||||
|
-D__HEAP_SIZE=1024
|
||||||
|
-DARM_MATH_CM4
|
||||||
|
-DSOFTDEVICE_PRESENT
|
||||||
|
-DUSE_APP_CONFIG
|
||||||
|
)
|
||||||
|
|
||||||
|
set(COMMON_COMPILE_INC
|
||||||
|
${ARM_TOOLCHAIN_DIR}/../arm-none-eabi/include
|
||||||
|
${CMAKE_SOURCE_DIR}/app
|
||||||
|
${NRF_SDK_DIR}/components/ble/ble_db_discovery
|
||||||
|
${NRF_SDK_DIR}/components/ble/ble_services/ble_dis
|
||||||
|
${NRF_SDK_DIR}/components/ble/ble_services/ble_dis_c
|
||||||
|
${NRF_SDK_DIR}/components/ble/common/
|
||||||
|
${NRF_SDK_DIR}/components/ble/nrf_ble_gatt
|
||||||
|
${NRF_SDK_DIR}/components/ble/nrf_ble_gq
|
||||||
|
${NRF_SDK_DIR}/components/ble/nrf_ble_scan
|
||||||
|
${NRF_SDK_DIR}/components/libraries/atomic
|
||||||
|
${NRF_SDK_DIR}/components/libraries/atomic_flags
|
||||||
|
${NRF_SDK_DIR}/components/libraries/balloc
|
||||||
|
${NRF_SDK_DIR}/components/libraries/delay
|
||||||
|
${NRF_SDK_DIR}/components/libraries/experimental_section_vars
|
||||||
|
${NRF_SDK_DIR}/components/libraries/log
|
||||||
|
${NRF_SDK_DIR}/components/libraries/log/src
|
||||||
|
${NRF_SDK_DIR}/components/libraries/memobj
|
||||||
|
${NRF_SDK_DIR}/components/libraries/queue
|
||||||
|
${NRF_SDK_DIR}/components/libraries/ringbuf
|
||||||
|
${NRF_SDK_DIR}/components/libraries/strerror
|
||||||
|
${NRF_SDK_DIR}/components/libraries/util
|
||||||
|
${NRF_SDK_DIR}/components/softdevice/common
|
||||||
|
${NRF_SDK_DIR}/components/softdevice/mbr/headers
|
||||||
|
${NRF_SDK_DIR}/components/softdevice/s140/headers
|
||||||
|
${NRF_SDK_DIR}/components/toolchain/cmsis/include
|
||||||
|
${NRF_SDK_DIR}/external/fprintf
|
||||||
|
${NRF_SDK_DIR}/external/freertos/portable/CMSIS/nrf52
|
||||||
|
${NRF_SDK_DIR}/external/freertos/portable/GCC/nrf52
|
||||||
|
${NRF_SDK_DIR}/external/freertos/source/include
|
||||||
|
${NRF_SDK_DIR}/external/segger_rtt
|
||||||
|
${NRF_SDK_DIR}/integration/nrfx
|
||||||
|
${NRF_SDK_DIR}/integration/nrfx/legacy
|
||||||
|
${NRF_SDK_DIR}/modules/nrfx
|
||||||
|
${NRF_SDK_DIR}/modules/nrfx/drivers/include
|
||||||
|
${NRF_SDK_DIR}/modules/nrfx/hal
|
||||||
|
${NRF_SDK_DIR}/modules/nrfx/mdk
|
||||||
|
)
|
||||||
|
|
||||||
|
# ==========================
|
||||||
|
# Prj Configuration
|
||||||
|
# ==========================
|
||||||
|
add_library(prj_config INTERFACE)
|
||||||
|
target_include_directories(prj_config INTERFACE ${COMMON_COMPILE_INC})
|
||||||
|
target_compile_definitions(prj_config INTERFACE ${COMMON_COMPILE_DEF})
|
||||||
|
target_compile_options(prj_config INTERFACE ${COMMON_COMPILE_OPT})
|
||||||
|
|
||||||
|
# ====================================================
|
||||||
|
# Add FreeRTOS kernel and portable layer
|
||||||
|
# Add application source files as an OBJECT library
|
||||||
|
# Add board support package (BSP) source files as an OBJECT library
|
||||||
|
# ====================================================
|
||||||
|
add_subdirectory(app)
|
||||||
|
include(cmake/freertos.cmake)
|
||||||
|
|
||||||
|
# ==========================
|
||||||
|
# Executable Target
|
||||||
|
# ==========================
|
||||||
|
add_executable(${EXECUTABLE}
|
||||||
|
$<TARGET_OBJECTS:app>
|
||||||
|
${NRF_SDK_DIR}/components/ble/ble_db_discovery/ble_db_discovery.c
|
||||||
|
${NRF_SDK_DIR}/components/ble/ble_services/ble_dis_c/ble_dis_c.c
|
||||||
|
${NRF_SDK_DIR}/components/ble/common/ble_advdata.c
|
||||||
|
${NRF_SDK_DIR}/components/ble/common/ble_conn_params.c
|
||||||
|
${NRF_SDK_DIR}/components/ble/common/ble_conn_state.c
|
||||||
|
${NRF_SDK_DIR}/components/ble/nrf_ble_gatt/nrf_ble_gatt.c
|
||||||
|
${NRF_SDK_DIR}/components/ble/nrf_ble_gq/nrf_ble_gq.c
|
||||||
|
${NRF_SDK_DIR}/components/ble/nrf_ble_scan/nrf_ble_scan.c
|
||||||
|
${NRF_SDK_DIR}/components/libraries/atomic/nrf_atomic.c
|
||||||
|
${NRF_SDK_DIR}/components/libraries/atomic_flags/nrf_atflags.c
|
||||||
|
${NRF_SDK_DIR}/components/libraries/balloc/nrf_balloc.c
|
||||||
|
${NRF_SDK_DIR}/components/libraries/experimental_section_vars/nrf_section_iter.c
|
||||||
|
${NRF_SDK_DIR}/components/libraries/log/src/nrf_log_backend_rtt.c
|
||||||
|
${NRF_SDK_DIR}/components/libraries/log/src/nrf_log_backend_serial.c
|
||||||
|
${NRF_SDK_DIR}/components/libraries/log/src/nrf_log_default_backends.c
|
||||||
|
${NRF_SDK_DIR}/components/libraries/log/src/nrf_log_frontend.c
|
||||||
|
${NRF_SDK_DIR}/components/libraries/log/src/nrf_log_str_formatter.c
|
||||||
|
${NRF_SDK_DIR}/components/libraries/memobj/nrf_memobj.c
|
||||||
|
${NRF_SDK_DIR}/components/libraries/queue/nrf_queue.c
|
||||||
|
${NRF_SDK_DIR}/components/libraries/ringbuf/nrf_ringbuf.c
|
||||||
|
${NRF_SDK_DIR}/components/libraries/strerror/nrf_strerror.c
|
||||||
|
${NRF_SDK_DIR}/components/libraries/util/app_error.c
|
||||||
|
${NRF_SDK_DIR}/components/libraries/util/app_error_handler_gcc.c
|
||||||
|
${NRF_SDK_DIR}/components/libraries/util/app_error_weak.c
|
||||||
|
${NRF_SDK_DIR}/components/libraries/util/app_util_platform.c
|
||||||
|
${NRF_SDK_DIR}/components/softdevice/common/nrf_sdh.c
|
||||||
|
${NRF_SDK_DIR}/components/softdevice/common/nrf_sdh_ble.c
|
||||||
|
${NRF_SDK_DIR}/components/softdevice/common/nrf_sdh_freertos.c
|
||||||
|
${NRF_SDK_DIR}/external/fprintf/nrf_fprintf.c
|
||||||
|
${NRF_SDK_DIR}/external/fprintf/nrf_fprintf_format.c
|
||||||
|
${NRF_SDK_DIR}/external/segger_rtt/SEGGER_RTT.c
|
||||||
|
${NRF_SDK_DIR}/external/segger_rtt/SEGGER_RTT_printf.c
|
||||||
|
${NRF_SDK_DIR}/integration/nrfx/legacy/nrf_drv_clock.c
|
||||||
|
${NRF_SDK_DIR}/modules/nrfx/drivers/src/nrfx_clock.c
|
||||||
|
${NRF_SDK_DIR}/modules/nrfx/mdk/gcc_startup_nrf52840.S
|
||||||
|
${NRF_SDK_DIR}/modules/nrfx/mdk/system_nrf52.c
|
||||||
|
)
|
||||||
|
|
||||||
|
target_include_directories(${EXECUTABLE} PRIVATE ${COMMON_COMPILE_INC})
|
||||||
|
target_compile_definitions(${EXECUTABLE} PRIVATE ${COMMON_COMPILE_DEF})
|
||||||
|
target_compile_options(${EXECUTABLE} PRIVATE ${COMMON_COMPILE_OPT})
|
||||||
|
|
||||||
|
# ==========================
|
||||||
|
# Link configuration
|
||||||
|
# ==========================
|
||||||
|
|
||||||
|
# Linker options (linker script and flags)
|
||||||
|
target_link_options(${EXECUTABLE} PRIVATE
|
||||||
|
-T${LINKER_FILE} # Linker script
|
||||||
|
-L${SD_LINKER_DIR} # Linker library directory (SoftDevice)
|
||||||
|
-L${NRF_SDK_LINKER_DIR} # Linker library directory (SDK)
|
||||||
|
-L${LINKER_DIR} # Linker library directory
|
||||||
|
-mcpu=cortex-m4 # CPU architecture
|
||||||
|
-mfpu=fpv4-sp-d16 # Floating-point unit
|
||||||
|
-mfloat-abi=hard
|
||||||
|
-mthumb
|
||||||
|
--specs=nano.specs # Use nano C library
|
||||||
|
--specs=nosys.specs # Minimal syscall stubs
|
||||||
|
-u _printf_float # Enable float support in printf
|
||||||
|
-lc # Link C library
|
||||||
|
-lm # Link math library
|
||||||
|
-Wl,-Map=${PROJECT_NAME}.map,--cref # Generate memory map file
|
||||||
|
-Wl,--gc-sections # Remove unused sections
|
||||||
|
-Xlinker -print-memory-usage -Xlinker # Print memory usage after link
|
||||||
|
)
|
||||||
|
|
||||||
|
# Link with logical (target-based) libraries
|
||||||
|
target_link_libraries(${EXECUTABLE} PRIVATE
|
||||||
|
prj_config
|
||||||
|
app
|
||||||
|
freertos
|
||||||
|
)
|
||||||
|
|
||||||
|
# ==========================
|
||||||
|
# Post-build Actions
|
||||||
|
# ==========================
|
||||||
|
add_custom_command(TARGET ${EXECUTABLE}
|
||||||
|
POST_BUILD
|
||||||
|
COMMAND ${CMAKE_SIZE} ${EXECUTABLE}
|
||||||
|
COMMENT "Print memory usage"
|
||||||
|
)
|
||||||
|
|
||||||
|
add_custom_command(TARGET ${EXECUTABLE}
|
||||||
|
POST_BUILD
|
||||||
|
COMMAND ${CMAKE_OBJCOPY} -O srec --srec-len=64 ${EXECUTABLE} ${PROJECT_NAME}.s19
|
||||||
|
COMMAND ${CMAKE_OBJCOPY} -O ihex ${EXECUTABLE} ${PROJECT_NAME}.hex
|
||||||
|
COMMAND ${CMAKE_OBJCOPY} -O binary ${EXECUTABLE} ${PROJECT_NAME}.bin
|
||||||
|
COMMENT "Generate .s19, .hex, and .bin output files"
|
||||||
|
)
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
{
|
||||||
|
"version": 3,
|
||||||
|
"configurePresets": [
|
||||||
|
{
|
||||||
|
"name": "default",
|
||||||
|
"hidden": true,
|
||||||
|
"generator": "Ninja",
|
||||||
|
"binaryDir": "${sourceDir}/build/${presetName}",
|
||||||
|
"cacheVariables": {
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Debug",
|
||||||
|
"inherits": "default",
|
||||||
|
"cacheVariables": {
|
||||||
|
"CMAKE_BUILD_TYPE": "Debug"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "RelWithDebInfo",
|
||||||
|
"inherits": "default",
|
||||||
|
"cacheVariables": {
|
||||||
|
"CMAKE_BUILD_TYPE": "RelWithDebInfo"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Release",
|
||||||
|
"inherits": "default",
|
||||||
|
"cacheVariables": {
|
||||||
|
"CMAKE_BUILD_TYPE": "Release"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "MinSizeRel",
|
||||||
|
"inherits": "default",
|
||||||
|
"cacheVariables": {
|
||||||
|
"CMAKE_BUILD_TYPE": "MinSizeRel"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"buildPresets": [
|
||||||
|
{
|
||||||
|
"name": "Debug",
|
||||||
|
"configurePreset": "Debug"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "RelWithDebInfo",
|
||||||
|
"configurePreset": "RelWithDebInfo"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Release",
|
||||||
|
"configurePreset": "Release"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "MinSizeRel",
|
||||||
|
"configurePreset": "MinSizeRel"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
@echo off
|
||||||
|
REM Usage: ConvertSoftdevice.bat <Softdevice Name> <Intermediate Hex file name>
|
||||||
|
set ARM_GCC_PREFIX=arm-none-eabi-
|
||||||
|
cd /d %~dp0
|
||||||
|
|
||||||
|
if not exist soft mkdir soft
|
||||||
|
if not exist hard mkdir hard
|
||||||
|
|
||||||
|
%ARM_GCC_PREFIX%objcopy.exe --gap-fill 0xFF -I ihex -O binary %2 %1_softdevice.bin
|
||||||
|
|
||||||
|
%ARM_GCC_PREFIX%gcc empty.c -c -o hard\%1_softdevice.o -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16
|
||||||
|
%ARM_GCC_PREFIX%objcopy.exe --add-section .softdevice=%1_softdevice.bin --set-section-flags .softdevice=CONTENTS,ALLOC,LOAD,READONLY,CODE hard\%1_softdevice.o --remove-section .text --remove-section .data --remove-section .bss
|
||||||
|
|
||||||
|
%ARM_GCC_PREFIX%gcc empty.c -c -o soft\%1_softdevice.o -mcpu=cortex-m4 -mthumb -mfloat-abi=soft
|
||||||
|
%ARM_GCC_PREFIX%objcopy.exe --add-section .softdevice=%1_softdevice.bin --set-section-flags .softdevice=CONTENTS,ALLOC,LOAD,READONLY,CODE soft\%1_softdevice.o --remove-section .text --remove-section .data --remove-section .bss
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,3 @@
|
|||||||
|
void dummyfunc()
|
||||||
|
{
|
||||||
|
}
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,9 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.15.3)
|
||||||
|
|
||||||
|
file(GLOB_RECURSE APP_SOURCES "*.c")
|
||||||
|
|
||||||
|
add_library(app OBJECT ${APP_SOURCES})
|
||||||
|
|
||||||
|
target_link_libraries(app PRIVATE
|
||||||
|
prj_config
|
||||||
|
)
|
||||||
@@ -109,12 +109,18 @@ extern "C"
|
|||||||
#define DEF_ELITE_EIS_11 0x00040101
|
#define DEF_ELITE_EIS_11 0x00040101
|
||||||
#define DEF_ELITE_EIS_MINI_10 0x00040102
|
#define DEF_ELITE_EIS_MINI_10 0x00040102
|
||||||
|
|
||||||
#define LE_DEVICE_NAME "CENRAL"
|
#define LE_DEVICE_NAME "CENRAL MEMv2.0"
|
||||||
#define MAJOR_PRODUCT_NUMBER 0
|
#define MAJOR_PRODUCT_NUMBER 0
|
||||||
#define MINOR_PRODUCT_NUMBER 1
|
#define MINOR_PRODUCT_NUMBER 1
|
||||||
#define MAJOR_VERSION_NUMBER 0
|
#define MAJOR_VERSION_NUMBER 0
|
||||||
#define MINOR_VERSION_NUMBER 1
|
#define MINOR_VERSION_NUMBER 1
|
||||||
|
|
||||||
|
#define VERSION_DATE_YEAR 25
|
||||||
|
#define VERSION_DATE_MONTH 9
|
||||||
|
#define VERSION_DATE_DAY 1
|
||||||
|
#define VERSION_DATE_HOUR 16
|
||||||
|
#define VERSION_DATE_MINUTE 24
|
||||||
|
|
||||||
#define ELITE_DEVICE_NAME_LIST \
|
#define ELITE_DEVICE_NAME_LIST \
|
||||||
{ \
|
{ \
|
||||||
"EIS", "EDC" \
|
"EIS", "EDC" \
|
||||||
@@ -5,6 +5,8 @@ extern "C"
|
|||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "sdk_config.h"
|
||||||
|
|
||||||
#include "ble_advdata.h"
|
#include "ble_advdata.h"
|
||||||
|
|
||||||
#include "nrf_ble_gatt.h"
|
#include "nrf_ble_gatt.h"
|
||||||
@@ -175,7 +177,7 @@ static void on_ins_connect(ins_connect_t *p_ins)
|
|||||||
static void on_ins_write_char(ins_write_char_t *p_ins)
|
static void on_ins_write_char(ins_write_char_t *p_ins)
|
||||||
{
|
{
|
||||||
uint16_t write_size = p_ins->len - sizeof(p_ins->handle) - 1;
|
uint16_t write_size = p_ins->len - sizeof(p_ins->handle) - 1;
|
||||||
NRF_LOG_INFO("write handle: 0x%02X", p_ins->handle);
|
NRF_LOG_INFO("[BLE] write_char(W) handle 0x%02X data to peripheral:", p_ins->handle);
|
||||||
{
|
{
|
||||||
uint8_t *p_start = (void *)p_ins->write_data;
|
uint8_t *p_start = (void *)p_ins->write_data;
|
||||||
uint32_t loop = write_size / 8;
|
uint32_t loop = write_size / 8;
|
||||||
@@ -191,18 +193,35 @@ static void on_ins_write_char(ins_write_char_t *p_ins)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extern ret_code_t le_gatt_c_write_req(uint32_t handle, void *, uint16_t);
|
if (p_ins->handle == 0x0024 ||
|
||||||
ret_code_t err_code = le_gatt_c_write_req(p_ins->handle, p_ins->write_data, write_size);
|
p_ins->handle == 0x0028)
|
||||||
APP_ERROR_CHECK(err_code);
|
{
|
||||||
|
extern ret_code_t le_gatt_c_write_req(uint32_t handle, void *, uint16_t);
|
||||||
|
ret_code_t err_code = le_gatt_c_write_req(p_ins->handle, p_ins->write_data, write_size);
|
||||||
|
APP_ERROR_CHECK(err_code);
|
||||||
|
|
||||||
success_ack();
|
success_ack();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (p_ins->handle == 0x0030)
|
||||||
|
{
|
||||||
|
uint32_t set_baud = *(uint32_t *)p_ins->write_data;
|
||||||
|
extern ret_code_t le_uart_baudrate_set(uint32_t baudrate);
|
||||||
|
ret_code_t err_code = le_uart_baudrate_set(set_baud);
|
||||||
|
APP_ERROR_CHECK(err_code);
|
||||||
|
|
||||||
|
success_ack();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void on_ins_read_char(ins_read_char_t *p_ins)
|
static void on_ins_read_char(ins_read_char_t *p_ins)
|
||||||
{
|
{
|
||||||
NRF_LOG_INFO("read handle: 0x%02X", p_ins->handle);
|
NRF_LOG_INFO("[BLE] read_char(R) handle 0x%02X data from peripheral:", p_ins->handle);
|
||||||
extern ret_code_t le_gatt_c_read_char_req(uint32_t handle);
|
if (p_ins->handle == 0x0021)
|
||||||
ret_code_t ret_code = le_gatt_c_read_char_req(p_ins->handle);
|
{
|
||||||
|
extern ret_code_t le_gatt_c_read_char_req(uint32_t handle);
|
||||||
|
ret_code_t ret_code = le_gatt_c_read_char_req(p_ins->handle);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void on_ins_disconnect(ins_disconnect_t *p_ins)
|
static void on_ins_disconnect(ins_disconnect_t *p_ins)
|
||||||
@@ -261,6 +280,7 @@ typedef struct
|
|||||||
} __PACKED data;
|
} __PACKED data;
|
||||||
} manu_spec_data_t;
|
} manu_spec_data_t;
|
||||||
|
|
||||||
|
static uint16_t scan_times = 0;
|
||||||
void host_scan_filter_match_cb(
|
void host_scan_filter_match_cb(
|
||||||
void *p_manu_spec_data,
|
void *p_manu_spec_data,
|
||||||
uint32_t manu_spec_data_len,
|
uint32_t manu_spec_data_len,
|
||||||
@@ -301,6 +321,12 @@ void host_scan_filter_match_cb(
|
|||||||
host_scan_rsp.dev_name,
|
host_scan_rsp.dev_name,
|
||||||
peer_addr_str,
|
peer_addr_str,
|
||||||
rssi);
|
rssi);
|
||||||
|
scan_times++;
|
||||||
|
if (scan_times >= 10)
|
||||||
|
{
|
||||||
|
extern void le_scan_stop(void);
|
||||||
|
le_scan_stop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void host_connected_cb(void)
|
void host_connected_cb(void)
|
||||||
@@ -320,28 +346,53 @@ static void host_cmd_exec_task(void *p_arg)
|
|||||||
|
|
||||||
size_t recv = xMessageBufferReceive(host_cmd_msg, buf, sizeof(buf), portMAX_DELAY);
|
size_t recv = xMessageBufferReceive(host_cmd_msg, buf, sizeof(buf), portMAX_DELAY);
|
||||||
|
|
||||||
switch (p_ins->raw.opcode)
|
extern bool le_gap_is_connected(void);
|
||||||
|
if (le_gap_is_connected())
|
||||||
{
|
{
|
||||||
case INS_SCAN:
|
switch (p_ins->raw.opcode)
|
||||||
on_ins_scan(&p_ins->scan);
|
{
|
||||||
break;
|
case INS_WRITE_CHAR:
|
||||||
case INS_CONNECT:
|
NRF_LOG_INFO("[INS_WRITE_CHAR]");
|
||||||
on_ins_connect(&p_ins->connect);
|
on_ins_write_char(&p_ins->write_char);
|
||||||
break;
|
break;
|
||||||
case INS_WRITE_CHAR:
|
case INS_READ_CHAR:
|
||||||
on_ins_write_char(&p_ins->write_char);
|
NRF_LOG_INFO("[INS_READ_CHAR]");
|
||||||
break;
|
on_ins_read_char(&p_ins->read_char);
|
||||||
case INS_READ_CHAR:
|
break;
|
||||||
on_ins_read_char(&p_ins->read_char);
|
case INS_DISCONNECT:
|
||||||
break;
|
NRF_LOG_INFO("[INS_DISCONNECT]");
|
||||||
case INS_DISCONNECT:
|
on_ins_disconnect(&p_ins->disconnect);
|
||||||
on_ins_disconnect(&p_ins->disconnect);
|
break;
|
||||||
break;
|
case INS_CHECK_SURVIVE:
|
||||||
case INS_CHECK_SURVIVE:
|
NRF_LOG_INFO("[INS_CHECK_SURVIVE]");
|
||||||
on_ins_survive(&p_ins->survive);
|
on_ins_survive(&p_ins->survive);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
NRF_LOG_INFO("unsupported INS");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
switch (p_ins->raw.opcode)
|
||||||
|
{
|
||||||
|
case INS_SCAN:
|
||||||
|
NRF_LOG_INFO("[INS_SCAN]");
|
||||||
|
on_ins_scan(&p_ins->scan);
|
||||||
|
scan_times = 0;
|
||||||
|
break;
|
||||||
|
case INS_CONNECT:
|
||||||
|
NRF_LOG_INFO("[INS_CONNECT]");
|
||||||
|
on_ins_connect(&p_ins->connect);
|
||||||
|
break;
|
||||||
|
case INS_CHECK_SURVIVE:
|
||||||
|
NRF_LOG_INFO("[INS_CHECK_SURVIVE]");
|
||||||
|
on_ins_survive(&p_ins->survive);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
NRF_LOG_INFO("unsupported INS");
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,6 +4,8 @@ extern "C"
|
|||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "sdk_config.h"
|
||||||
|
|
||||||
#include "ble_db_discovery.h"
|
#include "ble_db_discovery.h"
|
||||||
#include "nrf_ble_gatt.h"
|
#include "nrf_ble_gatt.h"
|
||||||
#include "nrf_ble_gq.h"
|
#include "nrf_ble_gq.h"
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#include "sdk_config.h"
|
||||||
|
|
||||||
#include "ble_dis_c.h"
|
#include "ble_dis_c.h"
|
||||||
|
|
||||||
#include "ble_gattc.h"
|
#include "ble_gattc.h"
|
||||||
@@ -7,7 +7,8 @@ extern "C"
|
|||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "app_config.h"
|
#include "sdk_config.h"
|
||||||
|
|
||||||
#include "apply_old_config.h"
|
#include "apply_old_config.h"
|
||||||
#include "sdk_config.h"
|
#include "sdk_config.h"
|
||||||
|
|
||||||
@@ -4,6 +4,8 @@ extern "C"
|
|||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "sdk_config.h"
|
||||||
|
|
||||||
#include "nrf_ble_gq.h"
|
#include "nrf_ble_gq.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
@@ -3,6 +3,7 @@ extern "C"
|
|||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "app_config.h"
|
||||||
#include "ble_db_discovery.h"
|
#include "ble_db_discovery.h"
|
||||||
#include "ble_gattc.h"
|
#include "ble_gattc.h"
|
||||||
#include "ble_srv_common.h"
|
#include "ble_srv_common.h"
|
||||||
@@ -62,13 +63,13 @@ static void on_hvx(ble_gatt_c_t *p_ble_gatt_c, ble_evt_t const *p_ble_evt)
|
|||||||
ble_gattc_evt_hvx_t *hvx = (void *)&p_ble_evt->evt.gattc_evt.params.hvx;
|
ble_gattc_evt_hvx_t *hvx = (void *)&p_ble_evt->evt.gattc_evt.params.hvx;
|
||||||
uint32_t len = hvx->len;
|
uint32_t len = hvx->len;
|
||||||
uint8_t *p = (uint8_t *)hvx->data;
|
uint8_t *p = (uint8_t *)hvx->data;
|
||||||
extern void mem_notify_cb(uint8_t * p, uint32_t len);
|
extern void mem_notify_cb(uint8_t *p, uint32_t len);
|
||||||
mem_notify_cb(p, len);
|
mem_notify_cb(p, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void on_read_rsp(ble_gatt_c_t *p_le_gatt_c, ble_evt_t const *p_ble_evt)
|
static void on_read_rsp(ble_gatt_c_t *p_le_gatt_c, ble_evt_t const *p_ble_evt)
|
||||||
{
|
{
|
||||||
extern void host_read_char_cb(uint8_t * p_data, uint16_t len);
|
extern void host_read_char_cb(uint8_t *p_data, uint16_t len);
|
||||||
uint16_t handle = p_ble_evt->evt.gattc_evt.params.read_rsp.handle;
|
uint16_t handle = p_ble_evt->evt.gattc_evt.params.read_rsp.handle;
|
||||||
|
|
||||||
for (int i = 0; i < COUNTOF(p_le_gatt_c->char_handles); i++)
|
for (int i = 0; i < COUNTOF(p_le_gatt_c->char_handles); i++)
|
||||||
@@ -96,9 +97,9 @@ ret_code_t le_gatt_ccdc_configure(uint16_t conn_handle, uint16_t char_handle, bo
|
|||||||
return NRF_ERROR_INVALID_PARAM;
|
return NRF_ERROR_INVALID_PARAM;
|
||||||
}
|
}
|
||||||
|
|
||||||
NRF_LOG_INFO("Configuring CCCD Handle = 0x%04X, Connection Handle = 0x%04X",
|
NRF_LOG_INFO("Set CCCD(0x%04X) on Connection(0x%04X)",
|
||||||
char_handle + 1,
|
char_handle + 1,
|
||||||
conn_handle);
|
notification_enable);
|
||||||
|
|
||||||
nrf_ble_gq_req_t cccd_req;
|
nrf_ble_gq_req_t cccd_req;
|
||||||
uint16_t cccd_val = notification_enable ? BLE_GATT_HVX_NOTIFICATION : BLE_GATT_HVX_INVALID;
|
uint16_t cccd_val = notification_enable ? BLE_GATT_HVX_NOTIFICATION : BLE_GATT_HVX_INVALID;
|
||||||
@@ -224,7 +225,7 @@ void le_gatt_c_cccd_timer_cb(TimerHandle_t xTimer)
|
|||||||
{
|
{
|
||||||
le_gatt_ccdc_configure(m_gatt_c.conn_handle, m_gatt_c.char_handles[i], true);
|
le_gatt_ccdc_configure(m_gatt_c.conn_handle, m_gatt_c.char_handles[i], true);
|
||||||
}
|
}
|
||||||
NRF_LOG_INFO("Enable notifications. ");
|
NRF_LOG_INFO("Enable EVENT notifications. ");
|
||||||
}
|
}
|
||||||
|
|
||||||
static TimerHandle_t le_gatt_c_cccd_timer = NULL;
|
static TimerHandle_t le_gatt_c_cccd_timer = NULL;
|
||||||
@@ -6,6 +6,7 @@ extern "C"
|
|||||||
#include "ble_db_discovery.h"
|
#include "ble_db_discovery.h"
|
||||||
#include "ble_gattc.h"
|
#include "ble_gattc.h"
|
||||||
#include "ble_srv_common.h"
|
#include "ble_srv_common.h"
|
||||||
|
#include "sdk_config.h"
|
||||||
|
|
||||||
#include "nrf_ble_gq.h"
|
#include "nrf_ble_gq.h"
|
||||||
|
|
||||||
@@ -101,9 +102,9 @@ ret_code_t le_uart_ccdc_configure(uint16_t conn_handle, uint16_t char_handle, bo
|
|||||||
return NRF_ERROR_INVALID_PARAM;
|
return NRF_ERROR_INVALID_PARAM;
|
||||||
}
|
}
|
||||||
|
|
||||||
NRF_LOG_INFO("Configuring CCCD Handle = 0x%04X, Connection Handle = 0x%04X",
|
NRF_LOG_INFO("Set CCCD(0x%04X) on Connection(0x%04X)",
|
||||||
char_handle + 1,
|
char_handle + 1,
|
||||||
conn_handle);
|
notification_enable);
|
||||||
|
|
||||||
nrf_ble_gq_req_t cccd_req;
|
nrf_ble_gq_req_t cccd_req;
|
||||||
uint16_t cccd_val = notification_enable ? BLE_GATT_HVX_NOTIFICATION : BLE_GATT_HVX_INVALID;
|
uint16_t cccd_val = notification_enable ? BLE_GATT_HVX_NOTIFICATION : BLE_GATT_HVX_INVALID;
|
||||||
@@ -412,7 +413,7 @@ static void ble_uart_echo(void *p_arg)
|
|||||||
|
|
||||||
uint32_t get_baud = 1000000;
|
uint32_t get_baud = 1000000;
|
||||||
uint32_t set_baud = 115200;
|
uint32_t set_baud = 115200;
|
||||||
extern ret_code_t le_uart_baudrate_get(uint32_t * baudrate);
|
extern ret_code_t le_uart_baudrate_get(uint32_t *baudrate);
|
||||||
le_uart_baudrate_get(&get_baud);
|
le_uart_baudrate_get(&get_baud);
|
||||||
NRF_LOG_INFO("Get Baud rate: %d", get_baud);
|
NRF_LOG_INFO("Get Baud rate: %d", get_baud);
|
||||||
|
|
||||||
@@ -460,7 +461,7 @@ void le_uart_c_init(void)
|
|||||||
|
|
||||||
m_le_uart_c.le_uart_c_cccd_timer = xTimerCreate("Timer", pdMS_TO_TICKS(1000), pdTRUE, (void *)1, le_uart_c_cccd_timer_cb);
|
m_le_uart_c.le_uart_c_cccd_timer = xTimerCreate("Timer", pdMS_TO_TICKS(1000), pdTRUE, (void *)1, le_uart_c_cccd_timer_cb);
|
||||||
|
|
||||||
#if 1
|
#if 0
|
||||||
xTaskCreate(ble_uart_echo, "ble uart echo", 2048, NULL, 3, NULL);
|
xTaskCreate(ble_uart_echo, "ble uart echo", 2048, NULL, 3, NULL);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
+13
-1
@@ -121,7 +121,7 @@ static void initialize(void *p_context)
|
|||||||
|
|
||||||
extern void le_uart_c_init(void);
|
extern void le_uart_c_init(void);
|
||||||
le_uart_c_init();
|
le_uart_c_init();
|
||||||
|
|
||||||
extern void le_gap_init(void);
|
extern void le_gap_init(void);
|
||||||
le_gap_init();
|
le_gap_init();
|
||||||
|
|
||||||
@@ -140,6 +140,18 @@ int main(void)
|
|||||||
NRF_LOG_INIT(xTaskGetTickCount, configTICK_RATE_HZ);
|
NRF_LOG_INIT(xTaskGetTickCount, configTICK_RATE_HZ);
|
||||||
NRF_LOG_DEFAULT_BACKENDS_INIT();
|
NRF_LOG_DEFAULT_BACKENDS_INIT();
|
||||||
NRF_LOG_INFO("%s Build: %s %s", LE_DEVICE_NAME, __TIME__, __DATE__);
|
NRF_LOG_INFO("%s Build: %s %s", LE_DEVICE_NAME, __TIME__, __DATE__);
|
||||||
|
NRF_LOG_INFO("[Board] HW ver: %d.%d.%d.%d(%s)",
|
||||||
|
MAJOR_PRODUCT_NUMBER,
|
||||||
|
MINOR_PRODUCT_NUMBER,
|
||||||
|
MAJOR_VERSION_NUMBER,
|
||||||
|
MINOR_VERSION_NUMBER,
|
||||||
|
LE_DEVICE_NAME);
|
||||||
|
NRF_LOG_INFO("[Board] FW ver: %02d%02d%02d %02d:%02d",
|
||||||
|
VERSION_DATE_YEAR,
|
||||||
|
VERSION_DATE_MONTH,
|
||||||
|
VERSION_DATE_DAY,
|
||||||
|
VERSION_DATE_HOUR,
|
||||||
|
VERSION_DATE_MINUTE);
|
||||||
|
|
||||||
le_stack_Init();
|
le_stack_Init();
|
||||||
|
|
||||||
@@ -62,7 +62,7 @@ typedef struct
|
|||||||
} __PACKED;
|
} __PACKED;
|
||||||
} header[3];
|
} header[3];
|
||||||
} green_frame;
|
} green_frame;
|
||||||
uint8_t red_frame[2048];
|
uint8_t red_frame[8180]; // 8192-12
|
||||||
} mem_data_t;
|
} mem_data_t;
|
||||||
mem_data_t mem_data;
|
mem_data_t mem_data;
|
||||||
uint32_t mem_notify_cnt = 0;
|
uint32_t mem_notify_cnt = 0;
|
||||||
@@ -168,7 +168,7 @@ static void mem_drv_task(void *p_arg)
|
|||||||
NRF_LOG_HEXDUMP_INFO(&p[(total_size / 32) * 32], total_size % 32);
|
NRF_LOG_HEXDUMP_INFO(&p[(total_size / 32) * 32], total_size % 32);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
NRF_LOG_INFO("Write: %4d bytes, and switch sram done!!!", total_size);
|
NRF_LOG_INFO("Write: %4d bytes, and switch sram done!!!\n", total_size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,7 +187,7 @@ void mem_notify_cb(uint8_t *p, uint32_t len)
|
|||||||
uint8_t prefix;
|
uint8_t prefix;
|
||||||
uint8_t cnt;
|
uint8_t cnt;
|
||||||
uint8_t len;
|
uint8_t len;
|
||||||
uint8_t content[64];
|
uint8_t content[256];
|
||||||
} swap_buf;
|
} swap_buf;
|
||||||
|
|
||||||
swap_buf.prefix = 0xFF;
|
swap_buf.prefix = 0xFF;
|
||||||
@@ -209,7 +209,7 @@ void mem_notify_cb(uint8_t *p, uint32_t len)
|
|||||||
sum += swap_buf.prefix;
|
sum += swap_buf.prefix;
|
||||||
sum += swap_buf.cnt;
|
sum += swap_buf.cnt;
|
||||||
sum += swap_buf.len;
|
sum += swap_buf.len;
|
||||||
swap_buf.content[len + 5] = sum & 0xFF;
|
swap_buf.content[len + 5] = sum & 0xFF;
|
||||||
|
|
||||||
taskENTER_CRITICAL();
|
taskENTER_CRITICAL();
|
||||||
xStreamBufferSend(mem_drv_stream, &swap_buf, 3 + len + 6, 0);
|
xStreamBufferSend(mem_drv_stream, &swap_buf, 3 + len + 6, 0);
|
||||||
@@ -243,7 +243,7 @@ void mem_board_init(void)
|
|||||||
|
|
||||||
// Create Semphr & Task
|
// Create Semphr & Task
|
||||||
mem_sel_semphr = xSemaphoreCreateBinary();
|
mem_sel_semphr = xSemaphoreCreateBinary();
|
||||||
mem_drv_stream = xStreamBufferCreate(4096, 1);
|
mem_drv_stream = xStreamBufferCreate(8180, 1); // 8192-12=8180
|
||||||
xTaskCreate(mem_drv_task, "mem_drv", 256, NULL, 5, NULL);
|
xTaskCreate(mem_drv_task, "mem_drv", 256, NULL, 5, NULL);
|
||||||
|
|
||||||
sd_nvic_SetPriority(GPIOTE_IRQn, _PRIO_APP_MID);
|
sd_nvic_SetPriority(GPIOTE_IRQn, _PRIO_APP_MID);
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
|
#include "app_config.h"
|
||||||
|
|
||||||
#include "nrf_gpio.h"
|
#include "nrf_gpio.h"
|
||||||
#include "nrf_spim.h"
|
#include "nrf_spim.h"
|
||||||
@@ -24,6 +24,8 @@ extern "C"
|
|||||||
#define HOST_UART_DRV_TX_PIN NRF_GPIO_PIN_MAP(0, 4)
|
#define HOST_UART_DRV_TX_PIN NRF_GPIO_PIN_MAP(0, 4)
|
||||||
#define HOST_UART_DRV_RX_PIN NRF_GPIO_PIN_MAP(0, 27)
|
#define HOST_UART_DRV_RX_PIN NRF_GPIO_PIN_MAP(0, 27)
|
||||||
|
|
||||||
|
#define PRINT_UART_DATA 0
|
||||||
|
|
||||||
static SemaphoreHandle_t uart_drv_tx_sem;
|
static SemaphoreHandle_t uart_drv_tx_sem;
|
||||||
static SemaphoreHandle_t uart_drv_rx_sem;
|
static SemaphoreHandle_t uart_drv_rx_sem;
|
||||||
static SemaphoreHandle_t uart_drv_tx_mutex;
|
static SemaphoreHandle_t uart_drv_tx_mutex;
|
||||||
@@ -48,6 +50,11 @@ uint32_t uart_drv_rx(void *p_data, uint16_t len)
|
|||||||
nrf_uarte_task_trigger(HOST_UART, NRF_UARTE_TASK_STOPRX);
|
nrf_uarte_task_trigger(HOST_UART, NRF_UARTE_TASK_STOPRX);
|
||||||
xSemaphoreTake(uart_drv_rx_sem, portMAX_DELAY);
|
xSemaphoreTake(uart_drv_rx_sem, portMAX_DELAY);
|
||||||
uint32_t recv_bytes = nrf_uarte_rx_amount_get(HOST_UART);
|
uint32_t recv_bytes = nrf_uarte_rx_amount_get(HOST_UART);
|
||||||
|
if (PRINT_UART_DATA)
|
||||||
|
{
|
||||||
|
NRF_LOG_INFO("UART_BT_Rx:");
|
||||||
|
NRF_LOG_HEXDUMP_INFO(p_data, recv_bytes);
|
||||||
|
}
|
||||||
xSemaphoreGive(uart_drv_rx_mutex);
|
xSemaphoreGive(uart_drv_rx_mutex);
|
||||||
return recv_bytes;
|
return recv_bytes;
|
||||||
}
|
}
|
||||||
@@ -64,6 +71,12 @@ void uart_drv_tx(void *p_data, uint16_t len)
|
|||||||
nrf_uarte_task_trigger(HOST_UART, NRF_UARTE_TASK_STARTTX);
|
nrf_uarte_task_trigger(HOST_UART, NRF_UARTE_TASK_STARTTX);
|
||||||
xSemaphoreTake(uart_drv_tx_sem, portMAX_DELAY);
|
xSemaphoreTake(uart_drv_tx_sem, portMAX_DELAY);
|
||||||
xSemaphoreGive(uart_drv_tx_mutex);
|
xSemaphoreGive(uart_drv_tx_mutex);
|
||||||
|
if (PRINT_UART_DATA)
|
||||||
|
{
|
||||||
|
NRF_LOG_INFO("UART_BT_Tx:");
|
||||||
|
NRF_LOG_HEXDUMP_INFO(p_data, len);
|
||||||
|
NRF_LOG_INFO("\t");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void uart_drv_init(void)
|
void uart_drv_init(void)
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"folders": [
|
||||||
|
{
|
||||||
|
"path": "."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "../bmd380_sdk"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"settings": {}
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
# Call Cmake from the 'build' subfolder with the command below.
|
||||||
|
# For using Make:
|
||||||
|
# cmake -DCMAKE_MAKE_PROGRAM=make.exe -DCMAKE_TOOLCHAIN_FILE="arm-none-eabi-gcc.cmake" -G "Unix Makefiles" ..
|
||||||
|
# followed by
|
||||||
|
# 'make' or 'cmake --build .' to build it
|
||||||
|
#
|
||||||
|
# For using Ninja:
|
||||||
|
# cmake -DCMAKE_MAKE_PROGRAM=ninja.exe -DCMAKE_TOOLCHAIN_FILE="arm-none-eabi-gcc.cmake" -G "Ninja" ..
|
||||||
|
# followed by
|
||||||
|
# 'ninja' or 'cmake --build .' to build it
|
||||||
|
|
||||||
|
set(CMAKE_SYSTEM_NAME Generic)
|
||||||
|
set(CMAKE_SYSTEM_PROCESSOR arm)
|
||||||
|
|
||||||
|
if(CMAKE_HOST_WIN32)
|
||||||
|
set(EXECUTESUFFIX ".exe")
|
||||||
|
set(ARM_TOOLCHAIN_DIR "C:/SysGCC/arm-eabi/bin")
|
||||||
|
elseif(CMAKE_HOST_UNIX)
|
||||||
|
set(EXECUTESUFFIX "")
|
||||||
|
if(${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Darwin")
|
||||||
|
message(STATUS "Running on macOS")
|
||||||
|
set(ARM_TOOLCHAIN_DIR "/opt/homebrew/bin")
|
||||||
|
elseif(${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Linux")
|
||||||
|
message(STATUS "Running on Linux (likely Ubuntu)")
|
||||||
|
set(ARM_TOOLCHAIN_DIR "/opt/arm-none-eabi/bin")
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
message(WARNING "Unknown host OS: ${CMAKE_HOST_SYSTEM_NAME}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(BINUTILS_PATH ${ARM_TOOLCHAIN_DIR})
|
||||||
|
|
||||||
|
set(TOOLCHAIN_PREFIX arm-none-eabi-)
|
||||||
|
|
||||||
|
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
|
||||||
|
|
||||||
|
set(CMAKE_C_COMPILER ${ARM_TOOLCHAIN_DIR}/${TOOLCHAIN_PREFIX}gcc${EXECUTESUFFIX})
|
||||||
|
set(CMAKE_ASM_COMPILER ${CMAKE_C_COMPILER})
|
||||||
|
set(CMAKE_CXX_COMPILER ${ARM_TOOLCHAIN_DIR}/${TOOLCHAIN_PREFIX}g++${EXECUTESUFFIX})
|
||||||
|
set(CMAKE_LINKER ${ARM_TOOLCHAIN_DIR}/${TOOLCHAIN_PREFIX}ld${EXECUTESUFFIX})
|
||||||
|
set(CMAKE_OBJCOPY ${ARM_TOOLCHAIN_DIR}/${TOOLCHAIN_PREFIX}objcopy${EXECUTESUFFIX} CACHE INTERNAL "objcopy tool")
|
||||||
|
set(CMAKE_SIZE ${ARM_TOOLCHAIN_DIR}/${TOOLCHAIN_PREFIX}size${EXECUTESUFFIX} CACHE INTERNAL "size tool")
|
||||||
|
|
||||||
|
set(CMAKE_FIND_ROOT_PATH ${BINUTILS_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)
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.15.3)
|
||||||
|
|
||||||
|
file(GLOB FREERTO_KERNEL_SOURCES "${NRF_SDK_DIR}/external/freertos/source/*.c")
|
||||||
|
|
||||||
|
add_library(freertos OBJECT
|
||||||
|
${NRF_SDK_DIR}/external/freertos/portable/GCC/nrf52/port.c
|
||||||
|
${NRF_SDK_DIR}/external/freertos/portable/CMSIS/nrf52/port_cmsis.c
|
||||||
|
${NRF_SDK_DIR}/external/freertos/portable/CMSIS/nrf52/port_cmsis_systick.c
|
||||||
|
${NRF_SDK_DIR}/external/freertos/source/portable/MemMang/heap_4.c
|
||||||
|
${FREERTO_KERNEL_SOURCES}
|
||||||
|
)
|
||||||
|
|
||||||
|
target_include_directories(freertos PUBLIC
|
||||||
|
${NRF_SDK_DIR}/external/freertos/portable/CMSIS/nrf52
|
||||||
|
${NRF_SDK_DIR}/external/freertos/portable/GCC/nrf52
|
||||||
|
${NRF_SDK_DIR}/external/freertos/source/include
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(freertos PRIVATE
|
||||||
|
prj_config
|
||||||
|
)
|
||||||
@@ -1,21 +1,15 @@
|
|||||||
/* Linker script for nRF52811_XXAA */
|
/* Linker script for nRF52840_XXAA */
|
||||||
|
|
||||||
GROUP(S140_softdevice.o)
|
GROUP(S140_softdevice.o)
|
||||||
MEMORY
|
MEMORY
|
||||||
{
|
{
|
||||||
FLASH_SOFTDEVICE (rx) : ORIGIN = 0x00000000, LENGTH = 0x00027000
|
FLASH_SOFTDEVICE (rx) : ORIGIN = 0x00000000, LENGTH = 0x00027000
|
||||||
FLASH (rx) : ORIGIN = 0x00027000, LENGTH = 0x000d9000
|
FLASH (rx) : ORIGIN = 0x00027000, LENGTH = 0x000d9000
|
||||||
|
EXTFLASH (rx) : ORIGIN = 0x12000000, LENGTH = 0x8000000
|
||||||
RAM_SOFTDEVICE (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00010000
|
RAM_SOFTDEVICE (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00010000
|
||||||
RAM (rwx) : ORIGIN = 0x20010000, LENGTH = 0x0002F000
|
RAM (rwx) : ORIGIN = 0x20010000, LENGTH = 0x0002F000
|
||||||
RTT (rwx) : ORIGIN = 0x2003F000, LENGTH = 0x00001000
|
RTT (rwx) : ORIGIN = 0x2003F000, LENGTH = 0x00001000
|
||||||
CODE_RAM (rwx) : ORIGIN = 0x800000, LENGTH = 0x6000
|
CODE_RAM (rwx) : ORIGIN = 0x800000, LENGTH = 0x40000
|
||||||
}
|
|
||||||
|
|
||||||
SECTIONS
|
|
||||||
{
|
|
||||||
.segger_rtt (NOLOAD) :
|
|
||||||
{
|
|
||||||
} > RTT
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTIONS
|
SECTIONS
|
||||||
@@ -23,14 +17,12 @@ SECTIONS
|
|||||||
.softdevice :
|
.softdevice :
|
||||||
{
|
{
|
||||||
KEEP(*(.softdevice))
|
KEEP(*(.softdevice))
|
||||||
FILL(0xFFFFFFFF);
|
|
||||||
. = 0x00027000;
|
|
||||||
} > FLASH_SOFTDEVICE
|
} > FLASH_SOFTDEVICE
|
||||||
|
|
||||||
.softdevice_sram :
|
.softdevice_sram :
|
||||||
{
|
{
|
||||||
FILL(0xFFFFFFFF);
|
FILL(0xFFFFFFFF);
|
||||||
. = 0x000079e0;
|
. = 0x00010000;
|
||||||
} > RAM_SOFTDEVICE
|
} > RAM_SOFTDEVICE
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,128 @@
|
|||||||
|
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
|
||||||
|
.pwr_mgmt_data :
|
||||||
|
{
|
||||||
|
PROVIDE(__start_pwr_mgmt_data = .);
|
||||||
|
KEEP(*(SORT(.pwr_mgmt_data*)))
|
||||||
|
PROVIDE(__stop_pwr_mgmt_data = .);
|
||||||
|
} > 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
|
||||||
|
.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
|
||||||
|
|
||||||
|
} INSERT AFTER .text
|
||||||
|
|
||||||
|
|
||||||
|
INCLUDE "nrf_common.ld"
|
||||||
|
|
||||||
|
PROVIDE(_sbss = __bss_start__);
|
||||||
|
PROVIDE(_ebss = __bss_end__);
|
||||||
|
PROVIDE(_sdata = __data_start__);
|
||||||
|
PROVIDE(_sidata = __etext);
|
||||||
|
PROVIDE(_estack = __StackTop);
|
||||||
|
PROVIDE(_edata = __data_end__);
|
||||||
|
PROVIDE(__isr_vector = __StackTop);
|
||||||
|
PROVIDE(_etext = __etext);
|
||||||
+97
-39
@@ -1,34 +1,42 @@
|
|||||||
import serial
|
import serial
|
||||||
import os
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
|
||||||
def survive_cmd(ser):
|
def survive_cmd(ser):
|
||||||
send = [0x0A, 0x01, 0xF1]
|
send = [0x0A, 0x01, 0xF1]
|
||||||
|
ser.reset_input_buffer()
|
||||||
ser.write(send)
|
ser.write(send)
|
||||||
read = ser.read(4)
|
read = ser.read(4)
|
||||||
print("recv: " + " ".join("%02X" % b for b in read))
|
print("survive_cmd")
|
||||||
|
print("UART_BT_Tx:\t" + " ".join("%02X" % b for b in send))
|
||||||
|
print("UART_BT_Rx:\t" + " ".join("%02X" % b for b in read) + "\n")
|
||||||
|
|
||||||
|
|
||||||
def scan_cmd(ser, is_raw_data=True):
|
def scan_cmd(ser, is_raw_data=True):
|
||||||
send = [0x03, 0x01, 0xF1]
|
|
||||||
ser.write(send)
|
|
||||||
peer_addr = []
|
peer_addr = []
|
||||||
|
send = [0x03, 0x01, 0xF1]
|
||||||
|
ser.reset_input_buffer()
|
||||||
|
ser.write(send)
|
||||||
|
print("scan_cmd")
|
||||||
|
print("UART_BT_Tx:\t" + " ".join("%02X" % b for b in send))
|
||||||
|
|
||||||
for i in range(10):
|
for i in range(10):
|
||||||
hci_packet_event = ser.read(2)
|
hci_packet_event = ser.read(2)
|
||||||
if int.from_bytes(hci_packet_event, "little") != 0x0004:
|
if int.from_bytes(hci_packet_event, "little") != 0x0004:
|
||||||
continue
|
continue
|
||||||
len = ser.read(1)
|
len = ser.read(1)
|
||||||
payload = ser.read(int.from_bytes(len, "little"))
|
payload = ser.read(int.from_bytes(len, "little"))
|
||||||
|
|
||||||
peer_addr = payload[0:6]
|
peer_addr = payload[0:6]
|
||||||
|
|
||||||
if is_raw_data:
|
if is_raw_data:
|
||||||
print(
|
print(
|
||||||
"recv: "
|
"UART_BT_Rx:\t"
|
||||||
+ " ".join("0x%02X" % b for b in hci_packet_event)
|
+ " ".join("%02X" % b for b in hci_packet_event)
|
||||||
+ " "
|
+ " "
|
||||||
+ " ".join("0x%02X" % b for b in len)
|
+ " ".join("%02X" % b for b in len)
|
||||||
+ " "
|
+ " "
|
||||||
+ " ".join("0x%02X" % b for b in payload)
|
+ " ".join("%02X" % b for b in payload)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
print("-" * 100)
|
print("-" * 100)
|
||||||
@@ -43,76 +51,126 @@ def scan_cmd(ser, is_raw_data=True):
|
|||||||
+ "V"
|
+ "V"
|
||||||
)
|
)
|
||||||
print(" device name: " + str(payload[21:], "utf-8"))
|
print(" device name: " + str(payload[21:], "utf-8"))
|
||||||
|
print("\n")
|
||||||
return peer_addr
|
return peer_addr
|
||||||
|
|
||||||
|
|
||||||
def connect(ser, peer_addr=[]):
|
def connect(ser, peer_addr=[]):
|
||||||
|
DISCONNECT_RSPONSE = [0x04, 0x00, 0x01, 0xFF]
|
||||||
|
CONNECTED_RSPONSE = [0x04, 0x00, 0x01, 0x03]
|
||||||
|
|
||||||
send = [0x05, 0x08, 0x00]
|
send = [0x05, 0x08, 0x00]
|
||||||
send += peer_addr
|
send += peer_addr
|
||||||
send += [0xF1]
|
send += [0xF1]
|
||||||
|
ser.reset_input_buffer()
|
||||||
ser.write(send)
|
ser.write(send)
|
||||||
read = ser.read(4)
|
read = ser.read(4)
|
||||||
print("recv: " + " ".join("%02X" % b for b in read))
|
print("connect " + ":".join(f"{b:02X}" for b in peer_addr))
|
||||||
|
print("UART_BT_Tx:\t" + " ".join("%02X" % b for b in send))
|
||||||
|
print("UART_BT_Rx:\t" + " ".join("%02X" % b for b in read) + "\n")
|
||||||
|
|
||||||
|
if list(read) == DISCONNECT_RSPONSE:
|
||||||
|
return False
|
||||||
|
elif list(read) == CONNECTED_RSPONSE:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def disconnect(ser):
|
def disconnect(ser):
|
||||||
send = [0x08, 0x01, 0xF1]
|
send = [0x08, 0x01, 0xF1]
|
||||||
|
ser.reset_input_buffer()
|
||||||
ser.write(send)
|
ser.write(send)
|
||||||
read = ser.read(4)
|
read = ser.read(4)
|
||||||
print("recv: " + " ".join("%02X" % b for b in read))
|
print("disconnect")
|
||||||
|
print("UART_BT_Tx:\t" + " ".join("%02X" % b for b in send))
|
||||||
|
print("UART_BT_Rx:\t" + " ".join("%02X" % b for b in read) + "\n")
|
||||||
|
|
||||||
|
|
||||||
def write_char(ser: serial.Serial, handle: int, write_data: tuple):
|
def write_char(ser: serial.Serial, handle: int, write_data: tuple):
|
||||||
send = [0x06, len(write_data)+2, handle]
|
send = [0x06, len(write_data) + 2, handle]
|
||||||
send += write_data
|
send += write_data
|
||||||
send += [0xF1]
|
send += [0xF1]
|
||||||
|
ser.reset_input_buffer()
|
||||||
ser.write(send)
|
ser.write(send)
|
||||||
|
read = ser.read(4)
|
||||||
|
print("write_char")
|
||||||
|
print("UART_BT_Tx:\t" + " ".join("%02X" % b for b in send))
|
||||||
|
print("UART_BT_Rx\t" + " ".join("%02X" % b for b in read) + "\n")
|
||||||
|
|
||||||
|
|
||||||
def read_char(ser: serial.Serial, handle: int):
|
def read_char(ser: serial.Serial, handle: int):
|
||||||
send = [0x07, 0x02, handle, 0xF1]
|
send = [0x07, 0x02, handle, 0xF1]
|
||||||
|
ser.reset_input_buffer()
|
||||||
ser.write(send)
|
ser.write(send)
|
||||||
read = ser.read(0xFFFF)
|
read = ser.read(0xFFFF)
|
||||||
print("recv: " + " ".join("%02X" % b for b in read))
|
print("read_char")
|
||||||
|
print("UART_BT_Tx:\t" + " ".join("%02X" % b for b in send))
|
||||||
|
print("UART_BT_Rx\t" + " ".join("%02X" % b for b in read) + "\n")
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
# set comport
|
ser = serial.Serial("COM14", 115200, 8, inter_byte_timeout=0.01)
|
||||||
ser = serial.Serial("COM15", 57600, 8, inter_byte_timeout=0.01)
|
|
||||||
|
|
||||||
# send survive cmd
|
|
||||||
survive_cmd(ser)
|
survive_cmd(ser)
|
||||||
|
|
||||||
# send scan cmd
|
peer_addr = scan_cmd(ser, True)
|
||||||
peer_addr = scan_cmd(ser, False)
|
|
||||||
time.sleep(10)
|
# want_connected_addr = bytes.fromhex("C0 38 14 75 AD A9")
|
||||||
return
|
want_connected_addr = bytes.fromhex("C8 DC F1 3B 07 74")
|
||||||
# send connect cmd with peer addr
|
peer_addr = want_connected_addr
|
||||||
connect(ser, peer_addr)
|
connect_success = connect(ser, peer_addr)
|
||||||
time.sleep(3)
|
time.sleep(1)
|
||||||
|
|
||||||
# send write char to enable notify
|
if connect_success == False:
|
||||||
write_char(ser, 0x0024, [0xc4,0xf0,0xf1,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00])
|
print("connect fail, exit python code")
|
||||||
|
ser.close()
|
||||||
|
return
|
||||||
|
|
||||||
|
# read version
|
||||||
|
write_char(ser, 0x0024, [0x74, 0x40])
|
||||||
|
read_char(ser, 0x0021)
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
write_char(ser, 0x0024, [0x74,0x10,0xf1,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00])
|
|
||||||
time.sleep(0.1)
|
|
||||||
read_char(ser, 0x0021)
|
|
||||||
# 130500040000000000000000000000000000001c
|
|
||||||
time.sleep(0.2)
|
|
||||||
# send write char to enable notify
|
|
||||||
#write_char(ser, 0x0028, 1)
|
|
||||||
#time.sleep(5)
|
|
||||||
|
|
||||||
# send write char to disable notify
|
# -----------------------------------------------------
|
||||||
#write_char(ser, 0x0028, 0)
|
# run auto scan mode
|
||||||
|
# -----------------------------------------------------
|
||||||
|
PEL_RUN_AUTO_SCAN_MODE = False
|
||||||
|
if PEL_RUN_AUTO_SCAN_MODE:
|
||||||
|
|
||||||
# send read char to disable notify
|
# event_notify:enable
|
||||||
#read_char(ser, 0x0027)
|
write_char(ser, 0x0028, [0x01, 0x00])
|
||||||
|
time.sleep(0.1)
|
||||||
|
|
||||||
|
# PELv3.0 start auto_scan_mode
|
||||||
|
write_char(
|
||||||
|
ser,
|
||||||
|
0x0024,
|
||||||
|
[0x35, 0x00, 0x02, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x05, 0x00, 0x0A],
|
||||||
|
)
|
||||||
|
|
||||||
|
print("---------- notify data ----------")
|
||||||
|
time.sleep(0.5)
|
||||||
|
print("--------------------------------")
|
||||||
|
|
||||||
|
# PELv3.0 stop auto_scan_mode
|
||||||
|
write_char(ser, 0x0024, [0x30, 0x00, 0x02, 0x00])
|
||||||
|
time.sleep(0.1)
|
||||||
|
|
||||||
|
# event_notify:disable
|
||||||
|
write_char(ser, 0x0028, [0x00, 0x00])
|
||||||
|
time.sleep(0.1)
|
||||||
|
|
||||||
|
# auto scan mode completed
|
||||||
|
# -----------------------------------------------------
|
||||||
|
|
||||||
# send disconnect cmd
|
|
||||||
disconnect(ser)
|
disconnect(ser)
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
ser.close()
|
ser.close()
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user