From 7c8394e709f244dda9d1d9c9ee53d3e53f4f2e3e Mon Sep 17 00:00:00 2001 From: Jan-Henrik Bruhn Date: Thu, 2 Sep 2021 15:40:19 +0200 Subject: [PATCH 1/5] Add support for nrf52833 based module --- code/b-parasite/Makefile | 66 +++++---- code/b-parasite/b_parasite_gcc_nrf52833.ld | 130 ++++++++++++++++++ ...cc_nrf52.ld => b_parasite_gcc_nrf52840.ld} | 0 3 files changed, 170 insertions(+), 26 deletions(-) create mode 100644 code/b-parasite/b_parasite_gcc_nrf52833.ld rename code/b-parasite/{b_parasite_gcc_nrf52.ld => b_parasite_gcc_nrf52840.ld} (100%) diff --git a/code/b-parasite/Makefile b/code/b-parasite/Makefile index 5643a60..82040ca 100644 --- a/code/b-parasite/Makefile +++ b/code/b-parasite/Makefile @@ -1,17 +1,40 @@ +# Supported platforms: +# * E73_2G4M08S1C (nrf2480, default) +# * E73_2G4M08S1E (nrf2833) +PLATFORM ?= E73_2G4M08S1C + +ifeq ($(PLATFORM), E73_2G4M08S1E) + SRC_FILES += \ + $(SDK_ROOT)/modules/nrfx/mdk/gcc_startup_nrf52833.S \ + $(SDK_ROOT)/modules/nrfx/mdk/system_nrf52833.c + TARGETS := nrf52833_xxaa + CFLAGS += -DNRF52833_XXAA + ASMFLAGS += -DNRF52833_XXAA + LINKER_SCRIPT := b_parasite_gcc_nrf52833.ld +HEAP_SIZE := 2048 +STACK_SIZE := 2048 +else ifeq ($(PLATFORM), E73_2G4M08S1C) + SRC_FILES += \ + $(SDK_ROOT)/modules/nrfx/mdk/gcc_startup_nrf52840.S \ + $(SDK_ROOT)/modules/nrfx/mdk/system_nrf52840.c + TARGETS := nrf52840_xxaa + CFLAGS += -DNRF52840_XXAA + ASMFLAGS += -DNRF52840_XXAA + LINKER_SCRIPT := b_parasite_gcc_nrf52840.ld +HEAP_SIZE := 8192 +STACK_SIZE := 8192 +endif + + PROJECT_NAME := ble_app_beacon_pca10056_s140 -TARGETS := nrf52840_xxaa OUTPUT_DIRECTORY := _build # Set SDK_ROOT via env vars. # SDK_ROOT := ../../../.././.. PROJ_DIR := ./src -$(OUTPUT_DIRECTORY)/nrf52840_xxaa.out: \ - LINKER_SCRIPT := b_parasite_gcc_nrf52.ld - # Source files common to all targets SRC_FILES += \ - $(SDK_ROOT)/modules/nrfx/mdk/gcc_startup_nrf52840.S \ $(SDK_ROOT)/components/libraries/log/src/nrf_log_backend_rtt.c \ $(SDK_ROOT)/components/libraries/log/src/nrf_log_backend_serial.c \ $(SDK_ROOT)/components/libraries/log/src/nrf_log_backend_uart.c \ @@ -39,8 +62,6 @@ SRC_FILES += \ $(SDK_ROOT)/components/libraries/experimental_section_vars/nrf_section_iter.c \ $(SDK_ROOT)/components/libraries/sortlist/nrf_sortlist.c \ $(SDK_ROOT)/components/libraries/strerror/nrf_strerror.c \ - $(SDK_ROOT)/modules/nrfx/mdk/system_nrf52840.c \ - $(SDK_ROOT)/components/boards/boards.c \ $(SDK_ROOT)/integration/nrfx/legacy/nrf_drv_clock.c \ $(SDK_ROOT)/integration/nrfx/legacy/nrf_drv_twi.c \ $(SDK_ROOT)/modules/nrfx/soc/nrfx_atomic.c \ @@ -51,7 +72,6 @@ SRC_FILES += \ $(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_twi.c \ $(SDK_ROOT)/modules/nrfx/drivers/src/prs/nrfx_prs.c \ $(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_pwm.c \ - $(SDK_ROOT)/components/libraries/bsp/bsp.c \ $(PROJ_DIR)/main.c \ $(SDK_ROOT)/external/segger_rtt/SEGGER_RTT.c \ $(SDK_ROOT)/external/segger_rtt/SEGGER_RTT_Syscalls_GCC.c \ @@ -90,7 +110,6 @@ INC_FOLDERS += \ $(SDK_ROOT)/components/libraries/gpiote \ $(SDK_ROOT)/components/libraries/bootloader/ble_dfu \ $(SDK_ROOT)/components/nfc/ndef/connection_handover/common \ - $(SDK_ROOT)/components/boards \ $(SDK_ROOT)/components/nfc/ndef/generic/record \ $(SDK_ROOT)/components/ble/ble_advertising \ $(SDK_ROOT)/external/utf_converter \ @@ -108,7 +127,6 @@ INC_FOLDERS += \ $(SDK_ROOT)/components/ble/common \ $(SDK_ROOT)/components/ble/ble_services/ble_lls \ $(SDK_ROOT)/components/nfc/platform \ - $(SDK_ROOT)/components/libraries/bsp \ $(SDK_ROOT)/components/nfc/ndef/connection_handover/ac_rec \ $(SDK_ROOT)/components/ble/ble_services/ble_bas \ $(SDK_ROOT)/components/libraries/mpu \ @@ -203,7 +221,7 @@ INC_FOLDERS += \ LIB_FILES += \ # Optimization flags -OPT = -O3 -g3 +OPT = -O0 -g3 # Uncomment the line below to enable link time optimization #OPT += -flto @@ -211,20 +229,18 @@ OPT = -O3 -g3 CFLAGS += $(OPT) CFLAGS += -DAPP_TIMER_V2 CFLAGS += -DAPP_TIMER_V2_RTC1_ENABLED -CFLAGS += -DBOARD_PCA10056 CFLAGS += -DCONFIG_GPIO_AS_PINRESET CFLAGS += -DFLOAT_ABI_HARD -CFLAGS += -DNRF52840_XXAA CFLAGS += -DNRF_SD_BLE_API_VERSION=7 CFLAGS += -DS140 CFLAGS += -DSOFTDEVICE_PRESENT -CFLAGS += -DEBUG +CFLAGS += -DDEBUG # Setting -DDEBUG prints info via JLkinkRTTLogger, but hides the stack trace # when debugging with VSCode's Cortex Debug extension. # CFLAGS += -DDEBUG CFLAGS += -mcpu=cortex-m4 CFLAGS += -mthumb -mabi=aapcs -CFLAGS += -Wall -Werror +CFLAGS += -Wall -Werror -Wno-maybe-uninitialized CFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16 # keep every function in a separate section, this allows linker to discard unused ones CFLAGS += -ffunction-sections -fdata-sections -fno-strict-aliasing @@ -239,10 +255,8 @@ ASMFLAGS += -mthumb -mabi=aapcs ASMFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16 ASMFLAGS += -DAPP_TIMER_V2 ASMFLAGS += -DAPP_TIMER_V2_RTC1_ENABLED -ASMFLAGS += -DBOARD_PCA10056 ASMFLAGS += -DCONFIG_GPIO_AS_PINRESET ASMFLAGS += -DFLOAT_ABI_HARD -ASMFLAGS += -DNRF52840_XXAA ASMFLAGS += -DNRF_SD_BLE_API_VERSION=7 ASMFLAGS += -DS140 ASMFLAGS += -DSOFTDEVICE_PRESENT @@ -257,10 +271,10 @@ LDFLAGS += -Wl,--gc-sections # use newlib in nano version LDFLAGS += --specs=nano.specs -nrf52840_xxaa: CFLAGS += -D__HEAP_SIZE=8192 -nrf52840_xxaa: CFLAGS += -D__STACK_SIZE=8192 -nrf52840_xxaa: ASMFLAGS += -D__HEAP_SIZE=8192 -nrf52840_xxaa: ASMFLAGS += -D__STACK_SIZE=8192 +$(TARGETS): CFLAGS += -D__HEAP_SIZE=$(HEAP_SIZE) +$(TARGETS): CFLAGS += -D__STACK_SIZE=$(STACK_SIZE) +$(TARGETS): ASMFLAGS += -D__HEAP_SIZE=$(HEAP_SIZE) +$(TARGETS): ASMFLAGS += -D__STACK_SIZE=$(STACK_SIZE) # Add standard libraries at the very end of the linker input, after all objects # that may need symbols provided by these libraries. @@ -270,12 +284,12 @@ LIB_FILES += -lc -lnosys -lm .PHONY: default help # Default target - first one defined -default: nrf52840_xxaa +default: $(TARGETS) # Print all targets that can be built help: @echo following targets are available: - @echo nrf52840_xxaa + @echo $(TARGETS) @echo flash_softdevice @echo sdk_config - starting external tool for editing sdk_config.h @echo flash - flashing binary @@ -291,8 +305,8 @@ $(foreach target, $(TARGETS), $(call define_target, $(target))) # Flash the program flash: default - @echo Flashing: $(OUTPUT_DIRECTORY)/nrf52840_xxaa.hex - nrfjprog -f nrf52 --program $(OUTPUT_DIRECTORY)/nrf52840_xxaa.hex --sectorerase + @echo Flashing: $(OUTPUT_DIRECTORY)/$(TARGETS).hex + nrfjprog -f nrf52 --program $(OUTPUT_DIRECTORY)/$(TARGETS).hex --sectorerase nrfjprog -f nrf52 --reset # Flash softdevice @@ -319,4 +333,4 @@ lint: .PHONY: fix lint-fix: - find src -iname *.h -o -iname *.c | xargs clang-format -i \ No newline at end of file + find src -iname *.h -o -iname *.c | xargs clang-format -i diff --git a/code/b-parasite/b_parasite_gcc_nrf52833.ld b/code/b-parasite/b_parasite_gcc_nrf52833.ld new file mode 100644 index 0000000..9bd722d --- /dev/null +++ b/code/b-parasite/b_parasite_gcc_nrf52833.ld @@ -0,0 +1,130 @@ +/* Linker script to configure memory regions. */ + +SEARCH_DIR(.) +GROUP(-lgcc -lc -lnosys) + +MEMORY +{ + FLASH (rx) : ORIGIN = 0x27000, LENGTH = 0x59000 + RAM (rwx) : ORIGIN = 0x20002300, LENGTH = 0x1dd00 +} + +SECTIONS +{ +} + +SECTIONS +{ + . = ALIGN(4); + .mem_section_dummy_ram : + { + } + .cli_sorted_cmd_ptrs : + { + PROVIDE(__start_cli_sorted_cmd_ptrs = .); + KEEP(*(.cli_sorted_cmd_ptrs)) + PROVIDE(__stop_cli_sorted_cmd_ptrs = .); + } > RAM + .fs_data : + { + PROVIDE(__start_fs_data = .); + KEEP(*(.fs_data)) + PROVIDE(__stop_fs_data = .); + } > RAM + .log_dynamic_data : + { + PROVIDE(__start_log_dynamic_data = .); + KEEP(*(SORT(.log_dynamic_data*))) + PROVIDE(__stop_log_dynamic_data = .); + } > RAM + .log_filter_data : + { + PROVIDE(__start_log_filter_data = .); + KEEP(*(SORT(.log_filter_data*))) + PROVIDE(__stop_log_filter_data = .); + } > RAM + +} INSERT AFTER .data; + +SECTIONS +{ + .mem_section_dummy_rom : + { + } + .sdh_ble_observers : + { + PROVIDE(__start_sdh_ble_observers = .); + KEEP(*(SORT(.sdh_ble_observers*))) + PROVIDE(__stop_sdh_ble_observers = .); + } > FLASH + .sdh_soc_observers : + { + PROVIDE(__start_sdh_soc_observers = .); + KEEP(*(SORT(.sdh_soc_observers*))) + PROVIDE(__stop_sdh_soc_observers = .); + } > FLASH + .sdh_req_observers : + { + PROVIDE(__start_sdh_req_observers = .); + KEEP(*(SORT(.sdh_req_observers*))) + PROVIDE(__stop_sdh_req_observers = .); + } > FLASH + .sdh_state_observers : + { + PROVIDE(__start_sdh_state_observers = .); + KEEP(*(SORT(.sdh_state_observers*))) + PROVIDE(__stop_sdh_state_observers = .); + } > FLASH + .sdh_stack_observers : + { + PROVIDE(__start_sdh_stack_observers = .); + KEEP(*(SORT(.sdh_stack_observers*))) + PROVIDE(__stop_sdh_stack_observers = .); + } > FLASH + .nrf_queue : + { + PROVIDE(__start_nrf_queue = .); + KEEP(*(.nrf_queue)) + PROVIDE(__stop_nrf_queue = .); + } > FLASH + .nrf_balloc : + { + PROVIDE(__start_nrf_balloc = .); + KEEP(*(.nrf_balloc)) + PROVIDE(__stop_nrf_balloc = .); + } > FLASH + .cli_command : + { + PROVIDE(__start_cli_command = .); + KEEP(*(.cli_command)) + PROVIDE(__stop_cli_command = .); + } > FLASH + .crypto_data : + { + PROVIDE(__start_crypto_data = .); + KEEP(*(SORT(.crypto_data*))) + PROVIDE(__stop_crypto_data = .); + } > FLASH + .pwr_mgmt_data : + { + PROVIDE(__start_pwr_mgmt_data = .); + KEEP(*(SORT(.pwr_mgmt_data*))) + PROVIDE(__stop_pwr_mgmt_data = .); + } > FLASH + .log_const_data : + { + PROVIDE(__start_log_const_data = .); + KEEP(*(SORT(.log_const_data*))) + PROVIDE(__stop_log_const_data = .); + } > FLASH + .log_backends : + { + PROVIDE(__start_log_backends = .); + KEEP(*(SORT(.log_backends*))) + PROVIDE(__stop_log_backends = .); + } > FLASH + +} INSERT AFTER .text + + +INCLUDE "nrf_common.ld" diff --git a/code/b-parasite/b_parasite_gcc_nrf52.ld b/code/b-parasite/b_parasite_gcc_nrf52840.ld similarity index 100% rename from code/b-parasite/b_parasite_gcc_nrf52.ld rename to code/b-parasite/b_parasite_gcc_nrf52840.ld From 1aa07b4d743e7bf390695db4230cd8b75100d8dc Mon Sep 17 00:00:00 2001 From: Jan-Henrik Bruhn Date: Thu, 2 Sep 2021 15:45:33 +0200 Subject: [PATCH 2/5] Add platforms to readme --- code/b-parasite/README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/code/b-parasite/README.md b/code/b-parasite/README.md index 06aa32f..99bda17 100644 --- a/code/b-parasite/README.md +++ b/code/b-parasite/README.md @@ -39,3 +39,23 @@ Sensor data is encoded in unsigned 16 bits (2 bytes), and whenever multiple | 6-7 | Relative air humidity, scaled from 0 (0%) to 0xffff (100%) | | 8-9 | Soil moisture, scaled from from 0 (0%) to 0xffff (100%) | | 10-15 | b-parasite's own MAC address, big-endian format | + +# Supported Modules + +This code supports two E73 modules: + * E73-2G4M08S1C (nrf2480, default) + * E73-2G4M08S1E (nrf2833) + +To choose for which one you want to compile, just pass PLATFORM as an env variable to make, and set it to the platform you want to use. For example, to compile for E73-2G4M08S1E: + + +```bash +SDK_ROOT=<...> PLATFORM=E73_2G4M08S1E make +``` + +and vice-cerase for E73-2G4M08S1C, although that platform will be chosen as default anyways: + + +```bash +SDK_ROOT=<...> PLATFORM=E73_2G4M08S1C make +``` From da049fd8ad23533ad04b7cf9551529ef58485736 Mon Sep 17 00:00:00 2001 From: Jan-Henrik Bruhn Date: Thu, 2 Sep 2021 15:48:46 +0200 Subject: [PATCH 3/5] Set optimization back to previous value --- code/b-parasite/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/b-parasite/Makefile b/code/b-parasite/Makefile index 82040ca..239e232 100644 --- a/code/b-parasite/Makefile +++ b/code/b-parasite/Makefile @@ -221,7 +221,7 @@ INC_FOLDERS += \ LIB_FILES += \ # Optimization flags -OPT = -O0 -g3 +OPT = -O3 -g3 # Uncomment the line below to enable link time optimization #OPT += -flto From 683cd692ae6dfe0432fe1423c3d7b8094a7f2ad2 Mon Sep 17 00:00:00 2001 From: Jan-Henrik Bruhn Date: Thu, 2 Sep 2021 19:46:10 +0200 Subject: [PATCH 4/5] Fix indentation and default value for PLATFORM --- code/b-parasite/Makefile | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/code/b-parasite/Makefile b/code/b-parasite/Makefile index 239e232..72af3b9 100644 --- a/code/b-parasite/Makefile +++ b/code/b-parasite/Makefile @@ -1,28 +1,29 @@ # Supported platforms: # * E73_2G4M08S1C (nrf2480, default) # * E73_2G4M08S1E (nrf2833) -PLATFORM ?= E73_2G4M08S1C +# note: the missing whitespace after the = is on purpose here +PLATFORM ?=E73_2G4M08S1C -ifeq ($(PLATFORM), E73_2G4M08S1E) - SRC_FILES += \ +ifeq ($(PLATFORM),E73_2G4M08S1E) + SRC_FILES := \ $(SDK_ROOT)/modules/nrfx/mdk/gcc_startup_nrf52833.S \ $(SDK_ROOT)/modules/nrfx/mdk/system_nrf52833.c TARGETS := nrf52833_xxaa CFLAGS += -DNRF52833_XXAA ASMFLAGS += -DNRF52833_XXAA LINKER_SCRIPT := b_parasite_gcc_nrf52833.ld -HEAP_SIZE := 2048 -STACK_SIZE := 2048 -else ifeq ($(PLATFORM), E73_2G4M08S1C) - SRC_FILES += \ + HEAP_SIZE := 2048 + STACK_SIZE := 2048 +else ifeq ($(PLATFORM),E73_2G4M08S1C) + SRC_FILES := \ $(SDK_ROOT)/modules/nrfx/mdk/gcc_startup_nrf52840.S \ $(SDK_ROOT)/modules/nrfx/mdk/system_nrf52840.c TARGETS := nrf52840_xxaa CFLAGS += -DNRF52840_XXAA ASMFLAGS += -DNRF52840_XXAA LINKER_SCRIPT := b_parasite_gcc_nrf52840.ld -HEAP_SIZE := 8192 -STACK_SIZE := 8192 + HEAP_SIZE := 8192 + STACK_SIZE := 8192 endif From 05efd7474c6e554da6ac99793eb59282537e46f4 Mon Sep 17 00:00:00 2001 From: Jan-Henrik Bruhn Date: Thu, 2 Sep 2021 20:02:24 +0200 Subject: [PATCH 5/5] Fix typo in code readme --- code/b-parasite/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/b-parasite/README.md b/code/b-parasite/README.md index 99bda17..185a8bb 100644 --- a/code/b-parasite/README.md +++ b/code/b-parasite/README.md @@ -53,7 +53,7 @@ To choose for which one you want to compile, just pass PLATFORM as an env variab SDK_ROOT=<...> PLATFORM=E73_2G4M08S1E make ``` -and vice-cerase for E73-2G4M08S1C, although that platform will be chosen as default anyways: +and vice-versa for E73-2G4M08S1C, although that platform will be chosen as default anyways: ```bash