diff --git a/.buildpackrc b/.buildpackrc index 5a4992eed1..3f4cd11124 100644 --- a/.buildpackrc +++ b/.buildpackrc @@ -15,10 +15,10 @@ export BUILDPACK_VARIATION=manifest export RELEASE_PLATFORMS=( ) # Platforms for which this firmware is considered experimental -export PRERELEASE_PLATFORMS=( argon boron bsom b5som tracker esomx p2 ) +export PRERELEASE_PLATFORMS=( argon boron bsom b5som tracker esomx p2 trackerm ) # Note: a single platform should be only in release or prerelease list. If # added to both it will be considered a prerelease # Platforms which require modules to be prebuilt -export MODULAR_PLATFORMS=( argon boron bsom b5som tracker esomx p2 ) +export MODULAR_PLATFORMS=( argon boron bsom b5som tracker esomx p2 trackerm ) diff --git a/.circleci/config.yml b/.circleci/config.yml index 25148658f0..29c7c64388 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -14,7 +14,7 @@ orbs: aliases: - &tasks ["compile:all clean:all", "compile:user clean:user", "compile:debug clean:debug"] - - &platforms ["argon", "boron", "esomx", "bsom", "b5som", "tracker", "p2"] + - &platforms ["argon", "boron", "esomx", "bsom", "b5som", "tracker", "p2", "trackerm"] # Define a job to be invoked later in a workflow. # See: https://circleci.com/docs/2.0/configuration-reference/#jobs @@ -475,7 +475,7 @@ workflows: - particle-ci-private matrix: parameters: - platform: ["argon", "boron", "esomx", "bsom", "b5som", "tracker", "p2", "unit-test newhal gcc"] + platform: ["argon", "boron", "esomx", "bsom", "b5som", "tracker", "p2", "trackerm", "unit-test newhal gcc"] - combine-binaries: requires: - build-and-test diff --git a/.workbench/manifest.json b/.workbench/manifest.json index 97d7754bcf..8a8a064adb 100644 --- a/.workbench/manifest.json +++ b/.workbench/manifest.json @@ -2,7 +2,7 @@ "version": "1.0.0", "toolchains": [ { - "platforms": [12, 13, 15, 23, 25, 26, 32], + "platforms": [12, 13, 15, 23, 25, 26, 28, 32], "firmware": "deviceOS@source", "compilers": "gcc-arm@10.2.1", "tools": "buildtools@1.1.1", diff --git a/bootloader/makefile b/bootloader/makefile index 6fb0631326..90ba7aa7a7 100644 --- a/bootloader/makefile +++ b/bootloader/makefile @@ -3,7 +3,7 @@ BOOTLOADER_MODULE_PATH=. PLATFORM_DFU=0x8000000 BUILD_PATH_EXT = $(BOOTLOADER_BUILD_PATH_EXT) -ifeq ("$(PLATFORM)","p2") +ifeq ($(PLATFORM_MCU),rtl872x) RTL_BINARY_FLASH_START = 0x4000 endif diff --git a/bootloader/prebootloader/makefile b/bootloader/prebootloader/makefile index c0e49b35bb..c6f9b05bfa 100644 --- a/bootloader/prebootloader/makefile +++ b/bootloader/prebootloader/makefile @@ -10,7 +10,7 @@ include $(PROJECT_ROOT)/build/macros.mk include $(PROJECT_ROOT)/build/module-defaults.mk include $(PROJECT_ROOT)/build/arm-tools.mk -projects = $(sort $(wildcard $(current_dir)/src/$(PLATFORM_DYNALIB_MODULES)/*)) +projects = $(sort $(wildcard $(current_dir)/src/$(PLATFORM_MCU)/*)) makefiles = $(foreach module,$(projects),$(and $(strip $(subst $(MODULE_EXCLUDE),,$(notdir $(module)))),$(wildcard $(module)/makefile))) SUBDIR_GOALS := $(MAKECMDGOALS) diff --git a/bootloader/prebootloader/src/tron/mbr/bootloader_update.c b/bootloader/prebootloader/src/rtl872x/mbr/bootloader_update.c similarity index 100% rename from bootloader/prebootloader/src/tron/mbr/bootloader_update.c rename to bootloader/prebootloader/src/rtl872x/mbr/bootloader_update.c diff --git a/bootloader/prebootloader/src/tron/mbr/bootloader_update.h b/bootloader/prebootloader/src/rtl872x/mbr/bootloader_update.h similarity index 100% rename from bootloader/prebootloader/src/tron/mbr/bootloader_update.h rename to bootloader/prebootloader/src/rtl872x/mbr/bootloader_update.h diff --git a/bootloader/prebootloader/src/tron/mbr/build.mk b/bootloader/prebootloader/src/rtl872x/mbr/build.mk similarity index 100% rename from bootloader/prebootloader/src/tron/mbr/build.mk rename to bootloader/prebootloader/src/rtl872x/mbr/build.mk diff --git a/bootloader/prebootloader/src/tron/mbr/cxx_constructors.cpp b/bootloader/prebootloader/src/rtl872x/mbr/cxx_constructors.cpp similarity index 100% rename from bootloader/prebootloader/src/tron/mbr/cxx_constructors.cpp rename to bootloader/prebootloader/src/rtl872x/mbr/cxx_constructors.cpp diff --git a/bootloader/prebootloader/src/tron/mbr/import.mk b/bootloader/prebootloader/src/rtl872x/mbr/import.mk similarity index 100% rename from bootloader/prebootloader/src/tron/mbr/import.mk rename to bootloader/prebootloader/src/rtl872x/mbr/import.mk diff --git a/bootloader/prebootloader/src/tron/mbr/include.mk b/bootloader/prebootloader/src/rtl872x/mbr/include.mk similarity index 100% rename from bootloader/prebootloader/src/tron/mbr/include.mk rename to bootloader/prebootloader/src/rtl872x/mbr/include.mk diff --git a/bootloader/prebootloader/src/tron/mbr/linker.ld b/bootloader/prebootloader/src/rtl872x/mbr/linker.ld similarity index 100% rename from bootloader/prebootloader/src/tron/mbr/linker.ld rename to bootloader/prebootloader/src/rtl872x/mbr/linker.ld diff --git a/bootloader/prebootloader/src/tron/mbr/main.cpp b/bootloader/prebootloader/src/rtl872x/mbr/main.cpp similarity index 100% rename from bootloader/prebootloader/src/tron/mbr/main.cpp rename to bootloader/prebootloader/src/rtl872x/mbr/main.cpp diff --git a/bootloader/prebootloader/src/tron/mbr/makefile b/bootloader/prebootloader/src/rtl872x/mbr/makefile similarity index 100% rename from bootloader/prebootloader/src/tron/mbr/makefile rename to bootloader/prebootloader/src/rtl872x/mbr/makefile diff --git a/bootloader/prebootloader/src/tron/mbr/module_info.c b/bootloader/prebootloader/src/rtl872x/mbr/module_info.c similarity index 100% rename from bootloader/prebootloader/src/tron/mbr/module_info.c rename to bootloader/prebootloader/src/rtl872x/mbr/module_info.c diff --git a/bootloader/prebootloader/src/tron/mbr/part1_import.c b/bootloader/prebootloader/src/rtl872x/mbr/part1_import.c similarity index 100% rename from bootloader/prebootloader/src/tron/mbr/part1_import.c rename to bootloader/prebootloader/src/rtl872x/mbr/part1_import.c diff --git a/bootloader/prebootloader/src/tron/mbr/part1_preinit_import.c b/bootloader/prebootloader/src/rtl872x/mbr/part1_preinit_import.c similarity index 100% rename from bootloader/prebootloader/src/tron/mbr/part1_preinit_import.c rename to bootloader/prebootloader/src/rtl872x/mbr/part1_preinit_import.c diff --git a/bootloader/prebootloader/src/tron/mbr/rtl_header.cpp b/bootloader/prebootloader/src/rtl872x/mbr/rtl_header.cpp similarity index 100% rename from bootloader/prebootloader/src/tron/mbr/rtl_header.cpp rename to bootloader/prebootloader/src/rtl872x/mbr/rtl_header.cpp diff --git a/bootloader/prebootloader/src/tron/mbr/rtl_it.c b/bootloader/prebootloader/src/rtl872x/mbr/rtl_it.c similarity index 100% rename from bootloader/prebootloader/src/tron/mbr/rtl_it.c rename to bootloader/prebootloader/src/rtl872x/mbr/rtl_it.c diff --git a/bootloader/prebootloader/src/tron/mbr/rtl_it.h b/bootloader/prebootloader/src/rtl872x/mbr/rtl_it.h similarity index 100% rename from bootloader/prebootloader/src/tron/mbr/rtl_it.h rename to bootloader/prebootloader/src/rtl872x/mbr/rtl_it.h diff --git a/bootloader/prebootloader/src/tron/mbr/sources.mk b/bootloader/prebootloader/src/rtl872x/mbr/sources.mk similarity index 100% rename from bootloader/prebootloader/src/tron/mbr/sources.mk rename to bootloader/prebootloader/src/rtl872x/mbr/sources.mk diff --git a/bootloader/prebootloader/src/tron/mbr/tlm.mk b/bootloader/prebootloader/src/rtl872x/mbr/tlm.mk similarity index 100% rename from bootloader/prebootloader/src/tron/mbr/tlm.mk rename to bootloader/prebootloader/src/rtl872x/mbr/tlm.mk diff --git a/bootloader/prebootloader/src/tron/part1/build.mk b/bootloader/prebootloader/src/rtl872x/part1/build.mk similarity index 100% rename from bootloader/prebootloader/src/tron/part1/build.mk rename to bootloader/prebootloader/src/rtl872x/part1/build.mk diff --git a/bootloader/prebootloader/src/tron/part1/cxx_constructors.cpp b/bootloader/prebootloader/src/rtl872x/part1/cxx_constructors.cpp similarity index 100% rename from bootloader/prebootloader/src/tron/part1/cxx_constructors.cpp rename to bootloader/prebootloader/src/rtl872x/part1/cxx_constructors.cpp diff --git a/bootloader/prebootloader/src/tron/part1/import.mk b/bootloader/prebootloader/src/rtl872x/part1/import.mk similarity index 100% rename from bootloader/prebootloader/src/tron/part1/import.mk rename to bootloader/prebootloader/src/rtl872x/part1/import.mk diff --git a/bootloader/prebootloader/src/tron/part1/include.mk b/bootloader/prebootloader/src/rtl872x/part1/include.mk similarity index 100% rename from bootloader/prebootloader/src/tron/part1/include.mk rename to bootloader/prebootloader/src/rtl872x/part1/include.mk diff --git a/bootloader/prebootloader/src/tron/part1/ipc.c b/bootloader/prebootloader/src/rtl872x/part1/ipc.c similarity index 100% rename from bootloader/prebootloader/src/tron/part1/ipc.c rename to bootloader/prebootloader/src/rtl872x/part1/ipc.c diff --git a/bootloader/prebootloader/src/tron/part1/linker.ld b/bootloader/prebootloader/src/rtl872x/part1/linker.ld similarity index 100% rename from bootloader/prebootloader/src/tron/part1/linker.ld rename to bootloader/prebootloader/src/rtl872x/part1/linker.ld diff --git a/bootloader/prebootloader/src/tron/part1/makefile b/bootloader/prebootloader/src/rtl872x/part1/makefile similarity index 100% rename from bootloader/prebootloader/src/tron/part1/makefile rename to bootloader/prebootloader/src/rtl872x/part1/makefile diff --git a/bootloader/prebootloader/src/tron/part1/module_info.c b/bootloader/prebootloader/src/rtl872x/part1/module_info.c similarity index 100% rename from bootloader/prebootloader/src/tron/part1/module_info.c rename to bootloader/prebootloader/src/rtl872x/part1/module_info.c diff --git a/bootloader/prebootloader/src/tron/part1/part1_export.c b/bootloader/prebootloader/src/rtl872x/part1/part1_export.c similarity index 100% rename from bootloader/prebootloader/src/tron/part1/part1_export.c rename to bootloader/prebootloader/src/rtl872x/part1/part1_export.c diff --git a/bootloader/prebootloader/src/tron/part1/rtl_support.c b/bootloader/prebootloader/src/rtl872x/part1/rtl_support.c similarity index 100% rename from bootloader/prebootloader/src/tron/part1/rtl_support.c rename to bootloader/prebootloader/src/rtl872x/part1/rtl_support.c diff --git a/bootloader/prebootloader/src/tron/part1/rtl_support.h b/bootloader/prebootloader/src/rtl872x/part1/rtl_support.h similarity index 100% rename from bootloader/prebootloader/src/tron/part1/rtl_support.h rename to bootloader/prebootloader/src/rtl872x/part1/rtl_support.h diff --git a/bootloader/prebootloader/src/tron/part1/sleep_handler.cpp b/bootloader/prebootloader/src/rtl872x/part1/sleep_handler.cpp similarity index 100% rename from bootloader/prebootloader/src/tron/part1/sleep_handler.cpp rename to bootloader/prebootloader/src/rtl872x/part1/sleep_handler.cpp diff --git a/bootloader/prebootloader/src/tron/part1/sleep_handler.h b/bootloader/prebootloader/src/rtl872x/part1/sleep_handler.h similarity index 100% rename from bootloader/prebootloader/src/tron/part1/sleep_handler.h rename to bootloader/prebootloader/src/rtl872x/part1/sleep_handler.h diff --git a/bootloader/prebootloader/src/tron/part1/sources.mk b/bootloader/prebootloader/src/rtl872x/part1/sources.mk similarity index 91% rename from bootloader/prebootloader/src/tron/part1/sources.mk rename to bootloader/prebootloader/src/rtl872x/part1/sources.mk index d0839c3719..fc02d68a2e 100644 --- a/bootloader/prebootloader/src/tron/part1/sources.mk +++ b/bootloader/prebootloader/src/rtl872x/part1/sources.mk @@ -11,7 +11,8 @@ CSRC += $(PROJECT_ROOT)/hal/src/rtl872x/hal_irq_flag.c CPPSRC += $(PROJECT_ROOT)/hal/src/rtl872x/flash_common.cpp CPPSRC += $(PROJECT_ROOT)/hal/src/rtl872x/km0_km4_ipc.cpp CPPSRC += $(PROJECT_ROOT)/hal/src/rtl872x/pinmap_hal.cpp -CPPSRC += $(PROJECT_ROOT)/hal/src/tron/pinmap_defines.cpp + +CPPSRC += $(PROJECT_ROOT)/hal/src/$(PLATFORM_NAME)/pinmap_defines.cpp LDFLAGS += -T$(PREBOOTLOADER_PART1_SRC_PATH)/linker.ld LINKER_DEPS += $(PREBOOTLOADER_PART1_SRC_PATH)/linker.ld diff --git a/bootloader/prebootloader/src/tron/part1/tlm.mk b/bootloader/prebootloader/src/rtl872x/part1/tlm.mk similarity index 100% rename from bootloader/prebootloader/src/tron/part1/tlm.mk rename to bootloader/prebootloader/src/rtl872x/part1/tlm.mk diff --git a/bootloader/prebootloader/src/tron/part1/update_handler.c b/bootloader/prebootloader/src/rtl872x/part1/update_handler.c similarity index 100% rename from bootloader/prebootloader/src/tron/part1/update_handler.c rename to bootloader/prebootloader/src/rtl872x/part1/update_handler.c diff --git a/bootloader/prebootloader/src/tron/part1/update_handler.h b/bootloader/prebootloader/src/rtl872x/part1/update_handler.h similarity index 100% rename from bootloader/prebootloader/src/tron/part1/update_handler.h rename to bootloader/prebootloader/src/rtl872x/part1/update_handler.h diff --git a/bootloader/prebootloader/src/tron/shared/bootloader_part1_export.ld b/bootloader/prebootloader/src/rtl872x/shared/bootloader_part1_export.ld similarity index 100% rename from bootloader/prebootloader/src/tron/shared/bootloader_part1_export.ld rename to bootloader/prebootloader/src/rtl872x/shared/bootloader_part1_export.ld diff --git a/bootloader/prebootloader/src/tron/shared/crc32_nolookup.c b/bootloader/prebootloader/src/rtl872x/shared/crc32_nolookup.c similarity index 100% rename from bootloader/prebootloader/src/tron/shared/crc32_nolookup.c rename to bootloader/prebootloader/src/rtl872x/shared/crc32_nolookup.c diff --git a/bootloader/prebootloader/src/tron/shared/include.mk b/bootloader/prebootloader/src/rtl872x/shared/include.mk similarity index 100% rename from bootloader/prebootloader/src/tron/shared/include.mk rename to bootloader/prebootloader/src/rtl872x/shared/include.mk diff --git a/bootloader/prebootloader/src/tron/shared/part1_dynalib.h b/bootloader/prebootloader/src/rtl872x/shared/part1_dynalib.h similarity index 100% rename from bootloader/prebootloader/src/tron/shared/part1_dynalib.h rename to bootloader/prebootloader/src/rtl872x/shared/part1_dynalib.h diff --git a/bootloader/prebootloader/src/tron/shared/part1_preinit_dynalib.h b/bootloader/prebootloader/src/rtl872x/shared/part1_preinit_dynalib.h similarity index 100% rename from bootloader/prebootloader/src/tron/shared/part1_preinit_dynalib.h rename to bootloader/prebootloader/src/rtl872x/shared/part1_preinit_dynalib.h diff --git a/bootloader/src/main.c b/bootloader/src/main.c index 582e7f30ff..e4332c1611 100644 --- a/bootloader/src/main.c +++ b/bootloader/src/main.c @@ -32,7 +32,7 @@ #include "button_hal.h" #include "dct.h" #include "feature_flags.h" -#if PLATFORM_ID == PLATFORM_P2 +#if HAL_PLATFORM_RTL872X #include "rtl8721d.h" #include "nonsecure.h" #endif @@ -48,7 +48,7 @@ extern void HAL_DFU_Process(); void platform_startup(); -#if PLATFORM_ID == PLATFORM_P2 +#if HAL_PLATFORM_RTL872X static void jump_to_system(uint32_t addr, uint32_t sp) { nonsecure_jump_to_system(addr); (void) sp; diff --git a/bootloader/src/trackerm/include.mk b/bootloader/src/trackerm/include.mk new file mode 100644 index 0000000000..5a86395fbb --- /dev/null +++ b/bootloader/src/trackerm/include.mk @@ -0,0 +1,2 @@ +INCLUDE_DIRS += $(BOOTLOADER_MODULE_PATH)/src/$(PLATFORM_NAME) +include $(BOOTLOADER_MODULE_PATH)/src/rtl872x/include.mk diff --git a/bootloader/src/trackerm/sources.mk b/bootloader/src/trackerm/sources.mk new file mode 100644 index 0000000000..bb5433032a --- /dev/null +++ b/bootloader/src/trackerm/sources.mk @@ -0,0 +1,2 @@ +BOOTLOADER_SRC_PATH = $(BOOTLOADER_MODULE_PATH)/src/${PLATFORM_NAME} +include $(BOOTLOADER_MODULE_PATH)/src/rtl872x/sources.mk \ No newline at end of file diff --git a/build/create_module.py b/build/create_module.py index 0ac4677b2b..e3a80ab361 100644 --- a/build/create_module.py +++ b/build/create_module.py @@ -49,6 +49,7 @@ class Platform(IntEnum): BSOM = 23 B5SOM = 25 TRACKER = 26 + TRACKERM = 28 P2 = 32 class StructSerializable(struct.Struct): @@ -243,7 +244,7 @@ def parse_dependency(dep): GEN3_RADIO_STACK_DEPENDENCY = ModuleDependency(ModuleFunction.BOOTLOADER, 501) GEN3_RADIO_STACK_DEPENDENCY2 = ModuleDependency(ModuleFunction.SYSTEM_PART, 1321, 1) -RTL_PLATFORMS = [Platform.P2] +RTL_PLATFORMS = [Platform.P2, Platform.TRACKERM] RTL_MBR_OFFSET = 0x08000000 RTL_KM0_PART1_OFFSET = 0x08014000 diff --git a/build/make_release.sh b/build/make_release.sh index c3378aa32b..8644ba7586 100755 --- a/build/make_release.sh +++ b/build/make_release.sh @@ -131,7 +131,7 @@ function valid_platform() # Validate platform (result of expression returned to caller) [ "$platform" = "all" ] || [ "$platform" = "argon" ] || [ "$platform" = "asom" ] || \ [ "$platform" = "boron" ] || [ "$platform" = "bsom" ] || [ "$platform" = "b5som" ] || \ - [ "$platform" = "esomx" ] || [ "$platform" = "tracker" ] || [ "$platform" = "p2" ] + [ "$platform" = "esomx" ] || [ "$platform" = "tracker" ] || [ "$platform" = "p2" ] || [ "$platform" = "trackerm" ] } if !(valid_platform $PLATFORM); then @@ -155,6 +155,7 @@ if [ $PLATFORM = "all" ]; then release_platform "tracker" release_platform "esomx" release_platform "p2" + release_platform "trackerm" else release_platform "$PLATFORM" fi diff --git a/build/module.mk b/build/module.mk index 057e4cf383..7725e9dbc7 100644 --- a/build/module.mk +++ b/build/module.mk @@ -102,7 +102,7 @@ exe: $(TARGET_BASE)$(EXECUTABLE_EXTENSION) none: ; -ifeq ("$(PLATFORM)","p2") +ifeq ($(PLATFORM_MCU),rtl872x) .PHONY: rtl-flash rtl_module_start_address = $(subst 0x08,0x00,$(call get_module_start_address)) rtl-flash: diff --git a/build/platform-id.mk b/build/platform-id.mk index 503ab6967b..9c0e388b93 100644 --- a/build/platform-id.mk +++ b/build/platform-id.mk @@ -53,6 +53,10 @@ ifeq ("$(PLATFORM)","tracker") PLATFORM_ID=26 endif +ifeq ("$(PLATFORM)","trackerm") +PLATFORM_ID=28 +endif + ifeq ("$(PLATFORM)","p2") PLATFORM_ID=32 endif @@ -214,6 +218,32 @@ PLATFORM_THREADING=1 PLATFORM_OPENTHREAD=nrf52840 endif +ifeq ("$(PLATFORM_ID)","28") +PLATFORM=trackerm +PLATFORM_NAME=trackerm +PLATFORM_GEN=3 +PLATFORM_MCU=rtl872x +PLATFORM_NET=rtl872x +PLATFORM_WIZNET=W5500 +PRODUCT_DESC=Production TrackerM +USBD_VID_PARTICLE=0x2B04 +USBD_PID_DFU=0xD01C +USBD_PID_CDC=0xC01C +DEFAULT_PRODUCT_ID=$(PLATFORM_ID) +PLATFORM_DYNALIB_MODULES=trackerm +PLATFORM_PREBOOTLOADER=1 +ifneq ("$(PLATFORM_MCU_CORE)","") +ARM_CPU=cortex-$(PLATFORM_MCU_CORE) +MCU_DEVICE=rtl872x_$(PLATFORM_MCU_CORE) +else +ARM_CPU=cortex-m33 +MCU_DEVICE=rtl872x +endif +PLATFORM_THREADING=1 +MODULE_SUFFIX_PRODUCT_DATA_OFFSET_FROM_END=42 +BOOTLOADER_USE_LTO=n +endif + ifeq ("$(PLATFORM_ID)","32") PLATFORM=p2 PLATFORM_NAME=tron @@ -268,8 +298,6 @@ ifeq ("$(MCU_DEVICE)","rtl872x") PLATFORM_THREADING=1 endif - - ifeq ("$(PLATFORM_MCU)","") $(error PLATFORM_MCU not defined. Check platform id $(PLATFORM_ID)) endif diff --git a/build/release-publish.sh b/build/release-publish.sh index 190713249b..5045364265 100755 --- a/build/release-publish.sh +++ b/build/release-publish.sh @@ -94,7 +94,7 @@ function valid_platform() # Validate platform (result of expression returned to caller) [ "$platform" = "argon" ] || [ "$platform" = "asom" ] || [ "$platform" = "boron" ] || \ [ "$platform" = "bsom" ] || [ "$platform" = "b5som" ] || [ "$platform" = "tracker" ] || \ - [ "$platform" = "esomx" ] || [ "$platform" = "p2" ] + [ "$platform" = "esomx" ] || [ "$platform" = "p2" ] || [ "$platform" = "trackerm" ] } # Identify the absolute directory diff --git a/build/release-tests.sh b/build/release-tests.sh index e7b4bf4517..494bfd7a9c 100755 --- a/build/release-tests.sh +++ b/build/release-tests.sh @@ -109,7 +109,7 @@ function valid_platform () # Validate platform (result of expression returned to caller) [ "$platform" = "argon" ] || [ "$platform" = "asom" ] || [ "$platform" = "boron" ] || \ [ "$platform" = "bsom" ] || [ "$platform" = "b5som" ] || [ "$platform" = "tracker" ] || \ - [ "$platform" = "esomx" ] || [ "$platform" = "p2" ] + [ "$platform" = "esomx" ] || [ "$platform" = "p2" ] || [ "$platform" = "trackerm" ] } # Handle invalid arguments @@ -153,6 +153,9 @@ case "$PLATFORM" in "tracker") PLATFORM_ID="26" ;; + "trackerm") + PLATFORM_ID="28" + ;; "p2") PLATFORM_ID="32" ;; diff --git a/build/release.sh b/build/release.sh index 7967cd33a4..f8d0e54106 100755 --- a/build/release.sh +++ b/build/release.sh @@ -238,6 +238,10 @@ elif [ ! -z $PLATFORM ]; then PLATFORM_ID="26" GEN3=true ;; + "trackerm") + PLATFORM_ID="28" + GEN3=true + ;; "p2") PLATFORM_ID="32" GEN3=true @@ -277,6 +281,10 @@ else PLATFORM="tracker" GEN3=true ;; + 28) + PLATFORM="trackerm" + GEN3=true + ;; 32) PLATFORM="p2" GEN3=true @@ -321,7 +329,7 @@ rm -rf $ABSOLUTE_TARGET_DIRECTORY/ ######################### # GEN3 -if [ $PLATFORM_ID -eq 12 ] || [ $PLATFORM_ID -eq 13 ] || [ $PLATFORM_ID -eq 15 ] || [ $PLATFORM_ID -eq 22 ] || [ $PLATFORM_ID -eq 23 ] || [ $PLATFORM_ID -eq 25 ] || [ $PLATFORM_ID -eq 26 ] || [ $PLATFORM_ID -eq 32 ]; then +if [ $PLATFORM_ID -eq 12 ] || [ $PLATFORM_ID -eq 13 ] || [ $PLATFORM_ID -eq 15 ] || [ $PLATFORM_ID -eq 22 ] || [ $PLATFORM_ID -eq 23 ] || [ $PLATFORM_ID -eq 25 ] || [ $PLATFORM_ID -eq 26 ] || [ $PLATFORM_ID -eq 28 ] || [ $PLATFORM_ID -eq 32 ]; then # Configure if [ $DEBUG = true ]; then cd ../main diff --git a/ci/cf_generate_message.sh b/ci/cf_generate_message.sh index f9a75300f8..4fefd5fcf8 100755 --- a/ci/cf_generate_message.sh +++ b/ci/cf_generate_message.sh @@ -53,7 +53,7 @@ EOF ) fields="" - for p in Argon Boron BSoM B5SoM Tracker ESomX P2 GCC Newhal P2; do + for p in Argon Boron BSoM B5SoM Tracker TrackerM ESomX P2 GCC Newhal P2; do if echo -e "${failures}" | grep -q "PLATFORM=\"${p,,}\""; then msg=":scrum_closed: $p\\n" else diff --git a/ci/enumerate_build_matrix.sh b/ci/enumerate_build_matrix.sh index cee788250e..0acf1fef91 100755 --- a/ci/enumerate_build_matrix.sh +++ b/ci/enumerate_build_matrix.sh @@ -47,7 +47,7 @@ MAKE=runmake # define build matrix dimensions # "" means execute execute the $MAKE command without that var specified DEBUG_BUILD=( y n ) -PLATFORM=( argon boron asom bsom b5som esomx p2 ) +PLATFORM=( argon boron asom bsom b5som esomx p2 trackerm ) # All modules are now built by reease scripts instead, skip # Only building applications and tests here # PLATFORM_BOOTLOADER=( argon boron asom bsom b5som tracker esomx p2 ) @@ -57,7 +57,7 @@ PLATFORM_PREBOOTLOADER=() APP=( "" product_id_and_version ) TEST=( wiring/api ) -MODULAR_PLATFORM=( argon boron asom bsom b5som tracker esomx p2 ) +MODULAR_PLATFORM=( argon boron asom bsom b5som tracker esomx p2 trackerm ) filterPlatform PLATFORM filterPlatform MODULAR_PLATFORM @@ -159,7 +159,7 @@ do do # Gen 3 overflows with modular DEBUG_BUILD=y, so skip those if [[ "$db" = "y" ]]; then - if [[ "$p" = "argon" ]] || [[ "$p" = "boron" ]] || [[ "$p" = "asom" ]] || [[ "$p" = "bsom" ]] || [[ "$p" = "b5som" ]] || [[ "$p" = "tracker" ]] || [[ "$p" = "esomx" ]] || [[ "$p" = "p2" ]]; then + if [[ "$p" = "argon" ]] || [[ "$p" = "boron" ]] || [[ "$p" = "asom" ]] || [[ "$p" = "bsom" ]] || [[ "$p" = "b5som" ]] || [[ "$p" = "tracker" ]] || [[ "$p" = "esomx" ]] || [[ "$p" = "p2" ]] || [[ "$p" = "trackerm" ]]; then continue fi fi diff --git a/dynalib/inc/dynalib.h b/dynalib/inc/dynalib.h index db8052a43e..7380c9d7ad 100644 --- a/dynalib/inc/dynalib.h +++ b/dynalib/inc/dynalib.h @@ -125,7 +125,7 @@ constexpr T2* dynalib_checked_cast(T2 *p) { #define __S(x) #x #define __SX(x) __S(x) - #if PLATFORM_ID == 32 + #if PLATFORM_ID == 32 || PLATFORM_ID == 28 #define DYNALIB_FN_IMPORT(index, tablename, name, counter) \ DYNALIB_STATIC_ASSERT(index == counter, "Index of the dynamically exported function has changed"); \ const char check_name_##tablename_##name[0]={}; /* this will fail if the name is already defined */ \ diff --git a/dynalib/inc/module_info.inc b/dynalib/inc/module_info.inc index ecb4ad50d1..6310d93f8e 100644 --- a/dynalib/inc/module_info.inc +++ b/dynalib/inc/module_info.inc @@ -91,7 +91,7 @@ extern "C" { extern char link_module_start; extern char link_module_end; -#if PLATFORM_ID == 32 +#if HAL_PLATFORM_RTL872X extern uintptr_t link_dynalib_start; extern uintptr_t link_dynalib_flash_start; #endif diff --git a/hal/inc/hal_platform.h b/hal/inc/hal_platform.h index 5f07a48476..821e2dd9c0 100644 --- a/hal/inc/hal_platform.h +++ b/hal/inc/hal_platform.h @@ -36,11 +36,17 @@ #define HAL_PLATFORM_WIFI_NCP_SDIO (0) #endif // HAL_PLATFORM_WIFI_NCP_SDIO +#ifndef HAL_PLATFORM_ESP32_NCP +#define HAL_PLATFORM_ESP32_NCP (0) +#endif // HAL_PLATFORM_ESP32_NCP + +#if HAL_PLATFORM_ESP32_NCP #if HAL_PLATFORM_WIFI && HAL_PLATFORM_NCP_AT && !HAL_PLATFORM_WIFI_NCP_SDIO # ifndef HAL_PLATFORM_WIFI_SERIAL # error "HAL_PLATFORM_WIFI_SERIAL is not defined" # endif /* HAL_PLATFORM_WIFI_SERIAL */ #endif /* HAL_PLATFORM_WIFI */ +#endif /* HAL_PLATFORM_ESP32_NCP */ #ifndef HAL_PLATFORM_CELLULAR #define HAL_PLATFORM_CELLULAR 0 diff --git a/hal/src/tracker/demux.cpp b/hal/shared/demux.cpp similarity index 76% rename from hal/src/tracker/demux.cpp rename to hal/shared/demux.cpp index caad43f290..5fac3861a6 100644 --- a/hal/src/tracker/demux.cpp +++ b/hal/shared/demux.cpp @@ -20,6 +20,9 @@ #if HAL_PLATFORM_DEMUX #include "check.h" +#if HAL_PLATFORM_RTL872X +#include "gpio_hal.h" +#endif #include "system_error.h" using namespace particle; @@ -38,17 +41,33 @@ int Demux::write(uint8_t pin, uint8_t value) { DemuxLock lock(); CHECK_TRUE(pin < DEMUX_MAX_PIN_COUNT && pin != 0, SYSTEM_ERROR_INVALID_ARGUMENT); // Y0 is not available for user's usage. CHECK_TRUE(initialized_, SYSTEM_ERROR_INVALID_STATE); +#if HAL_PLATFORM_NRF52840 // We can do it in this way for now, since the control pins are continuous. uint32_t currOut = (nrf_gpio_port_out_read(DEMUX_NRF_PORT) >> DEMUX_PINS_SHIFT) & 0x00000007; if ((currOut == pin && value == 0) || (currOut != pin && value == 1)) { return SYSTEM_ERROR_NONE; } +#endif + if (value) { +#if HAL_PLATFORM_NRF52840 // Select Y0 by default, so that all other pins output high. nrf_gpio_port_out_clear(DEMUX_NRF_PORT, DEMUX_PIN_2_MASK | DEMUX_PIN_1_MASK | DEMUX_PIN_0_MASK); +#elif HAL_PLATFORM_RTL872X + // Select Y0 by default, so that all other pins output high. + hal_gpio_write(DEMUX_C, 0); + hal_gpio_write(DEMUX_B, 0); + hal_gpio_write(DEMUX_A, 0); +#endif setPinValue(0, 0); } else { +#if HAL_PLATFORM_NRF52840 nrf_gpio_port_out_set(DEMUX_NRF_PORT, ((uint32_t)pin) << DEMUX_PINS_SHIFT); +#elif HAL_PLATFORM_RTL872X + hal_gpio_write(DEMUX_C, (pin & DEMUX_PIN_2_MASK) ? 1 : 0); + hal_gpio_write(DEMUX_B, (pin & DEMUX_PIN_1_MASK) ? 1 : 0); + hal_gpio_write(DEMUX_A, (pin & DEMUX_PIN_0_MASK) ? 1 : 0); +#endif setPinValue(pin, 0); } return SYSTEM_ERROR_NONE; @@ -72,9 +91,19 @@ int Demux::unlock() { } void Demux::init() { +#if HAL_PLATFORM_NRF52840 nrf_gpio_port_dir_output_set(DEMUX_NRF_PORT, DEMUX_PIN_0_MASK | DEMUX_PIN_1_MASK | DEMUX_PIN_2_MASK); // Select Y0 by default. nrf_gpio_port_out_clear(DEMUX_NRF_PORT, DEMUX_PIN_0_MASK | DEMUX_PIN_1_MASK | DEMUX_PIN_2_MASK); +#elif HAL_PLATFORM_RTL872X + hal_gpio_mode(DEMUX_A, OUTPUT); + hal_gpio_mode(DEMUX_B, OUTPUT); + hal_gpio_mode(DEMUX_C, OUTPUT); + // Select Y0 by default. + hal_gpio_write(DEMUX_C, 0); + hal_gpio_write(DEMUX_B, 0); + hal_gpio_write(DEMUX_A, 0); +#endif initialized_ = true; } diff --git a/hal/src/tracker/demux.h b/hal/shared/demux.h similarity index 97% rename from hal/src/tracker/demux.h rename to hal/shared/demux.h index 7407d41303..5b180e93a9 100644 --- a/hal/src/tracker/demux.h +++ b/hal/shared/demux.h @@ -25,16 +25,21 @@ #include "static_recursive_mutex.h" #include "pinmap_defines.h" #include "pinmap_hal.h" +#if HAL_PLATFORM_NRF52840 #include "nrf_gpio.h" +#endif #define DEMUX_MAX_PIN_COUNT 8 +#if HAL_PLATFORM_NRF52840 #define DEMUX_NRF_PORT (NRF_P1) +#endif #define DEMUX_PIN_0_MASK 0x00000400 #define DEMUX_PIN_1_MASK 0x00000800 #define DEMUX_PIN_2_MASK 0x00001000 #define DEMUX_PINS_SHIFT (10) + namespace particle { class Demux { diff --git a/hal/src/tracker/mcp23s17.cpp b/hal/shared/mcp23s17.cpp similarity index 100% rename from hal/src/tracker/mcp23s17.cpp rename to hal/shared/mcp23s17.cpp diff --git a/hal/src/tracker/mcp23s17.h b/hal/shared/mcp23s17.h similarity index 100% rename from hal/src/tracker/mcp23s17.h rename to hal/shared/mcp23s17.h diff --git a/hal/shared/platforms.h b/hal/shared/platforms.h index 62277296ab..cc07373ec5 100644 --- a/hal/shared/platforms.h +++ b/hal/shared/platforms.h @@ -32,6 +32,7 @@ #define PLATFORM_BSOM 23 #define PLATFORM_B5SOM 25 #define PLATFORM_TRACKER 26 +#define PLATFORM_TRACKERM 28 #define PLATFORM_P2 32 #define PLATFORM_NEWHAL 60000 diff --git a/hal/src/argon/hal_platform_config.h b/hal/src/argon/hal_platform_config.h index 51827a15e6..2216fda854 100644 --- a/hal/src/argon/hal_platform_config.h +++ b/hal/src/argon/hal_platform_config.h @@ -14,6 +14,7 @@ #define HAL_PLATFORM_WIFI_COMPAT (1) #define HAL_PLATFORM_NCP_COUNT (1) #define HAL_PLATFORM_MAX_CLOUD_CONNECT_TIME (1*60*1000) +#define HAL_PLATFORM_ESP32_NCP (1) #define PRODUCT_SERIES "argon" diff --git a/hal/src/rtl872x/backup_ram_hal.cpp b/hal/src/rtl872x/backup_ram_hal.cpp index 7f3bee2e87..9bbca705d1 100644 --- a/hal/src/rtl872x/backup_ram_hal.cpp +++ b/hal/src/rtl872x/backup_ram_hal.cpp @@ -25,6 +25,7 @@ #include "platform_headers.h" #include "dct_hal.h" #include "dct.h" +#include "rtl8721d.h" // NOTE: we are using a dedicated flash page for this as timings for writing // into fs vs raw page are about 10x diff --git a/hal/src/rtl872x/deviceid_hal.cpp b/hal/src/rtl872x/deviceid_hal.cpp index 413d6cf8b1..3904e2c628 100644 --- a/hal/src/rtl872x/deviceid_hal.cpp +++ b/hal/src/rtl872x/deviceid_hal.cpp @@ -135,8 +135,8 @@ int hal_get_device_serial_number(char* str, size_t size, void* reserved) int hal_get_device_hw_version(uint32_t* revision, void* reserved) { - // HW Data format: | NCP_ID | HW_VERSION | HW Feature Flags | - // | byte 0 | byte 1 | byte 2/3 | + // HW Data format: | NCP_ID (LSB) | HW_VERSION | HW Feature Flags | + // | byte 0 | byte 1 | byte 2/3 | uint8_t hw_data[4] = {}; CHECK(readLogicalEfuse(HARDWARE_DATA_OFFSET, (uint8_t*)hw_data, HARDWARE_DATA_SIZE)); if (hw_data[1] == 0xFF) { diff --git a/hal/src/rtl872x/gpio_hal.cpp b/hal/src/rtl872x/gpio_hal.cpp index d7c5d5b815..58c594a1ea 100644 --- a/hal/src/rtl872x/gpio_hal.cpp +++ b/hal/src/rtl872x/gpio_hal.cpp @@ -26,6 +26,17 @@ extern "C" { #include "check.h" #include "hw_ticks.h" #include "timer_hal.h" +#include "module_info.h" + +#if HAL_PLATFORM_IO_EXTENSION && MODULE_FUNCTION != MOD_FUNC_BOOTLOADER +#if HAL_PLATFORM_MCP23S17 +#include "mcp23s17.h" +#endif +#if HAL_PLATFORM_DEMUX +#include "demux.h" +#endif +using namespace particle; +#endif namespace { @@ -203,12 +214,31 @@ int hal_gpio_configure(hal_pin_t pin, const hal_gpio_config_t* conf, void* reser } #if HAL_PLATFORM_MCP23S17 else if (pinInfo->type == HAL_PIN_TYPE_IO_EXPANDER) { - // TODO + CHECK_TRUE(mode == INPUT || mode == INPUT_PULLUP || mode == OUTPUT, SYSTEM_ERROR_INVALID_ARGUMENT); + + // Set pin function may reset nordic gpio configuration, should be called before the re-configuration + if (mode != PIN_MODE_NONE) { + hal_pin_set_function(pin, PF_DIO); + } else { + hal_pin_set_function(pin, PF_NONE); + } + + // Pre-set the output value if requested to avoid a glitch + if (conf->set_value && mode == OUTPUT) { + CHECK(Mcp23s17::getInstance().writePinValue(pinInfo->gpio_port, pinInfo->gpio_pin, conf->value)); + } + + CHECK(Mcp23s17::getInstance().setPinMode(pinInfo->gpio_port, pinInfo->gpio_pin, mode)); + pinInfo->pin_mode = mode; } #endif // HAL_PLATFORM_MCP23S17 #if HAL_PLATFORM_DEMUX else if (pinInfo->type == HAL_PIN_TYPE_DEMUX) { - // TODO + CHECK_TRUE(mode == OUTPUT, SYSTEM_ERROR_INVALID_ARGUMENT); + if (conf->set_value) { + Demux::getInstance().write(pinInfo->gpio_pin, conf->value); + } + pinInfo->pin_mode = mode; } #endif // HAL_PLATFORM_DEMUX else { @@ -267,12 +297,12 @@ void hal_gpio_write(hal_pin_t pin, uint8_t value) { } #if HAL_PLATFORM_MCP23S17 else if (pinInfo->type == HAL_PIN_TYPE_IO_EXPANDER) { - // TODO + Mcp23s17::getInstance().writePinValue(pinInfo->gpio_port, pinInfo->gpio_pin, value); } #endif #if HAL_PLATFORM_DEMUX else if (pinInfo->type == HAL_PIN_TYPE_DEMUX) { - // TODO + Demux::getInstance().write(pinInfo->gpio_pin, value); } #endif #endif @@ -310,14 +340,20 @@ int32_t hal_gpio_read(hal_pin_t pin) { } #if HAL_PLATFORM_MCP23S17 else if (pinInfo->type == HAL_PIN_TYPE_IO_EXPANDER) { - // TODO - return 0; + if ((pinInfo->pin_mode == INPUT) || + (pinInfo->pin_mode == INPUT_PULLUP) || + (pinInfo->pin_mode == OUTPUT)) { + uint8_t value = 0x00; + Mcp23s17::getInstance().readPinValue(pinInfo->gpio_port, pinInfo->gpio_pin, &value); + return value; + } else { + return 0; + } } #endif #if HAL_PLATFORM_DEMUX else if (pinInfo->type == HAL_PIN_TYPE_DEMUX) { - // TODO - return 0 + return Demux::getInstance().read(pinInfo->gpio_pin); } #endif else { diff --git a/hal/src/rtl872x/hal_platform_rtl8721x_config.h b/hal/src/rtl872x/hal_platform_rtl8721x_config.h index 61b2a09947..3a4f9713a9 100644 --- a/hal/src/rtl872x/hal_platform_rtl8721x_config.h +++ b/hal/src/rtl872x/hal_platform_rtl8721x_config.h @@ -38,8 +38,6 @@ #define HAL_PLATFORM_BLE_SETUP (1) -#define HAL_PLATFORM_WIFI (1) - #define HAL_PLATFORM_RTL872X (1) /* 25 seconds */ @@ -55,8 +53,6 @@ #define HAL_PLATFORM_I2C2 (1) -#define HAL_PLATFORM_USART2 (1) - #define HAL_PLATFORM_USART3 (1) #define HAL_PLATFORM_USB_VENDOR_REQUEST (1) diff --git a/hal/src/rtl872x/include.mk b/hal/src/rtl872x/include.mk index 15ff0e9e30..216b74d1a2 100644 --- a/hal/src/rtl872x/include.mk +++ b/hal/src/rtl872x/include.mk @@ -28,12 +28,12 @@ endif HAL_LINK ?= $(findstring hal,$(MAKE_DEPENDENCIES)) -HAL_DEPS = third_party/lwip third_party/freertos third_party/wiznet_driver +HAL_DEPS = third_party/lwip third_party/freertos third_party/wiznet_driver gsm0710muxer HAL_DEPS_INCLUDE_SCRIPTS =$(foreach module,$(HAL_DEPS),$(PROJECT_ROOT)/$(module)/import.mk) include $(HAL_DEPS_INCLUDE_SCRIPTS) ifneq ($(filter hal,$(LIBS)),) -HAL_LIB_DEP += $(FREERTOS_LIB_DEP) $(LWIP_LIB_DEP) $(WIZNET_DRIVER_LIB_DEP) +HAL_LIB_DEP += $(FREERTOS_LIB_DEP) $(LWIP_LIB_DEP) $(WIZNET_DRIVER_LIB_DEP) $(GSM0710MUXER_LIB_DEP) LIBS += $(notdir $(HAL_DEPS)) endif diff --git a/hal/src/rtl872x/interrupts_hal.cpp b/hal/src/rtl872x/interrupts_hal.cpp index 5da2df885a..474356c9bb 100644 --- a/hal/src/rtl872x/interrupts_hal.cpp +++ b/hal/src/rtl872x/interrupts_hal.cpp @@ -28,6 +28,7 @@ extern "C" { #include "gpio_hal.h" #include "check.h" #include "scope_guard.h" +#include "module_info.h" #if HAL_PLATFORM_IO_EXTENSION && MODULE_FUNCTION != MOD_FUNC_BOOTLOADER #if HAL_PLATFORM_MCP23S17 @@ -224,8 +225,7 @@ int hal_interrupt_attach(uint16_t pin, hal_interrupt_handler_t handler, void* da } #if HAL_PLATFORM_MCP23S17 else if (pinInfo->type == HAL_PIN_TYPE_IO_EXPANDER) { - // TODO - return SYSTEM_ERROR_NOT_SUPPORTED; + return Mcp23s17::getInstance().attachPinInterrupt(pinInfo->gpio_port, pinInfo->gpio_pin, mode, static_cast(handler), data); } #endif else { @@ -263,8 +263,7 @@ int hal_interrupt_detach_ext(uint16_t pin, uint8_t keepHandler, void* reserved) } #if HAL_PLATFORM_MCP23S17 else if (pinInfo->type == HAL_PIN_TYPE_IO_EXPANDER) { - // TODO - return SYSTEM_ERROR_NOT_SUPPORTED; + return Mcp23s17::getInstance().detachPinInterrupt(pinInfo->gpio_port, pinInfo->gpio_pin); } #endif else { diff --git a/hal/src/rtl872x/interrupts_irq.h b/hal/src/rtl872x/interrupts_irq.h index 579276881e..a638ccd6a9 100644 --- a/hal/src/rtl872x/interrupts_irq.h +++ b/hal/src/rtl872x/interrupts_irq.h @@ -25,8 +25,9 @@ extern "C" { #include "stdint.h" #ifdef USE_STDPERIPH_DRIVER -// FIXME -typedef int32_t IRQn_Type; + +#include "rtl8721d_vector_defines.h" + #if defined (ARM_CPU_CORTEX_M33) #ifdef AMEBAD_TODO #ifndef __ARMV8MML_REV diff --git a/hal/src/rtl872x/lwip/lwippppopts.h b/hal/src/rtl872x/lwip/lwippppopts.h index 88ad62a8d2..b0548789e2 100644 --- a/hal/src/rtl872x/lwip/lwippppopts.h +++ b/hal/src/rtl872x/lwip/lwippppopts.h @@ -24,7 +24,7 @@ * PPP_SUPPORT==1: Enable PPP. */ // TODO: There should probably be separate config files for each Gen 3 platform -#define PPP_SUPPORT (PLATFORM_ID == PLATFORM_BORON || PLATFORM_ID == PLATFORM_BSOM || PLATFORM_ID == PLATFORM_B5SOM || PLATFORM_ID == PLATFORM_TRACKER) +#define PPP_SUPPORT (PLATFORM_ID == PLATFORM_BORON || PLATFORM_ID == PLATFORM_BSOM || PLATFORM_ID == PLATFORM_B5SOM || PLATFORM_ID == PLATFORM_TRACKER || PLATFORM_ID == PLATFORM_P2 || PLATFORM_ID == PLATFORM_TRACKERM) /** * PPPOE_SUPPORT==1: Enable PPP Over Ethernet diff --git a/hal/src/rtl872x/platform_headers.h b/hal/src/rtl872x/platform_headers.h index 91be5e05a0..c9647b2b92 100644 --- a/hal/src/rtl872x/platform_headers.h +++ b/hal/src/rtl872x/platform_headers.h @@ -9,4 +9,9 @@ #define retained __attribute__((section(".retained_user"))) #define retained_system __attribute__((section(".retained_system"))) -#include "rtl8721d.h" +// Expose CMSIS/NVIC/IRQ/etc-related header files to the application +#include "interrupts_irq.h" +// Expose some of the peripheral registers +#include "hal_platform_rtl.h" +// GPIO/pinmux/fast-pin related stuff +#include "rtl8721d_pinmux_defines.h" diff --git a/hal/src/rtl872x/tlm.mk b/hal/src/rtl872x/tlm.mk index 505c9c72b6..6612c64a98 100644 --- a/hal/src/rtl872x/tlm.mk +++ b/hal/src/rtl872x/tlm.mk @@ -1,5 +1,5 @@ # this is included in the top-level-module makefile to provide # HAL-specific defines -DEPENDENCIES += communication newlib_nano third_party/freertos third_party/lwip third_party/wiznet_driver -MAKE_DEPENDENCIES += third_party/freertos third_party/lwip third_party/wiznet_driver +DEPENDENCIES += communication newlib_nano third_party/freertos third_party/lwip third_party/wiznet_driver gsm0710muxer +MAKE_DEPENDENCIES += third_party/freertos third_party/lwip third_party/wiznet_driver gsm0710muxer diff --git a/hal/src/rtl872x/usart_hal.cpp b/hal/src/rtl872x/usart_hal.cpp index 84811744c0..f30b67713d 100644 --- a/hal/src/rtl872x/usart_hal.cpp +++ b/hal/src/rtl872x/usart_hal.cpp @@ -191,7 +191,15 @@ class Usart { } PAD_PullCtrl(hal_pin_to_rtl_pin(txPin_), GPIO_PuPd_UP); PAD_PullCtrl(hal_pin_to_rtl_pin(rxPin_), GPIO_PuPd_UP); - + // Configure CTS/RTS pins + if (ctsPin_ != PIN_INVALID) { + Pinmux_Config(hal_pin_to_rtl_pin(ctsPin_), PINMUX_FUNCTION_UART_RTSCTS); + PAD_PullCtrl(hal_pin_to_rtl_pin(ctsPin_), GPIO_PuPd_UP); + } + if (rtsPin_ != PIN_INVALID) { + Pinmux_Config(hal_pin_to_rtl_pin(rtsPin_), PINMUX_FUNCTION_UART_RTSCTS); + PAD_PullCtrl(hal_pin_to_rtl_pin(rtsPin_), GPIO_PuPd_UP); + } UART_InitTypeDef uartInitStruct = {}; UART_StructInit(&uartInitStruct); uartInitStruct.RxFifoTrigLevel = UART_RX_FIFOTRIG_LEVEL_1BYTES; @@ -340,23 +348,22 @@ class Usart { size_t alreadyCommitted = blockSize - rxBuffer_.acquirePending(); size_t transferredToDmaFromUart = uartInstance->RX_BYTE_CNT & RUART_RX_READ_BYTE_CNTER; SPARK_ASSERT(transferredToDmaFromUart <= blockSize); - ssize_t toConsume = std::max(dmaAvailableInBuffer, transferredToDmaFromUart) - alreadyCommitted; - SPARK_ASSERT(toConsume >= 0); - if (commit && toConsume > 0) { - if (hal_interrupt_is_isr()) { - // This method is called from DMA RX ISR - toConsume = transferredToDmaFromUart - alreadyCommitted; - flushDmaRxFiFo(transferredToDmaFromUart); - } else { - toConsume = dmaAvailableInBuffer - alreadyCommitted; - // Try not suspending DMA unless necessary - if (toConsume <= 0) { - toConsume = transferredToDmaFromUart - dmaAvailableInBuffer; - if (toConsume > 0) { - flushDmaRxFiFo(transferredToDmaFromUart); - } + ssize_t toConsume = 0; + if (hal_interrupt_is_isr()) { + // This method is called from DMA RX ISR + toConsume = transferredToDmaFromUart - alreadyCommitted; + flushDmaRxFiFo(transferredToDmaFromUart); + } else { + toConsume = dmaAvailableInBuffer - alreadyCommitted; + // Try not suspending DMA unless necessary + if (toConsume <= 0) { + toConsume = transferredToDmaFromUart - dmaAvailableInBuffer; + if (toConsume > 0 && commit) { + flushDmaRxFiFo(transferredToDmaFromUart); } } + } + if (commit && toConsume > 0) { rxBuffer_.acquireCommit(toConsume); if (cancel) { // Release the rest of the buffer if any diff --git a/hal/src/tracker/hal_platform_config.h b/hal/src/tracker/hal_platform_config.h index a40cd2eef3..8b02a5c525 100644 --- a/hal/src/tracker/hal_platform_config.h +++ b/hal/src/tracker/hal_platform_config.h @@ -12,6 +12,7 @@ #define HAL_PLATFORM_I2C_NUM (3) #define HAL_PLATFORM_USART_NUM (2) #define HAL_PLATFORM_NCP_UPDATABLE (1) +#define HAL_PLATFORM_ESP32_NCP (1) #define HAL_PLATFORM_PMIC_BQ24195 (1) #define HAL_PLATFORM_PMIC_BQ24195_I2C (HAL_I2C_INTERFACE2) diff --git a/hal/src/trackerm/hal_platform_config.h b/hal/src/trackerm/hal_platform_config.h new file mode 100644 index 0000000000..24b87cdb19 --- /dev/null +++ b/hal/src/trackerm/hal_platform_config.h @@ -0,0 +1,45 @@ +#pragma once + +#include "hal_platform_rtl8721x_config.h" +#include "platforms.h" + +#define HAL_PLATFORM_NCP (1) +#define HAL_PLATFORM_NCP_AT (1) +#define HAL_PLATFORM_CELLULAR (1) +#define HAL_PLATFORM_CELLULAR_SERIAL (HAL_USART_SERIAL2) +#define HAL_PLATFORM_SETUP_BUTTON_UX (1) +// #define HAL_PLATFORM_MUXER_MAY_NEED_DELAY_IN_TX (1) +#define HAL_PLATFORM_SPI_NUM (2) +#define HAL_PLATFORM_I2C_NUM (2) +#define HAL_PLATFORM_USART_NUM (3) +#define HAL_PLATFORM_NCP_COUNT (1) +#define HAL_PLATFORM_WIFI (1) +#define HAL_PLATFORM_WIFI_COMPAT (0) +// #define HAL_PLATFORM_WIFI_NCP_SDIO (1) +#define HAL_PLATFORM_WIFI_SCAN_ONLY (1) + +#define HAL_PLATFORM_RADIO_ANTENNA_INTERNAL (1) +#define HAL_PLATFORM_RADIO_ANTENNA_EXTERNAL (1) + +#define HAL_PLATFORM_POWER_MANAGEMENT (1) +#define HAL_PLATFORM_PMIC_BQ24195 (1) +#define HAL_PLATFORM_PMIC_BQ24195_FAULT_COUNT_THRESHOLD (4) +#define HAL_PLATFORM_PMIC_INT_PIN_PRESENT (1) +#define HAL_PLATFORM_PMIC_BQ24195_I2C (HAL_I2C_INTERFACE1) +#define HAL_PLATFORM_FUELGAUGE_MAX17043 (1) +#define HAL_PLATFORM_FUELGAUGE_MAX17043_I2C (HAL_I2C_INTERFACE1) +#define HAL_PLATFORM_FLASH_MX25R6435FZNIL0 (1) + +#define HAL_PLATFORM_IO_EXTENSION (1) +#define HAL_PLATFORM_MCP23S17 (1) +#define HAL_PLATFORM_MCP23S17_SPI (HAL_SPI_INTERFACE1) +#define HAL_PLATFORM_MCP23S17_SPI_CLOCK (16000000) +#define HAL_PLATFORM_DEMUX (1) + +#if defined(MODULE_FUNCTION) && MODULE_FUNCTION != 2 // MOD_FUNC_BOOTLOADER +#define HAL_PLATFORM_USB_PRODUCT_STRING "TrackerM" +#else +#define HAL_PLATFORM_USB_PRODUCT_STRING "TrackerM DFU Mode" +#endif // defined(MODULE_FUNCTION) && MODULE_FUNCTION != 2 // MOD_FUNC_BOOTLOADER + +#define PRODUCT_SERIES "Tracker" diff --git a/hal/src/trackerm/include.mk b/hal/src/trackerm/include.mk new file mode 100644 index 0000000000..c2c03f0f08 --- /dev/null +++ b/hal/src/trackerm/include.mk @@ -0,0 +1,17 @@ + +# Define the prefix to this directory. +# Note: The name must be unique within this build and should be +# based on the root of the project + +INCLUDE_DIRS += $(TARGET_HAL_PATH)/src/$(PLATFORM_NAME) + +ifneq (,$(findstring platform,$(DEPENDENCIES))) +INCLUDE_DIRS += $(HAL_MODULE_PATH)/network/lwip/cellular +endif + +ifneq (,$(findstring platform,$(DEPENDENCIES))) +INCLUDE_DIRS += $(HAL_MODULE_PATH)/network/lwip/realtek +INCLUDE_DIRS += $(HAL_MODULE_PATH)/network/ncp/wifi +endif + +include $(TARGET_HAL_PATH)/src/rtl872x/include.mk \ No newline at end of file diff --git a/hal/src/trackerm/network/network.cpp b/hal/src/trackerm/network/network.cpp new file mode 100644 index 0000000000..ea5057b7bb --- /dev/null +++ b/hal/src/trackerm/network/network.cpp @@ -0,0 +1,248 @@ +/* + * Copyright (c) 2022 Particle Industries, Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ + +#define NO_STATIC_ASSERT +#include "ifapi.h" +#include "wiznet/wiznetif.h" +#include +#include +#include "random.h" +#include "check.h" +#include +#include "network/ncp/cellular/ncp.h" +#include "pppncpnetif.h" +#include "network/ncp_client/realtek/rtl_ncp_client.h" +#include "network/ncp_client/quectel/quectel_ncp_client.h" +#include "network/ncp/wifi/wifi_network_manager.h" +#include "network/ncp/wifi/ncp.h" +#include "debug.h" +#include "realtek/rtlncpnetif.h" +#include "lwip_util.h" +#include "core_hal.h" +#include "deviceid_hal.h" + +using namespace particle; +using namespace particle::net; + +namespace particle { + +namespace { + +/* en2 - Ethernet FeatherWing */ +BaseNetif* en2 = nullptr; +/* wl4 - Realtek NCP Station */ +BaseNetif* wl4 = nullptr; +/* wl5 - Realtek NCP Access Point */ +BaseNetif* wl5 = nullptr; +/* pp3 - Cellular */ +BaseNetif* pp3 = nullptr; + +class WifiNetworkManagerInit { +public: + WifiNetworkManagerInit() { + const int ret = init(); + SPARK_ASSERT(ret == 0); + } + + WifiNetworkManager* instance() const { + return mgr_.get(); + } + +private: + std::unique_ptr ncpClient_; + std::unique_ptr mgr_; + + int init() { + // Initialize NCP client + std::unique_ptr ncpClient(new(std::nothrow) RealtekNcpClient); + CHECK_TRUE(ncpClient, SYSTEM_ERROR_NO_MEMORY); + auto conf = NcpClientConfig() + .eventHandler(RealtekNcpNetif::ncpEventHandlerCb, wl4) + .dataHandler(RealtekNcpNetif::ncpDataHandlerCb, wl4); + CHECK(ncpClient->init(std::move(conf))); + // Initialize network manager + mgr_.reset(new(std::nothrow) WifiNetworkManager(ncpClient.get())); + CHECK_TRUE(mgr_, SYSTEM_ERROR_NO_MEMORY); + ncpClient_ = std::move(ncpClient); + return 0; + } +}; + +bool netifCanForwardIpv4(netif* iface) { + if (iface && netif_is_up(iface) && netif_is_link_up(iface)) { + auto addr = netif_ip_addr4(iface); + auto mask = netif_ip_netmask4(iface); + auto gw = netif_ip_gw4(iface); + if (!ip_addr_isany(addr) && !ip_addr_isany(mask) && !ip_addr_isany(gw)) { + return true; + } + } + + return false; +} + + +class CellularNetworkManagerInit { +public: + CellularNetworkManagerInit() { + const int r = init(); + SPARK_ASSERT(r == 0); + } + + CellularNetworkManager* instance() const { + return mgr_.get(); + } + +private: + std::unique_ptr client_; + std::unique_ptr mgr_; + + int init() { + // Get active SIM card + SimType sim = SimType::INVALID; + CHECK(CellularNetworkManager::getActiveSim(&sim)); + CellularNcpClientConfig conf; + conf.simType(sim); + conf.ncpIdentifier(platform_primary_ncp_identifier()); + conf.eventHandler(PppNcpNetif::ncpEventHandlerCb, pp3); + conf.dataHandler(PppNcpNetif::ncpDataHandlerCb, pp3); + // Initialize NCP client + std::unique_ptr client; + client.reset(new(std::nothrow) QuectelNcpClient); + CHECK_TRUE(client, SYSTEM_ERROR_NO_MEMORY); + CHECK(client->init(conf)); + // Initialize network manager + mgr_.reset(new(std::nothrow) CellularNetworkManager(client.get())); + CHECK_TRUE(mgr_, SYSTEM_ERROR_NO_MEMORY); + client_ = std::move(client); + return 0; + } +}; + +} // unnamed + +WifiNetworkManager* wifiNetworkManager() { + static WifiNetworkManagerInit mgr; + return mgr.instance(); +} + +CellularNetworkManager* cellularNetworkManager() { + static CellularNetworkManagerInit mgr; + return mgr.instance(); +} + +} // particle + +int if_init_platform(void*) { + /* lo0 (created by LwIP) */ + + /* th1 - OpenThread (Deprecated) */ + reserve_netif_index(); + + /* en2 - Ethernet FeatherWing (optional) */ + uint8_t deviceId[HAL_DEVICE_ID_SIZE] = {}; + hal_get_device_id(deviceId, sizeof(deviceId)); + uint8_t* mac = deviceId + HAL_DEVICE_ID_SIZE - 6; + mac[5] += 3; + + if (HAL_Feature_Get(FEATURE_ETHERNET_DETECTION)) { + en2 = new WizNetif(HAL_SPI_INTERFACE1, D5, D3, D4, mac); + } + + uint8_t dummy; + if (!en2 || if_get_index(en2->interface(), &dummy)) { + /* No en2 present */ + delete en2; + en2 = nullptr; + reserve_netif_index(); + } + + // Order of initialization is important! + /* pp3 - Cellular */ + pp3 = new PppNcpNetif(); + if (pp3) { + ((PppNcpNetif*)pp3)->setCellularManager(cellularNetworkManager()); + ((PppNcpNetif*)pp3)->init(); + } + + /* wl4 - Realtek NCP Station */ + wl4 = new RealtekNcpNetif(); + if (wl4) { + ((RealtekNcpNetif*)wl4)->setWifiManager(wifiNetworkManager()); + ((RealtekNcpNetif*)wl4)->init(); + } + + reserve_netif_index(); // wl5 + /* TODO: wl5 - Realtek NCP Access Point */ + (void)wl5; + + auto m = mallinfo(); + const size_t total = m.uordblks + m.fordblks; + LOG(TRACE, "Heap: %lu/%lu Kbytes used", m.uordblks / 1000, total / 1000); + + return 0; +} + +extern "C" { + +struct netif* lwip_hook_ip4_route_src(const ip4_addr_t* src, const ip4_addr_t* dst) { + if (src == nullptr) { + if (en2 && netifCanForwardIpv4(en2->interface())) { + return en2->interface(); +#if !HAL_PLATFORM_WIFI_SCAN_ONLY + } else if (wl4 && netifCanForwardIpv4(wl4->interface())) { + return wl4->interface(); +#endif + } else if (pp3 && netifCanForwardIpv4(pp3->interface())) { + return pp3->interface(); + } + } + + return nullptr; +} + +unsigned char* rltk_wlan_get_ip(int idx) { + return (uint8_t *) &(wl4->interface()->ip_addr); +} + +unsigned char* rltk_wlan_get_gw(int idx) { + return (uint8_t *) &(wl4->interface()->gw); +} + +unsigned char* rltk_wlan_get_gwmask(int idx) { + return (uint8_t *) &(wl4->interface()->netmask); +} + +void rltk_wlan_set_netif_info(int idx_wlan, void* dev, unsigned char* dev_addr) { + LOG(INFO, "rltk_wlan_set_netif_info: %d, %02x:%02x:%02x:%02x:%02x:%02x", idx_wlan, + dev_addr[0], dev_addr[1], dev_addr[2], dev_addr[3], dev_addr[4], dev_addr[5]); + if (wl4) { + memcpy(wl4->interface()->hwaddr, dev_addr, sizeof(wl4->interface()->hwaddr)); + } +} + +void netif_rx(int idx, unsigned int len) { + // LOG(INFO, "netif_rx %d %u", idx, len); + RealtekNcpNetif::ncpDataHandlerCb(0, nullptr, len, wl4); +} + +int netif_is_valid_IP(int idx, unsigned char *ip_dest) { + // Let LwIP stack handle this + return 1; +} + +} diff --git a/hal/src/trackerm/ota_flash_hal.cpp b/hal/src/trackerm/ota_flash_hal.cpp new file mode 100644 index 0000000000..3c044809b5 --- /dev/null +++ b/hal/src/trackerm/ota_flash_hal.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2022 Particle Industries, Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ + +#include +#include "ota_flash_hal_impl.h" +#include "platform_ncp.h" +#include "platform_radio_stack.h" + +void HAL_OTA_Add_System_Info(hal_system_info_t* info, bool create, void* reserved) +{ + add_system_properties(info, create, 0); +} diff --git a/hal/src/trackerm/pinmap_defines.cpp b/hal/src/trackerm/pinmap_defines.cpp new file mode 100644 index 0000000000..d4036f7828 --- /dev/null +++ b/hal/src/trackerm/pinmap_defines.cpp @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2022 Particle Industries, Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ + +#include "pinmap_hal.h" + +namespace { + +#define MCP23S17_PORT_A ((uint8_t)0u) +#define MCP23S17_PORT_B ((uint8_t)1u) +#define DEMUX_PORT ((uint8_t)0u) + +static hal_pin_info_t pinmap[TOTAL_PINS] = { +/* User space */ +/* D0 / A3 - 00 */ { RTL_PORT_B, 6, PIN_MODE_NONE, PF_NONE, 2, PWM_INSTANCE_NONE, PWM_CHANNEL_NONE, HAL_PIN_TYPE_MCU, 0}, +/* D1 / A4 - 01 */ { RTL_PORT_B, 5, PIN_MODE_NONE, PF_NONE, 1, 1, 9, HAL_PIN_TYPE_MCU, 0}, +/* D2 - 02 */ { RTL_PORT_A, 16, PIN_MODE_NONE, PF_NONE, ADC_CHANNEL_NONE, PWM_INSTANCE_NONE, PWM_CHANNEL_NONE, HAL_PIN_TYPE_MCU, 0}, +/* D3 - 03 */ { RTL_PORT_A, 17, PIN_MODE_NONE, PF_NONE, ADC_CHANNEL_NONE, PWM_INSTANCE_NONE, PWM_CHANNEL_NONE, HAL_PIN_TYPE_MCU, 0}, +/* D4 - 04 */ { RTL_PORT_A, 18, PIN_MODE_NONE, PF_NONE, ADC_CHANNEL_NONE, PWM_INSTANCE_NONE, PWM_CHANNEL_NONE, HAL_PIN_TYPE_MCU, 0}, +/* D5 - 05 */ { RTL_PORT_A, 19, PIN_MODE_NONE, PF_NONE, ADC_CHANNEL_NONE, PWM_INSTANCE_NONE, PWM_CHANNEL_NONE, HAL_PIN_TYPE_MCU, 0}, +/* D6 - 06 */ { RTL_PORT_B, 3, PIN_MODE_NONE, PF_NONE, ADC_CHANNEL_NONE, PWM_INSTANCE_NONE, PWM_CHANNEL_NONE, HAL_PIN_TYPE_MCU, 0}, +/* D7 - 07 */ { RTL_PORT_A, 27, PIN_MODE_NONE, PF_NONE, ADC_CHANNEL_NONE, PWM_INSTANCE_NONE, PWM_CHANNEL_NONE, HAL_PIN_TYPE_MCU, 0}, +/* D8 - 08 */ { RTL_PORT_A, 7, PIN_MODE_NONE, PF_NONE, ADC_CHANNEL_NONE, PWM_INSTANCE_NONE, PWM_CHANNEL_NONE, HAL_PIN_TYPE_MCU, 0}, +/* D9 - 09 */ { RTL_PORT_A, 8, PIN_MODE_NONE, PF_NONE, ADC_CHANNEL_NONE, PWM_INSTANCE_NONE, PWM_CHANNEL_NONE, HAL_PIN_TYPE_MCU, 0}, +/* D10 - 10 */ { RTL_PORT_A, 15, PIN_MODE_NONE, PF_NONE, ADC_CHANNEL_NONE, PWM_INSTANCE_NONE, PWM_CHANNEL_NONE, HAL_PIN_TYPE_MCU, 0}, +/* A0 - 11 */ { RTL_PORT_B, 1, PIN_MODE_NONE, PF_NONE, 4, PWM_INSTANCE_NONE, PWM_CHANNEL_NONE, HAL_PIN_TYPE_MCU, 0}, +/* A1 - 12 */ { RTL_PORT_B, 2, PIN_MODE_NONE, PF_NONE, 5, PWM_INSTANCE_NONE, PWM_CHANNEL_NONE, HAL_PIN_TYPE_MCU, 0}, +/* A2 - 13 */ { RTL_PORT_B, 7, PIN_MODE_NONE, PF_NONE, 3, 1, 17, HAL_PIN_TYPE_MCU, 0}, +/* A5 - 14 */ { RTL_PORT_B, 4, PIN_MODE_NONE, PF_NONE, 0, 1, 8, HAL_PIN_TYPE_MCU, 0}, +/* S0 - 15 */ { RTL_PORT_A, 12, PIN_MODE_NONE, PF_NONE, ADC_CHANNEL_NONE, 1, 0, HAL_PIN_TYPE_MCU, 0}, +/* S1 - 16 */ { RTL_PORT_A, 13, PIN_MODE_NONE, PF_NONE, ADC_CHANNEL_NONE, 1, 1, HAL_PIN_TYPE_MCU, 0}, +/* S2 - 17 */ { RTL_PORT_A, 14, PIN_MODE_NONE, PF_NONE, ADC_CHANNEL_NONE, PWM_INSTANCE_NONE, PWM_CHANNEL_NONE, HAL_PIN_TYPE_MCU, 0}, +/* S3 - 18 */ { RTL_PORT_B, 26, PIN_MODE_NONE, PF_NONE, ADC_CHANNEL_NONE, PWM_INSTANCE_NONE, PWM_CHANNEL_NONE, HAL_PIN_TYPE_MCU, 0}, +/* S4 - 19 */ { RTL_PORT_A, 0, PIN_MODE_NONE, PF_NONE, ADC_CHANNEL_NONE, PWM_INSTANCE_NONE, PWM_CHANNEL_NONE, HAL_PIN_TYPE_MCU, 0}, +/* S5 - 20 */ { RTL_PORT_B, 29, PIN_MODE_NONE, PF_NONE, ADC_CHANNEL_NONE, PWM_INSTANCE_NONE, PWM_CHANNEL_NONE, HAL_PIN_TYPE_MCU, 0}, +/* S6 - 21 */ { RTL_PORT_B, 31, PIN_MODE_NONE, PF_NONE, ADC_CHANNEL_NONE, PWM_INSTANCE_NONE, PWM_CHANNEL_NONE, HAL_PIN_TYPE_MCU, 0}, + +/* System space */ +/* RGBR - 22 */ { RTL_PORT_A, 30, PIN_MODE_NONE, PF_NONE, ADC_CHANNEL_NONE, 0, 1, HAL_PIN_TYPE_MCU, 0}, +/* RGBG - 23 */ { RTL_PORT_B, 23, PIN_MODE_NONE, PF_NONE, ADC_CHANNEL_NONE, 0, 3, HAL_PIN_TYPE_MCU, 0}, +/* RGBB - 24 */ { RTL_PORT_B, 22, PIN_MODE_NONE, PF_NONE, ADC_CHANNEL_NONE, 0, 2, HAL_PIN_TYPE_MCU, 0}, +/* MODE BUTTON - 25 */ { RTL_PORT_A, 4, PIN_MODE_NONE, PF_NONE, ADC_CHANNEL_NONE, PWM_INSTANCE_NONE, PWM_CHANNEL_NONE, HAL_PIN_TYPE_MCU, 0}, +/* ANTSW - 26 */ { RTL_PORT_A, 2, PIN_MODE_NONE, PF_NONE, ADC_CHANNEL_NONE, PWM_INSTANCE_NONE, PWM_CHANNEL_NONE, HAL_PIN_TYPE_MCU, 0}, +/* LOW_BAT_UC - 27 */ { MCP23S17_PORT_A, 0, PIN_MODE_NONE, PF_NONE, ADC_CHANNEL_NONE, PWM_INSTANCE_NONE, PWM_CHANNEL_NONE, HAL_PIN_TYPE_IO_EXPANDER, 0}, +/* SENSOR_INT1 - 28 */ { MCP23S17_PORT_A, 1, PIN_MODE_NONE, PF_NONE, ADC_CHANNEL_NONE, PWM_INSTANCE_NONE, PWM_CHANNEL_NONE, HAL_PIN_TYPE_IO_EXPANDER, 0}, +/* CAN_STBY - 29 */ { MCP23S17_PORT_A, 2, PIN_MODE_NONE, PF_NONE, ADC_CHANNEL_NONE, PWM_INSTANCE_NONE, PWM_CHANNEL_NONE, HAL_PIN_TYPE_IO_EXPANDER, 0}, +/* CAN_INT - 30 */ { MCP23S17_PORT_A, 3, PIN_MODE_NONE, PF_NONE, ADC_CHANNEL_NONE, PWM_INSTANCE_NONE, PWM_CHANNEL_NONE, HAL_PIN_TYPE_IO_EXPANDER, 0}, +/* PGOOD - 31 */ { MCP23S17_PORT_A, 4, PIN_MODE_NONE, PF_NONE, ADC_CHANNEL_NONE, PWM_INSTANCE_NONE, PWM_CHANNEL_NONE, HAL_PIN_TYPE_IO_EXPANDER, 0}, +/* DCDC_EN - 32 */ { MCP23S17_PORT_A, 5, PIN_MODE_NONE, PF_NONE, ADC_CHANNEL_NONE, PWM_INSTANCE_NONE, PWM_CHANNEL_NONE, HAL_PIN_TYPE_IO_EXPANDER, 0}, +/* GNSS_PWR_EN - 33 */ { MCP23S17_PORT_A, 6, PIN_MODE_NONE, PF_NONE, ADC_CHANNEL_NONE, PWM_INSTANCE_NONE, PWM_CHANNEL_NONE, HAL_PIN_TYPE_IO_EXPANDER, 0}, +/* GNSS_INT - 34 */ { MCP23S17_PORT_A, 7, PIN_MODE_NONE, PF_NONE, ADC_CHANNEL_NONE, PWM_INSTANCE_NONE, PWM_CHANNEL_NONE, HAL_PIN_TYPE_IO_EXPANDER, 0}, +/* GNSS_SAFEBOOT - 35 */ { MCP23S17_PORT_B, 0, PIN_MODE_NONE, PF_NONE, ADC_CHANNEL_NONE, PWM_INSTANCE_NONE, PWM_CHANNEL_NONE, HAL_PIN_TYPE_IO_EXPANDER, 0}, +/* GNSS_RST - 36 */ { MCP23S17_PORT_B, 1, PIN_MODE_NONE, PF_NONE, ADC_CHANNEL_NONE, PWM_INSTANCE_NONE, PWM_CHANNEL_NONE, HAL_PIN_TYPE_IO_EXPANDER, 0}, +/* CAN_RTS1 - 37 */ { MCP23S17_PORT_B, 2, PIN_MODE_NONE, PF_NONE, ADC_CHANNEL_NONE, PWM_INSTANCE_NONE, PWM_CHANNEL_NONE, HAL_PIN_TYPE_IO_EXPANDER, 0}, +/* CAN_RTS2 - 38 */ { MCP23S17_PORT_B, 3, PIN_MODE_NONE, PF_NONE, ADC_CHANNEL_NONE, PWM_INSTANCE_NONE, PWM_CHANNEL_NONE, HAL_PIN_TYPE_IO_EXPANDER, 0}, +/* CAN_RTS0 - 39 */ { MCP23S17_PORT_B, 4, PIN_MODE_NONE, PF_NONE, ADC_CHANNEL_NONE, PWM_INSTANCE_NONE, PWM_CHANNEL_NONE, HAL_PIN_TYPE_IO_EXPANDER, 0}, +/* P2_CELL_DIR - 40 */ { MCP23S17_PORT_B, 5, PIN_MODE_NONE, PF_NONE, ADC_CHANNEL_NONE, PWM_INSTANCE_NONE, PWM_CHANNEL_NONE, HAL_PIN_TYPE_IO_EXPANDER, 0}, +/* CAN_RST - 41 */ { MCP23S17_PORT_B, 6, PIN_MODE_NONE, PF_NONE, ADC_CHANNEL_NONE, PWM_INSTANCE_NONE, PWM_CHANNEL_NONE, HAL_PIN_TYPE_IO_EXPANDER, 0}, +/* CAN_VDD_EN - 42 */ { MCP23S17_PORT_B, 7, PIN_MODE_NONE, PF_NONE, ADC_CHANNEL_NONE, PWM_INSTANCE_NONE, PWM_CHANNEL_NONE, HAL_PIN_TYPE_IO_EXPANDER, 0}, + +/* SENSOR_CS - 43 */ { DEMUX_PORT, 2, PIN_MODE_NONE, PF_NONE, ADC_CHANNEL_NONE, PWM_INSTANCE_NONE, PWM_CHANNEL_NONE, HAL_PIN_TYPE_DEMUX, 0}, +/* GNSS_CS - 44 */ { DEMUX_PORT, 4, PIN_MODE_NONE, PF_NONE, ADC_CHANNEL_NONE, PWM_INSTANCE_NONE, PWM_CHANNEL_NONE, HAL_PIN_TYPE_DEMUX, 0}, +/* IOE_CS - 45 */ { DEMUX_PORT, 6, PIN_MODE_NONE, PF_NONE, ADC_CHANNEL_NONE, PWM_INSTANCE_NONE, PWM_CHANNEL_NONE, HAL_PIN_TYPE_DEMUX, 0}, +/* CAN_CS - 46 */ { DEMUX_PORT, 7, PIN_MODE_NONE, PF_NONE, ADC_CHANNEL_NONE, PWM_INSTANCE_NONE, PWM_CHANNEL_NONE, HAL_PIN_TYPE_DEMUX, 0}, + +}; + +} // anonymous + +hal_pin_info_t* hal_pin_map(void) { + return pinmap; +} diff --git a/hal/src/trackerm/pinmap_defines.h b/hal/src/trackerm/pinmap_defines.h new file mode 100644 index 0000000000..6fd2e57a3a --- /dev/null +++ b/hal/src/trackerm/pinmap_defines.h @@ -0,0 +1,146 @@ +/* + * Copyright (c) 2022 Particle Industries, Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ + +#pragma once + +#define TOTAL_PINS 47 +#define TOTAL_ANALOG_PINS 6 +#define FIRST_ANALOG_PIN 11 + +// Digital pins +#define D0 0 +#define D1 1 +#define D2 2 +#define D3 3 +#define D4 4 +#define D5 5 +#define D6 6 +#define D7 7 +#define D8 8 +#define D9 9 +#define D10 10 +#define D11 11 +#define D12 12 +#define D13 13 +#define D14 14 +#define D15 15 +#define D16 16 +#define D17 17 +#define D18 18 +#define D19 19 +#define D20 20 +#define D21 21 + +#define S0 D15 +#define S1 D16 +#define S2 D17 +#define S3 D18 +#define S4 D19 +#define S5 D20 +#define S6 D21 + +// Analog pins +#define A0 D11 +#define A1 D12 +#define A2 D13 +#define A3 D0 +#define A4 D1 +#define A5 D14 + +// RGB and Button +#define RGBR 22 +#define RGBG 23 +#define RGBB 24 +#define BTN 25 + +// SPI, Shared with UART2 +#define SS S3 +#define SCK S2 +#define MISO S1 +#define MOSI S0 + +#define SS1 D5 +#define SCK1 D4 +#define MISO1 D3 +#define MOSI1 D2 + +// IO Expander +#define IOE_INT D10 +#define IOE_RST A0 +#define IOE_CS 45 + +#define CS0 S3 +#define CS1 S4 +#define CS2 S5 + +#define DEMUX_A CS0 +#define DEMUX_B CS1 +#define DEMUX_C CS2 + +// I2C +#define SDA D0 +#define SCL D1 + +// PMIC +#define PMIC_SDA SDA +#define PMIC_SCL SCL +#define PMIC_INT S6 + +// UART +#define TX D8 +#define RX D9 +// Shared with SPI1 +#define TX1 D4 +#define RX1 D5 +#define CTS1 D3 +#define RTS1 D2 +// Shared with SPI +#define TX2 S0 +#define RX2 S1 +#define CTS2 D10 +#define RTS2 S2 + +#define WKP D10 + +#define ANTSW 26 +#define LOW_BAT_UC 27 +#define SENSOR_INT1 28 +#define CAN_STBY 29 +#define CAN_INT 30 +#define PGOOD 31 +#define DCDC_EN 32 +#define GNSS_PWR_EN 33 +#define GNSS_INT 34 +#define GNSS_SAFEBOOT 35 +#define GNSS_RST 36 +#define CAN_RTS1 37 +#define CAN_RTS2 38 +#define CAN_RTS0 39 +#define P2_CELL_DTR 40 +#define CAN_RST 41 +#define CAN_VDD_EN 42 + +#define SENSOR_CS 43 +#define GNSS_CS 44 +#define CAN_CS 46 + +// Cellular +#define BGRST A1 +#define BGPWR A1 +#define BGVINT A2 +#define BGDTR P2_CELL_DTR + diff --git a/hal/src/trackerm/platform_ncp_quectel.cpp b/hal/src/trackerm/platform_ncp_quectel.cpp new file mode 100644 index 0000000000..94e5c16e2e --- /dev/null +++ b/hal/src/trackerm/platform_ncp_quectel.cpp @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2022 Particle Industries, Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ + +#include "platform_ncp.h" +#include "exflash_hal.h" +#include "dct.h" +#include "check.h" +#include "system_error.h" +#include "deviceid_hal.h" + +namespace { + +const uintptr_t NCP_ID_OTP_ADDRESS = 0x00000020; + +// Undefine hardware version +const auto HW_VERSION_UNDEFINED = 0xFF; + +bool isValidNcpId(uint8_t id) { + switch (id) { + case PlatformNCPIdentifier::PLATFORM_NCP_QUECTEL_BG96: + case PlatformNCPIdentifier::PLATFORM_NCP_QUECTEL_EG91_E: + case PlatformNCPIdentifier::PLATFORM_NCP_QUECTEL_EG91_NA: + case PlatformNCPIdentifier::PLATFORM_NCP_QUECTEL_EG91_EX: + case PlatformNCPIdentifier::PLATFORM_NCP_QUECTEL_BG95_M1: + return true; + default: + return false; + } +} + +const auto NCP_IDX_PRIMARY_QUECTEL = 0; + +} // unnamed + +PlatformNCPIdentifier platform_primary_ncp_identifier() { + // Check the DCT + uint8_t ncpId = 0; + int r = dct_read_app_data_copy(DCT_NCP_ID_OFFSET, &ncpId, 1); + if (r < 0 || !isValidNcpId(ncpId)) { + // Check the OTP flash + r = hal_exflash_read_special(HAL_EXFLASH_SPECIAL_SECTOR_OTP, NCP_ID_OTP_ADDRESS, &ncpId, 1); + if (r < 0 || !isValidNcpId(ncpId)) { + // Check the logical eFuse + uint32_t hwVersion = HW_VERSION_UNDEFINED; + r = hal_get_device_hw_version(&hwVersion, nullptr); + // get the first byte for NCP ID + ncpId = (hwVersion & 0xFF); + if (r < 0 || !isValidNcpId(ncpId)) { + ncpId = PlatformNCPIdentifier::PLATFORM_NCP_UNKNOWN; + } + } + } + return (PlatformNCPIdentifier)ncpId; +} + +int platform_ncp_get_info(int idx, PlatformNCPInfo* info) { + CHECK_TRUE(info, SYSTEM_ERROR_INVALID_ARGUMENT); + CHECK_TRUE(idx > 0 && idx < platform_ncp_count(), SYSTEM_ERROR_INVALID_ARGUMENT); + if (idx == NCP_IDX_PRIMARY_QUECTEL) { + info->identifier = platform_primary_ncp_identifier(); + info->updatable = false; + } + return 0; +} diff --git a/hal/src/trackerm/sources.mk b/hal/src/trackerm/sources.mk new file mode 100644 index 0000000000..8ebb28b247 --- /dev/null +++ b/hal/src/trackerm/sources.mk @@ -0,0 +1,27 @@ +HAL_SRC_TRACKERM_PATH = $(TARGET_HAL_PATH)/src/trackerm + +INCLUDE_DIRS += $(HAL_SRC_TRACKERM_PATH) + +CSRC += $(call target_files,$(HAL_SRC_TRACKERM_PATH)/,*.c) +CPPSRC += $(call target_files,$(HAL_SRC_TRACKERM_PATH)/,*.cpp) + +CSRC += $(call here_files,$(HAL_MODULE_PATH)/network/lwip/cellular/,*.c) +CPPSRC += $(call here_files,$(HAL_MODULE_PATH)/network/lwip/cellular/,*.cpp) + +CSRC += $(call here_files,$(HAL_MODULE_PATH)/network/ncp/cellular/,*.c) +CPPSRC += $(call here_files,$(HAL_MODULE_PATH)/network/ncp/cellular/,*.cpp) + +CSRC += $(call here_files,$(HAL_MODULE_PATH)/network/ncp_client/quectel/,*.c) +CPPSRC += $(call here_files,$(HAL_MODULE_PATH)/network/ncp_client/quectel/,*.cpp) + +CSRC += $(call here_files,$(HAL_MODULE_PATH)/network/ncp/wifi/,*.c) +CPPSRC += $(call here_files,$(HAL_MODULE_PATH)/network/ncp/wifi/,*.cpp) + +CSRC += $(call here_files,$(HAL_MODULE_PATH)/network/lwip/realtek/,*.c) +CPPSRC += $(call here_files,$(HAL_MODULE_PATH)/network/lwip/realtek/,*.cpp) + +CSRC += $(call here_files,$(HAL_MODULE_PATH)/network/ncp_client/realtek/,*.c) +CPPSRC += $(call here_files,$(HAL_MODULE_PATH)/network/ncp_client/realtek/,*.cpp) + +include $(HAL_PLATFORM_SRC_PATH)/../rtl872x/sources.mk + diff --git a/hal/src/trackerm/tlm.mk b/hal/src/trackerm/tlm.mk new file mode 100644 index 0000000000..0f5c788c5e --- /dev/null +++ b/hal/src/trackerm/tlm.mk @@ -0,0 +1,6 @@ +# this is included in the top-level-module makefile to provide +# HAL-specific defines + +include $(HAL_MODULE_PATH)/src/rtl872x/tlm.mk + +DEPENDENCIES += system diff --git a/hal/src/tron/hal_platform_config.h b/hal/src/tron/hal_platform_config.h index 7f1315cfd6..3b42735c38 100644 --- a/hal/src/tron/hal_platform_config.h +++ b/hal/src/tron/hal_platform_config.h @@ -4,6 +4,7 @@ #include "platforms.h" #define HAL_PLATFORM_NCP (1) +#define HAL_PLATFORM_USART2 (1) #define HAL_PLATFORM_NCP_AT (0) #define HAL_PLATFORM_CELLULAR (0) // #define HAL_PLATFORM_CELLULAR_SERIAL (HAL_USART_SERIAL2) @@ -11,9 +12,10 @@ // #define HAL_PLATFORM_MUXER_MAY_NEED_DELAY_IN_TX (1) #define HAL_PLATFORM_SPI_NUM (2) #define HAL_PLATFORM_I2C_NUM (2) -#define HAL_PLATFORM_USART_NUM (2) +#define HAL_PLATFORM_USART_NUM (3) #define HAL_PLATFORM_NCP_COUNT (1) #define HAL_PLATFORM_BROKEN_MTU (1) +#define HAL_PLATFORM_WIFI (1) #define HAL_PLATFORM_WIFI_COMPAT (1) #define HAL_PLATFORM_RADIO_ANTENNA_INTERNAL (1) diff --git a/hal/src/tron/network/network.cpp b/hal/src/tron/network/network.cpp index cb42f820cb..75c9020f88 100644 --- a/hal/src/tron/network/network.cpp +++ b/hal/src/tron/network/network.cpp @@ -30,6 +30,8 @@ #include "realtek/rtlncpnetif.h" #include "lwip_util.h" #include "core_hal.h" +#include "deviceid_hal.h" + using namespace particle; using namespace particle::net; @@ -105,25 +107,13 @@ int if_init_platform(void*) { reserve_netif_index(); /* en2 - Ethernet FeatherWing (optional) */ - uint8_t mac[6] = {0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}; - { - // const uint32_t lsb = __builtin_bswap32(NRF_FICR->DEVICEADDR[0]); - // const uint32_t msb = NRF_FICR->DEVICEADDR[1] & 0xffff; - // memcpy(mac + 2, &lsb, sizeof(lsb)); - // mac[0] = msb >> 8; - // mac[1] = msb; - /* Drop 'multicast' bit */ - mac[0] &= 0b11111110; - /* Set 'locally administered' bit */ - mac[0] |= 0b10; - } + uint8_t deviceId[HAL_DEVICE_ID_SIZE] = {}; + hal_get_device_id(deviceId, sizeof(deviceId)); + uint8_t* mac = deviceId + HAL_DEVICE_ID_SIZE - 6; + mac[5] += 3; if (HAL_Feature_Get(FEATURE_ETHERNET_DETECTION)) { -#if PLATFORM_ID == PLATFORM_ARGON || PLATFORM_ID == PLATFORM_P2 en2 = new WizNetif(HAL_SPI_INTERFACE1, D5, D3, D4, mac); -#else // A SoM - en2 = new WizNetif(HAL_SPI_INTERFACE1, D8, A7, D22, mac); -#endif } uint8_t dummy; diff --git a/main/makefile b/main/makefile index f9a091c0d1..0077545380 100644 --- a/main/makefile +++ b/main/makefile @@ -27,6 +27,9 @@ endif ifeq ($(PLATFORM_ID),26) MODULAR?=y endif +ifeq ($(PLATFORM_ID),28) +MODULAR?=y +endif ifeq ($(PLATFORM_ID),32) MODULAR?=y endif @@ -73,7 +76,7 @@ BUILD_PATH_EXT = $(BUILD_TARGET_PLATFORM)$(USER_FLAVOR) USE_PRINTF_FLOAT ?= y -ifeq ("$(PLATFORM)","p2") +ifeq ($(PLATFORM_MCU),rtl872x) RTL_BINARY_FLASH_START = 0x60000 endif diff --git a/modules/shared/system_module_version.mk b/modules/shared/system_module_version.mk index e3a47dd424..fcb8fe05d4 100644 --- a/modules/shared/system_module_version.mk +++ b/modules/shared/system_module_version.mk @@ -16,7 +16,7 @@ USER_PART_MODULE_VERSION ?= 6 # Bump by 1 for every updated bootloader image for a release with the same v0.x.* base. BOOTLOADER_VERSION ?= 2000 -ifeq ($(PLATFORM_ID),32) +ifeq ($(PLATFORM_MCU),rtl872x) PREBOOTLOADER_MBR_VERSION ?= 2 PREBOOTLOADER_PART1_VERSION ?= 3 endif @@ -24,7 +24,7 @@ endif # The version of the bootloader that the system firmware requires # NOTE: this will force the device into safe mode until this dependency is met, which is why # this version usually lags behind the current bootloader version, to avoid non-mandatory updates. -ifeq ($(PLATFORM_ID),32) +ifeq ($(PLATFORM_MCU),rtl872x) BOOTLOADER_DEPENDENCY = 2000 else ifeq ($(PLATFORM_GEN),3) BOOTLOADER_DEPENDENCY = 1101 @@ -32,7 +32,7 @@ else # Some sensible default BOOTLOADER_DEPENDENCY = 0 endif -ifeq ($(PLATFORM_ID),32) +ifeq ($(PLATFORM_MCU),rtl872x) PREBOOTLOADER_PART1_DEPENDENCY = 3 endif @@ -70,7 +70,7 @@ endif endif endif # ($(PLATFORM_MCU),nRF52840) -ifeq ($(PLATFORM_ID), 32) +ifeq ($(PLATFORM_MCU),rtl872x) SYSTEM_PART1_MODULE_DEPENDENCY ?= ${MODULE_FUNCTION_BOOTLOADER},0,${BOOTLOADER_DEPENDENCY} BOOTLOADER_MODULE_DEPENDENCY ?= ${MODULE_FUNCTION_BOOTLOADER},2,${PREBOOTLOADER_PART1_DEPENDENCY} endif diff --git a/modules/trackerm/makefile b/modules/trackerm/makefile new file mode 100644 index 0000000000..6388752df0 --- /dev/null +++ b/modules/trackerm/makefile @@ -0,0 +1,4 @@ +include modular.mk + +%: + $(MAKE) -C .. $(MAKECMDGOALS) diff --git a/modules/trackerm/modular.mk b/modules/trackerm/modular.mk new file mode 100644 index 0000000000..2852945f6d --- /dev/null +++ b/modules/trackerm/modular.mk @@ -0,0 +1,12 @@ +# Makefile that included by all modules - this defines the layout of the various modules + +SHARED_MODULAR=$(PROJECT_ROOT)/modules/shared/rtl872x + +MODULAR_FIRMWARE=y +# propagate to sub makes +MAKE_ARGS += MODULAR_FIRMWARE=y + +# Ensure these defines are passed to all sub makefiles +GLOBAL_DEFINES += MODULAR_FIRMWARE=1 + +export PLATFORM_ID ?= 28 \ No newline at end of file diff --git a/modules/trackerm/system-part1/build.mk b/modules/trackerm/system-part1/build.mk new file mode 100644 index 0000000000..835c22f8a4 --- /dev/null +++ b/modules/trackerm/system-part1/build.mk @@ -0,0 +1,2 @@ + +include ../../shared/rtl872x/part1_build.mk \ No newline at end of file diff --git a/modules/trackerm/system-part1/import.mk b/modules/trackerm/system-part1/import.mk new file mode 100644 index 0000000000..70a64e2ecc --- /dev/null +++ b/modules/trackerm/system-part1/import.mk @@ -0,0 +1,9 @@ +include ../../shared/system_module_version.mk +SYSTEM_PART1_MODULE_PATH ?= $(PROJECT_ROOT)/modules/trackerm/system-part1 + +ifeq ($(MINIMAL),y) +GLOBAL_DEFINES += SYSTEM_MINIMAL +endif + +include $(call rwildcard,$(SYSTEM_PART1_MODULE_PATH)/,include.mk) +include $(call rwildcard,$(SHARED_MODULAR)/,include.mk) diff --git a/modules/trackerm/system-part1/linker.ld b/modules/trackerm/system-part1/linker.ld new file mode 100644 index 0000000000..fd00c56303 --- /dev/null +++ b/modules/trackerm/system-part1/linker.ld @@ -0,0 +1,21 @@ +/* Memory spaces definitions */ +INCLUDE platform_ram.ld +INCLUDE platform_flash.ld + +MEMORY +{ + INCLUDE memory_backup_ram.ld + + APP_FLASH (rx) : ORIGIN = platform_system_part1_flash_start, LENGTH = platform_system_part1_flash_size + SRAM (rwx) : ORIGIN = platform_system_part1_static_ram_start, LENGTH = platform_system_part1_static_ram_size + SECURE_SRAM (rwx) : ORIGIN = platform_system_part1_secure_ram_start, LENGTH = platform_system_part1_secure_ram_size + PSRAM (rwx) : ORIGIN = platform_system_part1_psram_start, LENGTH = platform_system_part1_psram_size +} + +/* Define the static locations of the part1 module so the dynamic invoke functions have the base address of each library table. */ +INCLUDE module_system_part1_export.ld + +/* Definitions for the static parts of the user module */ +INCLUDE module_user_export.ld + +INCLUDE linker_system_part1_common.ld diff --git a/modules/trackerm/system-part1/makefile b/modules/trackerm/system-part1/makefile new file mode 100644 index 0000000000..e53d18476f --- /dev/null +++ b/modules/trackerm/system-part1/makefile @@ -0,0 +1,23 @@ +MODULE=system-part1 +SYSTEM_PART1_MODULE_PATH=. +PROJECT_ROOT = ../../.. +BUILD_PATH_EXT = $(BUILD_TARGET_PLATFORM) +HAL_LINK := + +DEPENDENCIES = newlib_nano modules/trackerm/user-part modules/trackerm/system-part1 dynalib services hal platform system wiring communication rt-dynalib crypto wiring_globals +LIB_DEPENDENCIES = services system wiring communication hal platform crypto wiring_globals +# newlib_nano is special in that it's linked automatically by the system, so no need to add it to the library path here +MAKE_DEPENDENCIES = newlib_nano $(LIB_DEPENDENCIES) +include ../modular.mk +include $(PROJECT_ROOT)/build/platform-id.mk + +LIBS += $(LIB_DEPENDENCIES) +LIB_DEPS += $(SERVICES_LIB_DEP) $(PLATFORM_LIB_DEP) $(HAL_LIB_DEP) $(SYSTEM_LIB_DEP) $(COMMUNICATION_LIB_DEP) $(WIRING_LIB_DEP) $(CRYPTO_LIB_DEP) $(WIRING_GLOBALS_LIB_DEP) +LIB_DIRS += $(dir $(LIB_DEPS)) + +TARGET=elf bin lst hex size + + +include $(PROJECT_ROOT)/build/arm-tlm.mk + +$(call check_modular) diff --git a/modules/trackerm/system-part1/module_system_part1_export.ld b/modules/trackerm/system-part1/module_system_part1_export.ld new file mode 100644 index 0000000000..93237b9b9f --- /dev/null +++ b/modules/trackerm/system-part1/module_system_part1_export.ld @@ -0,0 +1,29 @@ +/* Dynalib table locations */ +PROVIDE (link_dynalib_location_offset_hal = 0); +PROVIDE (link_dynalib_location_offset_rt = 4); +PROVIDE (link_dynalib_location_offset_system = 8); +PROVIDE (link_dynalib_location_offset_hal_peripherals = 12); +PROVIDE (link_dynalib_location_offset_hal_i2c = 16); +PROVIDE (link_dynalib_location_offset_hal_gpio = 20); +PROVIDE (link_dynalib_location_offset_hal_spi = 24); +PROVIDE (link_dynalib_location_offset_hal_core = 28); +PROVIDE (link_dynalib_location_offset_hal_socket = 32); +PROVIDE (link_dynalib_location_offset_hal_usart = 36); +PROVIDE (link_dynalib_location_offset_system_net = 40); +PROVIDE (link_dynalib_location_offset_system_cloud = 44); +PROVIDE (link_dynalib_location_offset_hal_concurrent = 48); +PROVIDE (link_dynalib_location_offset_hal_usb = 52); +PROVIDE (link_dynalib_location_offset_hal_rgbled = 56); +PROVIDE (link_dynalib_location_offset_hal_bootloader = 60); +PROVIDE (link_dynalib_location_offset_hal_dct = 64); +PROVIDE (link_dynalib_location_offset_communication = 68); +PROVIDE (link_dynalib_location_offset_services = 72); +PROVIDE (link_dynalib_location_offset_hal_inet = 76); +PROVIDE (link_dynalib_location_offset_hal_netdb = 80); +PROVIDE (link_dynalib_location_offset_hal_ifapi = 84); +PROVIDE (link_dynalib_location_offset_hal_resolvapi = 88); +PROVIDE (link_dynalib_location_offset_hal_wlan = 92); +PROVIDE (link_dynalib_location_offset_hal_ble = 96); +PROVIDE (link_dynalib_location_offset_hal_posix_syscall = 100); +PROVIDE (link_dynalib_location_offset_hal_storage = 104); +PROVIDE (link_dynalib_location_offset_hal_cellular = 108); diff --git a/modules/trackerm/system-part1/src/export_rt.c b/modules/trackerm/system-part1/src/export_rt.c new file mode 100644 index 0000000000..870f4f7549 --- /dev/null +++ b/modules/trackerm/system-part1/src/export_rt.c @@ -0,0 +1 @@ +#include "export_rt.inc" diff --git a/modules/trackerm/system-part1/src/export_system.cpp b/modules/trackerm/system-part1/src/export_system.cpp new file mode 100644 index 0000000000..b930aa143d --- /dev/null +++ b/modules/trackerm/system-part1/src/export_system.cpp @@ -0,0 +1 @@ +#include "export_system.inc" diff --git a/modules/trackerm/system-part1/src/import_user.c b/modules/trackerm/system-part1/src/import_user.c new file mode 100644 index 0000000000..1bd06bbece --- /dev/null +++ b/modules/trackerm/system-part1/src/import_user.c @@ -0,0 +1 @@ +#include "import_user.inc" diff --git a/modules/trackerm/system-part1/src/import_user_preinit.c b/modules/trackerm/system-part1/src/import_user_preinit.c new file mode 100644 index 0000000000..28eeedeb0d --- /dev/null +++ b/modules/trackerm/system-part1/src/import_user_preinit.c @@ -0,0 +1 @@ +#include "import_user_preinit.inc" diff --git a/modules/trackerm/system-part1/src/module_info.c b/modules/trackerm/system-part1/src/module_info.c new file mode 100644 index 0000000000..cb6da8a379 --- /dev/null +++ b/modules/trackerm/system-part1/src/module_info.c @@ -0,0 +1 @@ +#include "module_info.inc" diff --git a/modules/trackerm/system-part1/src/module_system_part1.cpp b/modules/trackerm/system-part1/src/module_system_part1.cpp new file mode 100644 index 0000000000..d2885497eb --- /dev/null +++ b/modules/trackerm/system-part1/src/module_system_part1.cpp @@ -0,0 +1 @@ +#include "module_system_part1.inc" diff --git a/modules/trackerm/user-part/build.mk b/modules/trackerm/user-part/build.mk new file mode 100644 index 0000000000..c9eedae1c2 --- /dev/null +++ b/modules/trackerm/user-part/build.mk @@ -0,0 +1 @@ +include ../../shared/rtl872x/user_build.mk \ No newline at end of file diff --git a/modules/trackerm/user-part/import.mk b/modules/trackerm/user-part/import.mk new file mode 100644 index 0000000000..2cccf6c19e --- /dev/null +++ b/modules/trackerm/user-part/import.mk @@ -0,0 +1,5 @@ +include ../../shared/system_module_version.mk +USER_PART_MODULE_PATH ?= $(PROJECT_ROOT)/modules/trackerm/user-part +include $(call rwildcard,$(USER_PART_MODULE_PATH)/,include.mk) + + diff --git a/modules/trackerm/user-part/linker.ld b/modules/trackerm/user-part/linker.ld new file mode 100644 index 0000000000..777ab77f2c --- /dev/null +++ b/modules/trackerm/user-part/linker.ld @@ -0,0 +1,23 @@ +/* This file is generated at build time (see build_linker_script.mk) */ +INCLUDE memory_platform_user.ld + +INCLUDE platform_ram.ld +INCLUDE platform_flash.ld + +MEMORY +{ + INCLUDE memory_backup_ram.ld + + APP_FLASH (rx) : ORIGIN = platform_user_part_flash_start, LENGTH = platform_user_part_flash_size + SRAM (rwx) : ORIGIN = platform_user_part_static_ram_start, LENGTH = platform_user_part_static_ram_size + SECURE_SRAM (rwx) : ORIGIN = platform_user_part_secure_ram_start, LENGTH = platform_user_part_secure_ram_size + PSRAM (rwx) : ORIGIN = platform_user_part_psram_start, LENGTH = platform_user_part_psram_size +} + +/* Define the static locations of the part1 module so the dynamic invoke functions have the base address of each library table. */ +INCLUDE module_system_part1_export.ld + +/* Definitions for the static parts of the user module */ +INCLUDE module_user_export.ld + +INCLUDE linker_user_part_common.ld diff --git a/modules/trackerm/user-part/makefile b/modules/trackerm/user-part/makefile new file mode 100644 index 0000000000..0095f66d90 --- /dev/null +++ b/modules/trackerm/user-part/makefile @@ -0,0 +1,58 @@ +MODULE=user-part +USER_PART_MODULE_PATH=. +PROJECT_ROOT=../../.. +BUILD_PATH_EXT = $(BUILD_TARGET_PLATFORM) +HAL_LINK := +PLATFORM_DFU_LEAVE = y +# disable LTO build on 2015q2 - see issue #471 +export COMPILE_LTO=n + +# communication used only for header declarations +DEPENDENCIES = user dynalib services services-dynalib hal hal-dynalib system system-dynalib rt-dynalib wiring communication-dynalib modules/trackerm/system-part1 platform wiring_globals +MAKE_DEPENDENCIES = user hal-dynalib services-dynalib system-dynalib rt-dynalib wiring communication-dynalib platform wiring_globals +include ../modular.mk +include $(PROJECT_ROOT)/build/platform-id.mk + +LIBS += $(MAKE_DEPENDENCIES) +LIB_DEPS += $(USER_LIB_DEP) $(SERVICES_DYNALIB_LIB_DEP) $(HAL_DYNALIB_LIB_DEP) $(SYSTEM_DYNALIB_LIB_DEP) $(RT_DYNALIB_LIB_DEP) $(WIRING_LIB_DEP) $(COMMUNICATION_DYNALIB_LIB_DEP) $(PLATFORM_LIB_DEP) $(WIRING_GLOBALS_LIB_DEP) +LIB_DIRS += $(dir $(LIB_DEPS)) + + +TARGET= elf elf_fi bin lst hex size + + +include $(PROJECT_ROOT)/build/arm-tlm.mk + +$(call check_modular) + +MODULE_USER_MEMORY_FILE_GEN = $(TARGET_BASE_DIR)memory_platform_user.ld +export MODULE_USER_MEMORY_FILE_GEN + +elf_fi: $(TARGET_BASE)_fi.elf + + +prebuild: $(SHARED_MODULAR)/build_linker_script.mk + $(call echo,) + $(VERBOSE)$(RM) $(MODULE_USER_MEMORY_FILE_GEN) + $(VERBOSE)$(RM) $(TARGET_BASE).elf + $(VERBOSE)$(MKDIR) $(dir $(MODULE_USER_MEMORY_FILE_GEN)) + $(VERBOSE)$(MAKE) -f $(SHARED_MODULAR)/build_linker_script.mk PREBUILD=1 + $(call echo,) + + +postbuild: +# $(VERBOSE)$(RM) $(MODULE_USER_MEMORY_FILE_GEN) + + +$(TARGET_BASE)_fi.elf: $(ALLOBJ) $(LIB_DEPS) $(LINKER_DEPS) $(TARGET_BASE).elf $(SHARED_MODULAR)/build_linker_script.mk + $(VERBOSE)$(RM) $(MODULE_USER_MEMORY_FILE_GEN) + $(VERBOSE)$(MKDIR) $(dir $(MODULE_USER_MEMORY_FILE_GEN)) + $(VERBOSE)$(MAKE) -f $(SHARED_MODULAR)/build_linker_script.mk INTERMEDIATE_ELF=$(TARGET_BASE).elf + $(call echo,) + $(call echo, Generating the final ELF file...) + $(VERBOSE)$(MKDIR) $(dir $@) + $(VERBOSE)$(CCACHE) $(CPP) $(CFLAGS) $(ALLOBJ) --output $@ $(LDFLAGS) + $(VERBOSE)mv -f $@ $(TARGET_BASE).elf + $(call echo,) + +.PHONY: elf_fi diff --git a/modules/trackerm/user-part/module_user_export.ld b/modules/trackerm/user-part/module_user_export.ld new file mode 100644 index 0000000000..e9bc52f2dd --- /dev/null +++ b/modules/trackerm/user-part/module_user_export.ld @@ -0,0 +1,3 @@ +/* Dynalib table locations */ +PROVIDE (link_dynalib_location_offset_preinit = 0); +PROVIDE (link_dynalib_location_offset_user = 4); diff --git a/modules/trackerm/user-part/src/module_info.c b/modules/trackerm/user-part/src/module_info.c new file mode 100644 index 0000000000..cb6da8a379 --- /dev/null +++ b/modules/trackerm/user-part/src/module_info.c @@ -0,0 +1 @@ +#include "module_info.inc" diff --git a/modules/trackerm/user-part/src/newlib_stubs.cpp b/modules/trackerm/user-part/src/newlib_stubs.cpp new file mode 100644 index 0000000000..ec1cbe5c9c --- /dev/null +++ b/modules/trackerm/user-part/src/newlib_stubs.cpp @@ -0,0 +1 @@ +#include "newlib_stubs.inc" diff --git a/modules/trackerm/user-part/src/user_export.c b/modules/trackerm/user-part/src/user_export.c new file mode 100644 index 0000000000..ffc388f79d --- /dev/null +++ b/modules/trackerm/user-part/src/user_export.c @@ -0,0 +1 @@ +#include "user_part_export.c" \ No newline at end of file diff --git a/modules/trackerm/user-part/src/user_module.c b/modules/trackerm/user-part/src/user_module.c new file mode 100644 index 0000000000..215cda7210 --- /dev/null +++ b/modules/trackerm/user-part/src/user_module.c @@ -0,0 +1 @@ +#include "user_module.inc" diff --git a/platform/MCU/rtl872x/inc/platform_config.h b/platform/MCU/rtl872x/inc/platform_config.h index c745c08034..2e656c9fef 100644 --- a/platform/MCU/rtl872x/inc/platform_config.h +++ b/platform/MCU/rtl872x/inc/platform_config.h @@ -47,12 +47,8 @@ #define SYSTICK_IRQ_PRIORITY 7 //CORTEX_M33 Systick Interrupt -#if PLATFORM_ID == PLATFORM_P2 - #define INTERNAL_FLASH_SIZE (0x800000) -#else - #pragma message "PLATFORM_ID is " PREPSTRING(PLATFORM_ID) - #error "Unknown PLATFORM_ID" -#endif +// Currently works with platforms P2 and TrackerM +#define INTERNAL_FLASH_SIZE (0x800000) //Push Buttons, use interrupt HAL #define BUTTON1_PIN BTN diff --git a/system/src/control/wifi_new.cpp b/system/src/control/wifi_new.cpp index 904497aabb..b55c5c5e21 100644 --- a/system/src/control/wifi_new.cpp +++ b/system/src/control/wifi_new.cpp @@ -92,7 +92,7 @@ int joinNewNetwork(ctrl_request* req) { CHECK_TRUE(ncpClient, SYSTEM_ERROR_UNKNOWN); const NcpClientLock lock(ncpClient); // FIXME; the security sent from the mobile app is always zero. -#if PLATFORM_ID == 32 +#if HAL_PLATFORM_RTL872X // Scan for networks Vector networks; CHECK(ncpClient->scan([](WifiScanResult network, void* data) -> int { diff --git a/system/src/system_sleep.cpp b/system/src/system_sleep.cpp index 513c7be93d..364f2d1458 100644 --- a/system/src/system_sleep.cpp +++ b/system/src/system_sleep.cpp @@ -80,7 +80,7 @@ network_status_t system_sleep_network_suspend(network_interface_index index) { } } #endif -#if PLATFORM_ID == PLATFORM_P2 +#if HAL_PLATFORM_RTL872X // P2 doesn't need to turn off the modem manually system_notify_event(network_status, network_status_off); #else diff --git a/third_party/ambd_sdk/ambd_sdk b/third_party/ambd_sdk/ambd_sdk index 1dffc25c89..a3d2a9ae01 160000 --- a/third_party/ambd_sdk/ambd_sdk +++ b/third_party/ambd_sdk/ambd_sdk @@ -1 +1 @@ -Subproject commit 1dffc25c890010c4da1f7e5cfb8a77d817363e9a +Subproject commit a3d2a9ae01b136b985d7e5670a32c071fd085cfd diff --git a/user/applications/tinker/application.cpp b/user/applications/tinker/application.cpp index a338fd2cc6..2a283a1fe1 100644 --- a/user/applications/tinker/application.cpp +++ b/user/applications/tinker/application.cpp @@ -58,7 +58,7 @@ const PinMapping g_pinmap[] = { # endif // PLATFORM_ID == PLATFORM_BSOM || PLATFORM_ID == PLATFORM_B5SOM || PLATFORM_ID == PLATFORM_ASOM # endif // PLATFORM_ID == PLATFORM_TRACKER - // P2 + // P2 or TrackerM #elif HAL_PLATFORM_RTL872X PIN(D0), PIN(D1), PIN(D2), PIN(D3), PIN(D4), PIN(D5), PIN(D6), PIN(D7), PIN(D8), PIN(D9), PIN(D10), PIN(D11), PIN(D12), PIN(D13), PIN(D14), PIN(D15), PIN(D16), PIN(D17), PIN(D18), diff --git a/user/inc/Arduino.h b/user/inc/Arduino.h index cf3b10f0c3..26368bf81b 100644 --- a/user/inc/Arduino.h +++ b/user/inc/Arduino.h @@ -91,7 +91,7 @@ inline void yield() { #endif #ifndef analogInputToDigitalPin -#if PLATFORM_ID == PLATFORM_P2 +#if HAL_PLATFORM_RTL872X #define analogInputToDigitalPin(p) ((p) == 3 ? 0 : \ ((p) == 4 ? 1 : \ ((p) == 5 ? 14 : \ @@ -141,15 +141,15 @@ extern GPIO_TypeDef* PORT_AB[2]; # endif # ifndef portOutputRegister -# define portOutputRegister(port) ( &( port->PORT[ (port == PORT_AB[RTL_PORT_A]) ? RTL_PORT_A : RTL_PORT_B ].DR ) ) +# define portOutputRegister(port) ( &( port->PORT[0].DR ) ) # endif # ifndef portInputRegister -# define portInputRegister(port) ( &( port->EXT_PORT[ (port == PORT_AB[RTL_PORT_A]) ? RTL_PORT_A : RTL_PORT_B ] ) ) +# define portInputRegister(port) ( &( port->EXT_PORT[0] ) ) # endif # ifndef portModeRegister -# define portModeRegister(port) ( &( port->PORT[ (port == PORT_AB[RTL_PORT_A]) ? RTL_PORT_A : RTL_PORT_B ].DDR ) ) +# define portModeRegister(port) ( &( port->PORT[0].DDR ) ) # endif # ifndef digitalPinHasPWM diff --git a/user/tests/wiring/no_fixture_ble/ble.cpp b/user/tests/wiring/no_fixture_ble/ble.cpp index 07992a93b2..f687afbba5 100644 --- a/user/tests/wiring/no_fixture_ble/ble.cpp +++ b/user/tests/wiring/no_fixture_ble/ble.cpp @@ -20,7 +20,7 @@ #if Wiring_BLE == 1 -#if PLATFORM_ID != PLATFORM_P2 // P2 doesn't support setting device address +#if !HAL_PLATFORM_RTL872X // P2 doesn't support setting device address test(BLE_01_Set_BLE_Device_Address) { int ret; BleAddress defaultAddr = BLE.address(); @@ -74,7 +74,7 @@ test(BLE_01_Set_BLE_Device_Address) { getAddr = BLE.address(); assertTrue(getAddr == defaultAddr); } -#endif // PLATFORM_ID != PLATFORM_P2 +#endif // !HAL_PLATFORM_RTL872X test(BLE_02_Set_BLE_Device_Name) { int ret; @@ -118,7 +118,7 @@ test(BLE_02_Set_BLE_Device_Name) { assertTrue(getName == defaultName); } -#if PLATFORM_ID != PLATFORM_P2 // P2 doesn't support setting TX power +#if !HAL_PLATFORM_RTL872X // P2 doesn't support setting TX power test(BLE_03_Set_BLE_Tx_Power) { int ret; int8_t getTxPower; @@ -179,7 +179,7 @@ test(BLE_03_Set_BLE_Tx_Power) { assertEqual(ret, 0); assertEqual(getTxPower, 8); } -#endif // PLATFORM_ID != PLATFORM_P2 +#endif // !HAL_PLATFORM_RTL872X test(BLE_04_Select_BLE_Antenna) { #if HAL_PLATFORM_RADIO_ANTENNA_EXTERNAL diff --git a/user/tests/wiring/no_fixture_long_running/pwm.cpp b/user/tests/wiring/no_fixture_long_running/pwm.cpp index 2e16be1e58..5a07faf520 100644 --- a/user/tests/wiring/no_fixture_long_running/pwm.cpp +++ b/user/tests/wiring/no_fixture_long_running/pwm.cpp @@ -34,7 +34,7 @@ const PinMapping pwm_pins[] = { // cause problems if the RGB led is enabled. // PWM HAL also is not interrupt safe and RGB pins are modified in SysTick PIN(D2), PIN(D3), PIN(D4), PIN(D5), PIN(D6), /* PIN(D7), */ PIN(D8), PIN(A0), PIN(A1), PIN(A2), PIN(A3), PIN(A4), PIN(A5) /* , PIN(RGBR), PIN(RGBG), PIN(RGBB) */ -#elif PLATFORM_ID == PLATFORM_P2 +#elif HAL_PLATFORM_RTL872X // double check. Run tests etc PIN(D1), PIN(A2), PIN(A5), PIN(S0), PIN(S1) /* , PIN(RGBR), PIN(RGBG), PIN(RGBB) */ #elif (PLATFORM_ID == PLATFORM_ESOMX) PIN(D0), PIN(D1), PIN(D2), PIN(A3), PIN(A4), PIN(A5), PIN(A6), PIN(TX), PIN(RX), PIN(B2), PIN(B3), PIN(C4), PIN(C5) /* , PIN(RGBR), PIN(RGBG), PIN(RGBB) */ @@ -258,8 +258,9 @@ test(PWM_07_AnalogWriteWithFrequencyOnPinResultsInCorrectAnalogValue) { }); } -// See wiring/pwm/ for P2 fixture PWM tests -#if PLATFORM_ID != PLATFORM_P2 +// FIXME: rtl872x-based platforms don't support pulse in +// See wiring/pwm/ for fixture PWM tests +#if !HAL_PLATFORM_RTL872X test(PWM_08_LowDCAnalogWriteOnPinResultsInCorrectPulseWidth) { for_all_pwm_pins([](hal_pin_t pin, const char* name) { out->printlnf("Pin: %s", name); @@ -725,4 +726,4 @@ test(PWM_12_CompherensiveResolutionFrequency) { assertMoreOrEqual(resolution, 15); }); } -#endif // PLATFORM_ID != PLATFORM_P2 +#endif // !HAL_PLATFORM_RTL872X diff --git a/user/tests/wiring/no_fixture_long_running/servo.cpp b/user/tests/wiring/no_fixture_long_running/servo.cpp index f58d256fee..63543136b8 100644 --- a/user/tests/wiring/no_fixture_long_running/servo.cpp +++ b/user/tests/wiring/no_fixture_long_running/servo.cpp @@ -28,7 +28,7 @@ #include "unit-test/unit-test.h" #if HAL_PLATFORM_GEN == 3 -#if PLATFORM_ID == PLATFORM_P2 || PLATFORM_ID == PLATFORM_ESOMX +#if PLATFORM_ID == PLATFORM_ESOMX || HAL_PLATFORM_RTL872X static const hal_pin_t pin = D1, pin2 = D8; #else static const hal_pin_t pin = A0, pin2 = A1; @@ -89,7 +89,7 @@ test(SERVO_04_WritePulseWidthOnPinResultsInCorrectMicroSeconds) { } // FIXME: P2 doesn't support pulseIn() -#if PLATFORM_ID != PLATFORM_P2 +#if !HAL_PLATFORM_RTL872X test(SERVO_05_DetachDoesntAffectAnotherServoUsingSameTimer) { const int pulseWidth = 2000; // Attach 1st servo @@ -115,4 +115,4 @@ test(SERVO_05_DetachDoesntAffectAnotherServoUsingSameTimer) { servo2.detach(); assertTrue(readPulseWidth > pulseWidth - 50 && readPulseWidth < pulseWidth + 50); } -#endif // PLATFORM_ID != PLATFORM_P2 +#endif // !HAL_PLATFORM_RTL872X diff --git a/user/tests/wiring/no_fixture_long_running/ticks.cpp b/user/tests/wiring/no_fixture_long_running/ticks.cpp index e930942b09..52e1a56382 100644 --- a/user/tests/wiring/no_fixture_long_running/ticks.cpp +++ b/user/tests/wiring/no_fixture_long_running/ticks.cpp @@ -6,7 +6,7 @@ #include #include "random.h" -#if PLATFORM_ID == PLATFORM_P2 +#if HAL_PLATFORM_RTL872X #ifdef AMEBAD_TODO #define __ARMV8MML_REV 0x0000U /*!< ARMV8MML Core Revision */ #define __Vendor_SysTickConfig 0 /*!< Set to 1 if different SysTick Config is used */ @@ -26,7 +26,7 @@ #endif #include /* Use CMSE intrinsics */ #include "core_armv8mml.h" -#endif // PLATFORM_ID == PLATFORM_P2 +#endif // HAL_PLATFORM_RTL872X namespace { diff --git a/user/tests/wiring/no_fixture_long_running/tone.cpp b/user/tests/wiring/no_fixture_long_running/tone.cpp index 0d87d6afeb..8f2e91eadd 100644 --- a/user/tests/wiring/no_fixture_long_running/tone.cpp +++ b/user/tests/wiring/no_fixture_long_running/tone.cpp @@ -27,7 +27,7 @@ #include "tone_hal.h" #include "unit-test/unit-test.h" -#if PLATFORM_ID == PLATFORM_P2 +#if HAL_PLATFORM_RTL872X static const hal_pin_t pin = D1;//pin under test #elif PLATFORM_ID == PLATFORM_ESOMX static const hal_pin_t pin = A3;//pin under test diff --git a/user/tests/wiring/no_fixture_spi/spix.cpp b/user/tests/wiring/no_fixture_spi/spix.cpp index 0faed2e782..836bf2a77e 100644 --- a/user/tests/wiring/no_fixture_spi/spix.cpp +++ b/user/tests/wiring/no_fixture_spi/spix.cpp @@ -42,7 +42,7 @@ test(SPIX_01_SPI_Begin_Without_Argument) assertEqual(info.ss_pin, D8); #elif PLATFORM_ID == PLATFORM_TRACKER assertEqual(info.ss_pin, D7); -#elif PLATFORM_ID == PLATFORM_P2 +#elif HAL_PLATFORM_RTL872X assertEqual(info.ss_pin, S3); #elif PLATFORM_ID == PLATFORM_ESOMX assertEqual(info.ss_pin, A2); @@ -69,7 +69,7 @@ test(SPIX_02_SPI_Begin_With_Ss_Pin) assertEqual(info.ss_pin, D8); #elif PLATFORM_ID == PLATFORM_TRACKER assertEqual(info.ss_pin, D7); -#elif PLATFORM_ID == PLATFORM_P2 +#elif HAL_PLATFORM_RTL872X assertEqual(info.ss_pin, S3); #elif PLATFORM_ID == PLATFORM_ESOMX assertEqual(info.ss_pin, A2); @@ -123,7 +123,7 @@ test(SPIX_03_SPI_Begin_With_Mode) assertEqual(info.ss_pin,D8); #elif PLATFORM_ID == PLATFORM_TRACKER assertEqual(info.ss_pin, D7); -#elif PLATFORM_ID == PLATFORM_P2 +#elif HAL_PLATFORM_RTL872X assertEqual(info.ss_pin, S3); #elif PLATFORM_ID == PLATFORM_ESOMX assertEqual(info.ss_pin, A2); @@ -132,22 +132,17 @@ test(SPIX_03_SPI_Begin_With_Mode) #endif SPI.end(); +#if HAL_PLATFORM_RTL872X || HAL_PLATFORM_NRF52840 memset(&info, 0x00, sizeof(hal_spi_info_t)); + SPI.begin(SPI_MODE_SLAVE); + querySpiInfo(HAL_SPI_INTERFACE1, &info); + assertFalse(info.enabled); + SPI.end(); - // HAL_SPI_INTERFACE1 does not support slave mode on NRF52840 -#if HAL_PLATFORM_RTL872X - // HAL_SPI_INTERFACE1 does not support slave mode on P2 - SPI1.begin(SPI_MODE_SLAVE); - querySpiInfo(HAL_SPI_INTERFACE2, &info); - assertTrue(info.enabled); - assertEqual(info.mode, SPI_MODE_SLAVE); -#if PLATFORM_ID == PLATFORM_P2 - assertEqual(info.ss_pin, D5); #else -#error "Unknown platform!" -#endif - SPI.end(); -#endif // HAL_PLATFORM_RTL872X + #error "Unsupported platform!" +#endif // HAL_PLATFORM_RTL872X || HAL_PLATFORM_NRF52840 + } test(SPIX_04_SPI_Begin_With_Master_Ss_Pin) @@ -167,7 +162,7 @@ test(SPIX_04_SPI_Begin_With_Master_Ss_Pin) assertEqual(info.ss_pin, D8); #elif PLATFORM_ID == PLATFORM_TRACKER assertEqual(info.ss_pin, D7); -#elif PLATFORM_ID == PLATFORM_P2 +#elif HAL_PLATFORM_RTL872X assertEqual(info.ss_pin, S3); #elif PLATFORM_ID == PLATFORM_ESOMX assertEqual(info.ss_pin, A2); @@ -176,6 +171,8 @@ test(SPIX_04_SPI_Begin_With_Master_Ss_Pin) #endif SPI.end(); +#if HAL_PLATFORM_RTL872X || HAL_PLATFORM_NRF52840 + memset(&info, 0x00, sizeof(hal_spi_info_t)); SPI.begin(SPI_MODE_MASTER, D0); @@ -202,6 +199,10 @@ test(SPIX_04_SPI_Begin_With_Master_Ss_Pin) assertEqual(info.mode, SPI_MODE_MASTER); assertEqual(info.ss_pin, 123); SPI.end(); +#else + #error "Unsupported platform!" +#endif // HAL_PLATFORM_RTL872X || HAL_PLATFORM_NRF52840 + } #if Wiring_SPI1 @@ -278,8 +279,7 @@ test(SPIX_07_SPI1_Begin_With_Mode) assertEqual(info.ss_pin, D5); SPI1.end(); - // SPI1 can't work as slave on Tron -#if PLATFORM_ID != PLATFORM_P2 +#if !HAL_PLATFORM_RTL872X memset(&info, 0x00, sizeof(hal_spi_info_t)); SPI1.begin(SPI_MODE_SLAVE); querySpiInfo(HAL_SPI_INTERFACE2, &info); @@ -288,7 +288,7 @@ test(SPIX_07_SPI1_Begin_With_Mode) // D5 is the default SS pin for all platforms assertEqual(info.ss_pin, D5); SPI1.end(); -#endif +#endif // !HAL_PLATFORM_RTL872X } test(SPIX_08_SPI1_Begin_With_Master_Ss_Pin) @@ -335,7 +335,7 @@ test(SPIX_08_SPI1_Begin_With_Master_Ss_Pin) } // SPI1 can't work as slave on Tron -#if PLATFORM_ID != PLATFORM_P2 +#if !HAL_PLATFORM_RTL872X test(SPIX_09_SPI1_Begin_With_Slave_Ss_Pin) { // Just in case @@ -374,7 +374,7 @@ test(SPIX_09_SPI1_Begin_With_Slave_Ss_Pin) assertFalse(info.enabled); SPI1.end(); } -#endif // PLATFORM_ID != PLATFORM_P2 +#endif // !HAL_PLATFORM_RTL872X #endif // Wiring_SPI1 namespace { @@ -404,7 +404,7 @@ constexpr unsigned int SPI_NODMA_OVERHEAD = 15500; // 15.5us ~= 992 clock cycles constexpr unsigned int SPI_DMA_OVERHEAD = SPI_NODMA_OVERHEAD; // Gen 3 always uses DMA underneath #else #error "Unsupported platform" -#endif // HAL_PLATFORM_NRF52840 +#endif // HAL_PLATFORM_RTL872X #if !HAL_PLATFORM_RTL872X using SpixTestLock = SingleThreadedSection; diff --git a/user/tests/wiring/pwm/pwm.cpp b/user/tests/wiring/pwm/pwm.cpp index 5785160aba..bfff52c013 100644 --- a/user/tests/wiring/pwm/pwm.cpp +++ b/user/tests/wiring/pwm/pwm.cpp @@ -43,7 +43,7 @@ struct PinMapping { #define PIN(p) {#p, p} const PinMapping pwm_pins[] = { -#if PLATFORM_ID == PLATFORM_P2 +#if PLATFORM_ID == PLATFORM_P2 || PLATFORM_ID == PLATFORM_TRACKERM PIN(D1), PIN(A2), PIN(A5), PIN(S0), PIN(S1) /* ,PIN(RGBR), PIN(RGBG), PIN(RGBB) */ #else #error "Unsupported platform" diff --git a/user/tests/wiring/sleep20/sleep20.cpp b/user/tests/wiring/sleep20/sleep20.cpp index 1b9676bf6d..d5ded21025 100644 --- a/user/tests/wiring/sleep20/sleep20.cpp +++ b/user/tests/wiring/sleep20/sleep20.cpp @@ -89,7 +89,7 @@ test(02_System_Sleep_Mode_Deep_Without_Wakeup) { } } -#if PLATFORM_ID != PLATFORM_P2 +#if !HAL_PLATFORM_RTL872X test(03_System_Sleep_With_Configuration_Object_Hibernate_Mode_Wakeup_By_D0) { if (phase == 0xbeef0003) { Serial.println(" >> Device enters hibernate mode."); @@ -209,9 +209,9 @@ test(07_System_Sleep_Mode_Deep_Wakeup_By_External_Rtc) { } } #endif // HAL_PLATFORM_EXTERNAL_RTC -#endif // PLATFORM_ID != PLATFORM_P2 +#endif // !HAL_PLATFORM_RTL872X -#if PLATFORM_ID == PLATFORM_P2 +#if HAL_PLATFORM_RTL872X test(08_System_Sleep_With_Configuration_Object_Hibernate_Mode_Wakeup_By_Wkp_Pin) { if (phase == 0xbeef0003) { Serial.println(" >> Device enters hibernate mode."); @@ -333,7 +333,7 @@ test(12_System_Sleep_With_Configuration_Object_Hibernate_Mode_Bypass_Network_Off assertLessOrEqual(exitTime - enterTime, SLEEP_DURATION_S + 1); } } -#endif // PLATFORM_ID == PLATFORM_P2 +#endif // HAL_PLATFORM_RTL872X test(13_System_Sleep_With_Configuration_Object_Stop_Mode_Without_Wakeup) { SystemSleepConfiguration config; @@ -407,7 +407,7 @@ test(17_System_Sleep_With_Configuration_Object_Stop_Mode_Wakeup_By_Rtc) { assertEqual((int)result.wakeupReason(), (int)SystemSleepWakeupReason::BY_RTC); } -#if HAL_PLATFORM_BLE && PLATFORM_ID != PLATFORM_P2 +#if HAL_PLATFORM_BLE && !HAL_PLATFORM_RTL872X test(18_System_Sleep_With_Configuration_Object_Stop_Mode_Wakeup_By_Ble) { Serial.println(" >> Device enters stop mode. Please reconnect serial after device being connected by BLE Central."); Serial.println(" >> Press any key now"); @@ -430,7 +430,7 @@ test(18_System_Sleep_With_Configuration_Object_Stop_Mode_Wakeup_By_Ble) { BLE.stopAdvertising(); } -#endif // HAL_PLATFORM_BLE && PLATFORM_ID != PLATFORM_P2 +#endif // HAL_PLATFORM_BLE && !HAL_PLATFORM_RTL872X test(19_System_Sleep_Mode_Stop_Wakeup_By_D0) { Serial.println(" >> Device enters stop mode. Please reconnect serial after you have a rising edge on D0."); @@ -508,7 +508,7 @@ test(22_System_Sleep_With_Configuration_Object_Ultra_Low_Power_Mode_Wakeup_By_Rt assertEqual((int)result.wakeupReason(), (int)SystemSleepWakeupReason::BY_RTC); } -#if PLATFORM_ID != PLATFORM_P2 +#if !HAL_PLATFORM_RTL872X #if HAL_PLATFORM_BLE test(23_System_Sleep_With_Configuration_Object_Ultra_Low_Power_Mode_Wakeup_By_Ble) { @@ -725,7 +725,7 @@ test(31_System_Sleep_With_Configuration_Object_Ultra_Low_Power_Mode_Wakeup_By_Wi } #endif // HAL_PLATFORM_WIFI -#endif // PLATFORM_ID != PLATFORM_P2 +#endif // !HAL_PLATFORM_RTL872X test(32_System_Sleep_With_Configuration_Object_Execution_Time_Prepare) { /* This test should only be run with threading disabled */ diff --git a/user/tests/wiring/spi_master_slave/spi_master/spi_master.cpp b/user/tests/wiring/spi_master_slave/spi_master/spi_master.cpp index b1f6590700..a89b31e1c8 100644 --- a/user/tests/wiring/spi_master_slave/spi_master/spi_master.cpp +++ b/user/tests/wiring/spi_master_slave/spi_master/spi_master.cpp @@ -19,7 +19,7 @@ #endif // #ifndef USE_CS -#if (PLATFORM_ID == PLATFORM_P2) +#if HAL_PLATFORM_RTL872X #if (USE_SPI == 0 || USE_SPI == 255) // default to SPI #define MY_SPI SPI @@ -87,7 +87,7 @@ #error "Unsupported platform" -#endif // #if PLATFORM_P2 +#endif // #if HAL_PLATFORM_RTL872X #if defined(_SPI) && (USE_CS != 255) @@ -187,7 +187,7 @@ static void SPI_Master_Configure() MY_SPI.begin(MY_CS); // Clock dummy byte just in case - if (PLATFORM_ID != PLATFORM_P2) { // Since SPI is enabled, the dummy byte will generate gabage data in the fifo on P2 + if (!HAL_PLATFORM_RTL872X) { // Since SPI is enabled, the dummy byte will generate gabage data in the fifo on P2 (void)MY_SPI.transfer(0xff); } } diff --git a/user/tests/wiring/spi_master_slave/spi_slave/spi_slave.cpp b/user/tests/wiring/spi_master_slave/spi_slave/spi_slave.cpp index 65f21751b8..7ef5615e36 100644 --- a/user/tests/wiring/spi_master_slave/spi_slave/spi_slave.cpp +++ b/user/tests/wiring/spi_master_slave/spi_slave/spi_slave.cpp @@ -15,7 +15,7 @@ #error Define USE_CS #endif // #ifndef USE_CS -#if (PLATFORM_ID == PLATFORM_P2) +#if HAL_PLATFORM_RTL872X #if (USE_SPI == 0 || USE_SPI == 255) // default to SPI #error "SPI not supported as slave for p2" @@ -81,7 +81,7 @@ #endif // #if (PLATFORM_ID == PLATFORM_ASOM) || (PLATFORM_ID == PLATFORM_BSOM) || (PLATFORM_ID == PLATFORM_B5SOM) -#endif // HAL_PLATFORM_NRF52840 +#endif // HAL_PLATFORM_RTL872X #if defined(_SPI) && (USE_CS != 255) #pragma message "Overriding default CS selection" diff --git a/wiring_globals/src/spark_wiring_gpio.cpp b/wiring_globals/src/spark_wiring_gpio.cpp index 81e8e880b1..ad344adee2 100644 --- a/wiring_globals/src/spark_wiring_gpio.cpp +++ b/wiring_globals/src/spark_wiring_gpio.cpp @@ -194,7 +194,7 @@ int32_t digitalRead(hal_pin_t pin) */ int32_t analogRead(hal_pin_t pin) { -#if PLATFORM_ID != PLATFORM_P2 +#if !HAL_PLATFORM_RTL872X // Allow people to use 0-7 to define analog pins by checking to see if the values are too low. #if defined(FIRST_ANALOG_PIN) && FIRST_ANALOG_PIN > 0 if(pin < FIRST_ANALOG_PIN)