<commit_before>################################################################################
## Makefile for compiling apps against the nRF51 SDK
################################################################################

################################################################################
## Usage
##
## In your application Makefile, set the following variables:
##   - APPLICATION_SRCS   : List of all .c files to be compiled.
##   - LIBRARY_PATHS      : List of directories with .h files
##   - SOURCE_PATHS       : List of directories with .c files
##   - SOFTDEVICE_MODEL   : s110 | s120 | s130 | s210 | s310 | or do not set for no softdevice
##
## Optional
##   - SOFTDEVICE_VERSION : Full version number of the softdevice.
##   - SOFTDEVICE         : Path to the softdevice to use
##   - START_CODE         : .s file to execute first
##   - SYSTEM_FILE        : Base nRF .c file.
##   - NRF_MODEL          : nrf51 | nrf52  : Also set by the NRF_IC used
##   - NRF_IC             : nrf51422 | nrf51802 | nrf51822 | nrf52832 | nrf52840  
##   - BOARD              : Hardware board being used. Will get set as #define.
##   - RAM_KB             : Size of RAM on chip
##   - FLASH_KB           : Size of flash on chip
##   - SDK_VERSION        : Major version number of the SDK to use. Defaults to 10 for nrf51, 12 for nrf52
##   - GDB_PORT_NUMBER    : Defaults to 2331
##
##
## Then at the end of the Makefile do something like:
##    NRF_BASE_PATH ?= ../../nrf5x-base
##    include $(NRF_BASE_PATH)/make/Makefile

# Helper for relative paths
BASE_DIR := $(dir $(lastword $(MAKEFILE_LIST)))..

# Setup the compilers to use
TOOLCHAIN_PREFIX ?= arm-none-eabi
AS      = $(TOOLCHAIN_PATH)$(TOOLCHAIN_PREFIX)-as
CC      = $(TOOLCHAIN_PATH)$(TOOLCHAIN_PREFIX)-gcc
LD      = $(TOOLCHAIN_PATH)$(TOOLCHAIN_PREFIX)-gcc
OBJCOPY = $(TOOLCHAIN_PATH)$(TOOLCHAIN_PREFIX)-objcopy
OBJDUMP = $(TOOLCHAIN_PATH)$(TOOLCHAIN_PREFIX)-objdump
SIZE    = $(TOOLCHAIN_PATH)$(TOOLCHAIN_PREFIX)-size
GDB     = $(TOOLCHAIN_PATH)$(TOOLCHAIN_PREFIX)-gdb

# Set default board
BOARD ?= BOARD_NULL

# TODO: Guess NRF_MODEL from famous BOARD


# ---- Guess/Check NRF_MODEL from NRF_IC (if NRF_IC defined)
ifdef NRF_IC
  #if NRF_IC == nrf51422 or nrf51802 or nrf51822
  ifneq (,$(filter $(NRF_IC),nrf51422 nrf51802 nrf51822))
    ifdef NRF_MODEL
      ifneq ($(NRF_MODEL), nrf51)
        $(error NRF_MODEL $(NRF_MODEL) is not valid for NRF_IC $(NRF_IC))
      endif
    endif
    NRF_MODEL = nrf51
  #else if NRF_IC == nrf52832 or nrf52840
  else ifneq (,$(filter $(NRF_IC),nrf52832 nrf52840))
    ifdef NRF_MODEL
      ifneq ($(NRF_MODEL), nrf52)
        $(error NRF_MODEL $(NRF_MODEL) is not valid for NRF_IC $(NRF_IC))
      endif
    endif
    NRF_MODEL = nrf52
  endif
endif

# ---- NRF_MODEL Default to nrf51
NRF_MODEL ?= nrf51

# ---- Force NRF_MODEL for OLD SDK
ifneq (,$(filter $(SDK_VERSION),9 10))
  ifneq ($(NRF_MODEL), nrf51)
    $(error NRF_MODEL $(NRF_MODEL) is not valid for SDK_VERSION $(SDK_VERSION))
  endif
  NRF_MODEL = nrf51
endif

# --- NRF_IC: Default to nrf51822 for nrf51
ifeq ($(NRF_MODEL), nrf51)
  NRF_IC    ?= nrf51822
# --- NRF_IC: Default to nrf52832 for nrf52
else ifeq ($(NRF_MODEL), nrf52)
  NRF_IC    ?= nrf52832
endif
  

# ---- Set hardware memory sizes
ifneq (,$(filter $(NRF_IC),nrf51422 nrf51802 nrf51822))
  RAM_KB   ?= 16# can be also 32
  FLASH_KB ?= 256# can be also 128
else ifeq ($(NRF_IC), nrf52832)
  RAM_KB   ?= 64
  FLASH_KB ?= 512
else ifeq ($(NRF_IC), nrf52840)
  RAM_KB   ?= 256
  FLASH_KB ?= 1024
endif

# ---- Set SDK if not SET
# Default to SDK 10 for nrf51
ifeq ($(NRF_MODEL), nrf51)
  SDK_VERSION ?= 10
# Default to SDK 12 for nrf52
else ifeq ($(NRF_MODEL), nrf52)
  SDK_VERSION ?= 12
endif
	

# Set this for using GDB
GDB_PORT_NUMBER ?= 2331


#------ Now select/check SOFTDEVICE version if used (depending SDK version)
ifdef SOFTDEVICE_MODEL
	# SDK 9 or 10
	ifneq (,$(filter $(SDK_VERSION),9 10))
		WAITED_NRF_MODEL = nrf51
		ifeq ($(SOFTDEVICE_MODEL), s110)
		    USE_BLE = 1
		    WAITED_SOFTDEVICE_VERSION ?= 8.0.0
		else ifeq ($(SOFTDEVICE_MODEL), s120)
		    USE_BLE = 1
		    WAITED_SOFTDEVICE_VERSION ?= 2.1.0
		else ifeq ($(SOFTDEVICE_MODEL), s130)
		    USE_BLE = 1
		    WAITED_SOFTDEVICE_VERSION ?= 1.0.0
		else ifeq ($(SOFTDEVICE_MODEL), s210)
			# ANT only softDevice
		    WAITED_SOFTDEVICE_VERSION ?= 5.0.0
		else ifeq ($(SOFTDEVICE_MODEL), s310)
		    USE_BLE = 1
		    WAITED_SOFTDEVICE_VERSION ?= 3.0.0
		endif
	endif
	
	# SDK 11
	ifeq ($(SDK_VERSION), 11)
		ifeq ($(SOFTDEVICE_MODEL), s130)
			USE_BLE = 1
			WAITED_SOFTDEVICE_VERSION ?= 2.0.0
			WAITED_NRF_MODEL = nrf51
		else ifeq ($(SOFTDEVICE_MODEL), s132)
			USE_BLE = 1
			SOFTDEVICE_VERSION ?= 2.0.0
		else ifeq ($(SOFTDEVICE_MODEL), s212)
			# ANT only softDevice
			SOFTDEVICE_VERSION ?= 0.9.1
			WAITED_NRF_MODEL = nrf52
		else ifeq ($(SOFTDEVICE_MODEL), s332)
			USE_BLE = 1
			SOFTDEVICE_VERSION ?= 0.9.1
			WAITED_NRF_MODEL = nrf52
		endif
	endif
	
	# SDK 12
	ifeq ($(SDK_VERSION), 12)
		ifeq ($(SOFTDEVICE_MODEL), s130)
			USE_BLE = 1
			WAITED_SOFTDEVICE_VERSION ?= 2.0.1
			WAITED_NRF_MODEL = nrf51
		else ifeq ($(SOFTDEVICE_MODEL), s132)
			USE_BLE = 1
			SOFTDEVICE_VERSION ?= 3.0.0
		else ifeq ($(SOFTDEVICE_MODEL), s212)
			# ANT only softDevice
			SOFTDEVICE_VERSION ?= 2.0.0
			WAITED_NRF_MODEL = nrf52
		else ifeq ($(SOFTDEVICE_MODEL), s332)
			USE_BLE = 1
			SOFTDEVICE_VERSION ?= 2.0.0
			WAITED_NRF_MODEL = nrf52
		endif
	endif

	SOFTDEVICE_VERSION ?= WAITED_SOFTDEVICE_VERSION
    ifneq ($(SOFTDEVICE_VERSION), WAITED_SOFTDEVICE_VERSION)
        $(error FOR SDK$(SDK_VERSION) Supported SoftDevice Version for $(SOFTDEVICE_MODEL) is $(WAITED_SOFTDEVICE_VERSION))
    endif
    
    ifneq ($(WAITED_NRF_MODEL), $(NRF_MODEL))
        $(error SoftDevice $(SOFTDEVICE_MODEL) is only compatible with $(WAITED_NRF_MODEL))
    endif
    
endif // ifdef SOFTDEVICE_MODEL


# Print some helpful info about what the user is compiling for
space :=
space +=
$(info BUILD OPTIONS:)
$(info $(space) SoftDevice  $(SOFTDEVICE_MODEL))
$(info $(space) SDK         $(SDK_VERSION))
$(info $(space) nRF         $(NRF_IC))
$(info $(space) RAM         $(RAM_KB) kB)
$(info $(space) FLASH       $(FLASH_KB) kB)
$(info $(space) Board       $(BOARD))<commit_msg>Resolve bug in soft device version check<commit_after>################################################################################
## Makefile for compiling apps against the nRF51 SDK
################################################################################

################################################################################
## Usage
##
## In your application Makefile, set the following variables:
##   - APPLICATION_SRCS   : List of all .c files to be compiled.
##   - LIBRARY_PATHS      : List of directories with .h files
##   - SOURCE_PATHS       : List of directories with .c files
##   - SOFTDEVICE_MODEL   : s110 | s120 | s130 | s210 | s310 | or do not set for no softdevice
##
## Optional
##   - SOFTDEVICE_VERSION : Full version number of the softdevice.
##   - SOFTDEVICE         : Path to the softdevice to use
##   - START_CODE         : .s file to execute first
##   - SYSTEM_FILE        : Base nRF .c file.
##   - NRF_MODEL          : nrf51 | nrf52  : Also set by the NRF_IC used
##   - NRF_IC             : nrf51422 | nrf51802 | nrf51822 | nrf52832 | nrf52840  
##   - BOARD              : Hardware board being used. Will get set as #define.
##   - RAM_KB             : Size of RAM on chip
##   - FLASH_KB           : Size of flash on chip
##   - SDK_VERSION        : Major version number of the SDK to use. Defaults to 10 for nrf51, 12 for nrf52
##   - GDB_PORT_NUMBER    : Defaults to 2331
##
##
## Then at the end of the Makefile do something like:
##    NRF_BASE_PATH ?= ../../nrf5x-base
##    include $(NRF_BASE_PATH)/make/Makefile

# Helper for relative paths
BASE_DIR := $(dir $(lastword $(MAKEFILE_LIST)))..

# Setup the compilers to use
TOOLCHAIN_PREFIX ?= arm-none-eabi
AS      = $(TOOLCHAIN_PATH)$(TOOLCHAIN_PREFIX)-as
CC      = $(TOOLCHAIN_PATH)$(TOOLCHAIN_PREFIX)-gcc
LD      = $(TOOLCHAIN_PATH)$(TOOLCHAIN_PREFIX)-gcc
OBJCOPY = $(TOOLCHAIN_PATH)$(TOOLCHAIN_PREFIX)-objcopy
OBJDUMP = $(TOOLCHAIN_PATH)$(TOOLCHAIN_PREFIX)-objdump
SIZE    = $(TOOLCHAIN_PATH)$(TOOLCHAIN_PREFIX)-size
GDB     = $(TOOLCHAIN_PATH)$(TOOLCHAIN_PREFIX)-gdb

# Set default board
BOARD ?= BOARD_NULL

# TODO: Guess NRF_MODEL from famous BOARD


# ---- Guess/Check NRF_MODEL from NRF_IC (if NRF_IC defined)
ifdef NRF_IC
  #if NRF_IC == nrf51422 or nrf51802 or nrf51822
  ifneq (,$(filter $(NRF_IC),nrf51422 nrf51802 nrf51822))
    ifdef NRF_MODEL
      ifneq ($(NRF_MODEL), nrf51)
        $(error NRF_MODEL $(NRF_MODEL) is not valid for NRF_IC $(NRF_IC))
      endif
    endif
    NRF_MODEL = nrf51
  #else if NRF_IC == nrf52832 or nrf52840
  else ifneq (,$(filter $(NRF_IC),nrf52832 nrf52840))
    ifdef NRF_MODEL
      ifneq ($(NRF_MODEL), nrf52)
        $(error NRF_MODEL $(NRF_MODEL) is not valid for NRF_IC $(NRF_IC))
      endif
    endif
    NRF_MODEL = nrf52
  endif
endif

# ---- NRF_MODEL Default to nrf51
NRF_MODEL ?= nrf51

# ---- Force NRF_MODEL for OLD SDK
ifneq (,$(filter $(SDK_VERSION),9 10))
  ifneq ($(NRF_MODEL), nrf51)
    $(error NRF_MODEL $(NRF_MODEL) is not valid for SDK_VERSION $(SDK_VERSION))
  endif
  NRF_MODEL = nrf51
endif

# --- NRF_IC: Default to nrf51822 for nrf51
ifeq ($(NRF_MODEL), nrf51)
  NRF_IC    ?= nrf51822
# --- NRF_IC: Default to nrf52832 for nrf52
else ifeq ($(NRF_MODEL), nrf52)
  NRF_IC    ?= nrf52832
endif
  

# ---- Set hardware memory sizes
ifneq (,$(filter $(NRF_IC),nrf51422 nrf51802 nrf51822))
  RAM_KB   ?= 16# can be also 32
  FLASH_KB ?= 256# can be also 128
else ifeq ($(NRF_IC), nrf52832)
  RAM_KB   ?= 64
  FLASH_KB ?= 512
else ifeq ($(NRF_IC), nrf52840)
  RAM_KB   ?= 256
  FLASH_KB ?= 1024
endif

# ---- Set SDK if not SET
# Default to SDK 10 for nrf51
ifeq ($(NRF_MODEL), nrf51)
  SDK_VERSION ?= 10
# Default to SDK 12 for nrf52
else ifeq ($(NRF_MODEL), nrf52)
  SDK_VERSION ?= 12
endif
	

# Set this for using GDB
GDB_PORT_NUMBER ?= 2331


#------ Now select/check SOFTDEVICE version if used (depending SDK version)
ifdef SOFTDEVICE_MODEL
	# SDK 9 or 10
	ifneq (,$(filter $(SDK_VERSION),9 10))
		WAITED_NRF_MODEL = nrf51
		ifeq ($(SOFTDEVICE_MODEL), s110)
		    USE_BLE = 1
		    WAITED_SOFTDEVICE_VERSION ?= 8.0.0
		else ifeq ($(SOFTDEVICE_MODEL), s120)
		    USE_BLE = 1
		    WAITED_SOFTDEVICE_VERSION ?= 2.1.0
		else ifeq ($(SOFTDEVICE_MODEL), s130)
		    USE_BLE = 1
		    WAITED_SOFTDEVICE_VERSION ?= 1.0.0
		else ifeq ($(SOFTDEVICE_MODEL), s210)
			# ANT only softDevice
		    WAITED_SOFTDEVICE_VERSION ?= 5.0.0
		else ifeq ($(SOFTDEVICE_MODEL), s310)
		    USE_BLE = 1
		    WAITED_SOFTDEVICE_VERSION ?= 3.0.0
		endif
	endif
	
	# SDK 11
	ifeq ($(SDK_VERSION), 11)
		ifeq ($(SOFTDEVICE_MODEL), s130)
			USE_BLE = 1
			WAITED_SOFTDEVICE_VERSION ?= 2.0.0
			WAITED_NRF_MODEL = nrf51
		else ifeq ($(SOFTDEVICE_MODEL), s132)
			USE_BLE = 1
			SOFTDEVICE_VERSION ?= 2.0.0
		else ifeq ($(SOFTDEVICE_MODEL), s212)
			# ANT only softDevice
			SOFTDEVICE_VERSION ?= 0.9.1
			WAITED_NRF_MODEL = nrf52
		else ifeq ($(SOFTDEVICE_MODEL), s332)
			USE_BLE = 1
			SOFTDEVICE_VERSION ?= 0.9.1
			WAITED_NRF_MODEL = nrf52
		endif
	endif
	
	# SDK 12
	ifeq ($(SDK_VERSION), 12)
		ifeq ($(SOFTDEVICE_MODEL), s130)
			USE_BLE = 1
			WAITED_SOFTDEVICE_VERSION ?= 2.0.1
			WAITED_NRF_MODEL = nrf51
		else ifeq ($(SOFTDEVICE_MODEL), s132)
			USE_BLE = 1
			SOFTDEVICE_VERSION ?= 3.0.0
		else ifeq ($(SOFTDEVICE_MODEL), s212)
			# ANT only softDevice
			SOFTDEVICE_VERSION ?= 2.0.0
			WAITED_NRF_MODEL = nrf52
		else ifeq ($(SOFTDEVICE_MODEL), s332)
			USE_BLE = 1
			SOFTDEVICE_VERSION ?= 2.0.0
			WAITED_NRF_MODEL = nrf52
		endif
	endif

	SOFTDEVICE_VERSION ?= $(WAITED_SOFTDEVICE_VERSION)
    ifneq ($(SOFTDEVICE_VERSION), $(WAITED_SOFTDEVICE_VERSION))
        $(error FOR SDK$(SDK_VERSION) Supported SoftDevice Version for $(SOFTDEVICE_MODEL) is $(WAITED_SOFTDEVICE_VERSION))
    endif
    
    ifneq ($(WAITED_NRF_MODEL), $(NRF_MODEL))
        $(error SoftDevice $(SOFTDEVICE_MODEL) is only compatible with $(WAITED_NRF_MODEL))
    endif
    
endif # ifdef SOFTDEVICE_MODEL


# Print some helpful info about what the user is compiling for
space :=
space +=
$(info BUILD OPTIONS:)
$(info $(space) SoftDevice  $(SOFTDEVICE_MODEL))
$(info $(space) SDK         $(SDK_VERSION))
$(info $(space) nRF         $(NRF_IC))
$(info $(space) RAM         $(RAM_KB) kB)
$(info $(space) FLASH       $(FLASH_KB) kB)
$(info $(space) Board       $(BOARD))
{'fraction_non_alphanumeric': 0.1482216576691013, 'fraction_numerical': 0.05382661162273738, 'mean_word_length': 3.3724401249566123, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5235116', 'n_tokens_mistral': 5508, 'n_tokens_neox': 4628, 'n_words': 1239}