Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,5 @@

rsource "drivers/Kconfig"

choice NVS_LOG_LEVEL_CHOICE
default NVS_LOG_LEVEL_ERR
endchoice

choice SETTINGS_LOG_LEVEL_CHOICE
default SETTINGS_LOG_LEVEL_ERR
endchoice

config ALIRO_PRINT_READER_GROUP_ID
bool "Print reader group ID that should be provisioned into the User Device"
22 changes: 16 additions & 6 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,21 @@ target_sources(app PRIVATE
${app_sources}
)

set(ALIRO_LIB ${ZEPHYR_NCS_DOOR_LOCK_APP_MODULE_DIR}/lib/aliro/bin)
set(PUBLIC_API ${ZEPHYR_NCS_DOOR_LOCK_APP_MODULE_DIR}/lib/aliro)
set(ALIRO_LIB_DIR ${ZEPHYR_NCS_DOOR_LOCK_APP_MODULE_DIR}/lib/aliro)

zephyr_link_libraries(${ALIRO_LIB}/libaliro.a)
if(CONFIG_SOC_SERIES_NRF52X)
set(ALIRO_LIB_BIN_PATH ${ALIRO_LIB_DIR}/bin/cortex-m4)
elseif(CONFIG_SOC_SERIES_NRF54LX OR CONFIG_SOC_SERIES_NRF53X)
set(ALIRO_LIB_BIN_PATH ${ALIRO_LIB_DIR}/bin/cortex-m33)
endif()

zephyr_include_directories(${PUBLIC_API}/include)
zephyr_include_directories(${PUBLIC_API}/interfaces)
zephyr_include_directories(${PUBLIC_API}/interfaces/crypto/backend_crypto_psa)
add_library(aliro_stack STATIC IMPORTED GLOBAL)

set_target_properties(aliro_stack PROPERTIES IMPORTED_LOCATION ${ALIRO_LIB_BIN_PATH}/libaliro.a)

target_link_libraries(app PRIVATE aliro_stack)
target_link_libraries(aliro_stack INTERFACE zephyr_interface)

zephyr_include_directories(${ALIRO_LIB_DIR}/include)
zephyr_include_directories(${ALIRO_LIB_DIR}/interfaces)
zephyr_include_directories(${ALIRO_LIB_DIR}/interfaces/crypto/backend_crypto_psa)
2 changes: 1 addition & 1 deletion app/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#

rsource "src/nfc_transport_impl/Kconfig"
rsource "../lib/aliro/Kconfig.aliro.defconfig"
rsource "../lib/aliro/Kconfig.defconfig"

menu "Zephyr"
source "Kconfig.zephyr"
Expand Down
59 changes: 59 additions & 0 deletions app/boards/nrf52840dk_nrf52840.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright (c) 2025 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

&pinctrl {
spi0_default_alt: spi0_default_alt {
group1 {
psels = <NRF_PSEL(SPIM_SCK, 1, 15)>,
<NRF_PSEL(SPIM_MOSI, 1, 13)>,
<NRF_PSEL(SPIM_MISO, 1, 14)>;
};
};

spi0_sleep_alt: spi0_sleep_alt {
group1 {
psels = <NRF_PSEL(SPIM_SCK, 1, 15)>,
<NRF_PSEL(SPIM_MOSI, 1, 13)>,
<NRF_PSEL(SPIM_MISO, 1, 14)>;
low-power-enable;
};
};
};

&spi0 {
compatible = "nordic,nrf-spi";
status = "okay";
cs-gpios = <&gpio1 12 GPIO_ACTIVE_LOW>;

pinctrl-0 = <&spi0_default_alt>;
pinctrl-1 = <&spi0_sleep_alt>;
pinctrl-names = "default", "sleep";
nucleo_nfc@0 {
compatible = "x-nucleo-nfc";
reg = <0>;
spi-max-frequency = <4000000>;
irq-gpios = <&gpio0 3 GPIO_ACTIVE_HIGH>;
};
};

&spi1 {
status = "disabled";
};

&spi2 {
status = "disabled";
};

&spi3 {
status = "disabled";
};

/ {
psa_rng: psa-rng {
compatible = "zephyr,psa-crypto-rng";
status = "okay";
};
};
42 changes: 42 additions & 0 deletions app/boards/nrf5340dk_nrf5340_cpuapp.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2025 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

&pinctrl {
spi1_default_alt: spi1_default_alt {
group1 {
psels = <NRF_PSEL(SPIM_SCK, 1, 15)>,
<NRF_PSEL(SPIM_MOSI, 1, 13)>,
<NRF_PSEL(SPIM_MISO, 1, 14)>;
};
};

spi1_sleep_alt: spi1_sleep_alt {
group1 {
psels = <NRF_PSEL(SPIM_SCK, 1, 15)>,
<NRF_PSEL(SPIM_MOSI, 1, 13)>,
<NRF_PSEL(SPIM_MISO, 1, 14)>;
low-power-enable;
};
};

};


&spi1 {
compatible = "nordic,nrf-spim";
status = "okay";
cs-gpios = <&gpio1 12 GPIO_ACTIVE_LOW>;

pinctrl-0 = <&spi1_default_alt>;
pinctrl-1 = <&spi1_sleep_alt>;
pinctrl-names = "default", "sleep";
nucleo_nfc@0 {
compatible = "x-nucleo-nfc";
reg = <0>;
spi-max-frequency = <4000000>;
irq-gpios = <&gpio0 4 GPIO_ACTIVE_HIGH>;
};
};
20 changes: 14 additions & 6 deletions app/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,30 @@ CONFIG_CPP=y
CONFIG_STD_CPP17=y
CONFIG_REQUIRES_FULL_LIBCPP=y
CONFIG_RESET_ON_FATAL_ERROR=n
CONFIG_ASSERT=y

# Logging
CONFIG_CONSOLE=y
CONFIG_LOG=y
CONFIG_NCS_ALIRO_RFAL_LOG_LEVEL_DBG=y

# Print reader key that can be provisioned to the User Device
CONFIG_ALIRO_PRINT_READER_GROUP_ID=y

# RFAL worker stack size (TODO: optimize)
CONFIG_RFAL_WORKER_THREAD_STACK_SIZE=8192
CONFIG_USE_SEGGER_RTT=n
CONFIG_LOG_BACKEND_RTT=n
CONFIG_LOG_BACKEND_SHOW_COLOR=n

# Disable unused shell features
CONFIG_SHELL_VT100_COLORS=n
CONFIG_SHELL_HISTORY=n
CONFIG_SHELL_WILDCARD=n

# Increase shell buffer sizes
CONFIG_SHELL_BACKEND_SERIAL_RX_RING_BUFFER_SIZE=512
CONFIG_SHELL_BACKEND_SERIAL_TX_RING_BUFFER_SIZE=128

# Adjust logs queue size
CONFIG_SHELL_BACKEND_SERIAL_LOG_MESSAGE_QUEUE_SIZE=768

# Print reader key that can be provisioned to the User Device
CONFIG_ALIRO_PRINT_READER_GROUP_ID=y

# RFAL worker stack size (TODO: optimize)
CONFIG_RFAL_WORKER_THREAD_STACK_SIZE=8192
13 changes: 13 additions & 0 deletions app/sample.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
sample:
description: Door lock sample application
name: ncs-door-lock-sample
common:
sysbuild: true
build_only: true
platform_allow: &platforms
- nrf54l15dk/nrf54l15/cpuapp
- nrf52840dk/nrf52840
- nrf5340dk/nrf5340/cpuapp
integration_platforms: *platforms
tests:
app.nfc_door_lock: {}
38 changes: 0 additions & 38 deletions app/src/hw_init.cpp

This file was deleted.

13 changes: 1 addition & 12 deletions app/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,7 @@ LOG_MODULE_REGISTER(door_lock_app, CONFIG_NCS_DOOR_LOCK_APP_LOG_LEVEL);

int main()
{
LOG_INF(" \r\n"
" @@@ @@@@ \r\n"
" @@@@@@@@@@@@ @@@ \r\n"
" @@@@@ @@@@@ @@@@ @@ @@@ @@ @@ @@@@ \r\n"
" @@@@ @@@@ @@@@ @@@@@@ @@@ @@ @@@@@ @@@ @@@@ \r\n"
"@@@@ @@ @@@ @@@ @@@ @@@ @@ @@@ @@@ @@@\r\n"
"@@@ @@@@@ @@@ @@@ @@@ @@@ @@ @@ @@@ @@\r\n"
"@@@ @@@@@@@@ @@@ @@@ @@@ @@@ @@ @@ @@@ @@\r\n"
" @@@ @@@@ @@@@ @@@ @@@@ @@@ @@ @@ @@ @@@\r\n"
" @@@ @@@@ @@@@ @@@@@@@@@@@ @@@@@ @@ @@ @@@@@@@@@ \r\n"
" @@@@ @@@@ @@@@ \r\n"
" @@ @@@@ @@ \r\n");
LOG_INF("Starting nRF Door Lock Reference Application for the nRF Connect SDK");

AliroError ec = Aliro::AliroStack::Instance().Init(
{ .mOnAccessAttempt =
Expand Down
40 changes: 12 additions & 28 deletions app/src/nfc_transport_impl/nfc_transport_rfal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,8 @@ K_THREAD_STACK_DEFINE(mStack, CONFIG_RFAL_WORKER_THREAD_STACK_SIZE);
void NfcTransportRfal::Run()
{
while (true) {
if (mRxTimeout || mIdleTimeout) {
if (mRxTimeout) {
VerifyAndCall(Instance().NfcDriver::mCallbacks.mOnError, ALIRO_TIMEOUT);
mRxTimeout = false;
}
if (mIdleTimeout) {
mIdleTimeout = false;
}
if (mIdleTimeout) {
mIdleTimeout = false;
RecoverPolling();
}
rfalNfcWorker();
Expand Down Expand Up @@ -73,7 +67,6 @@ void NfcTransportRfal::RfalNotifyCallback(rfalNfcState state)
LOG_DBG("RFAL: Data exchange state");
break;
case RFAL_NFC_STATE_DATAEXCHANGE_DONE:
k_timer_stop(&mRxTimer);
CaptureRxData();
k_timer_start(&mIdleTimer, K_MSEC(sIdleTimerTimeoutMs), K_NO_WAIT);
break;
Expand Down Expand Up @@ -106,7 +99,7 @@ ReturnCode NfcTransportRfal::RfalNfcInit()
return err;
}

void NfcTransportRfal::SelectTag()
void NfcTransportRfal::SelectTag() const
{
rfalNfcDevice *nfcDevice;
rfalNfcGetActiveDevice(&nfcDevice);
Expand Down Expand Up @@ -150,7 +143,7 @@ void NfcTransportRfal::CaptureRxData()
0);
}

void NfcTransportRfal::RecoverPolling()
void NfcTransportRfal::RecoverPolling() const
{
if (rfalNfcIsDevActivated(rfalNfcGetState())) {
ReturnCode err = rfalNfcDeactivate(RFAL_NFC_DEACTIVATE_SLEEP);
Expand All @@ -169,26 +162,26 @@ AliroError NfcTransportRfal::_Init(IsoDep::Callbacks callbacks)
return ALIRO_NO_ERROR;
}

AliroError NfcTransportRfal::_PrepareData(NfcTransport::Data data)
AliroError NfcTransportRfal::_PrepareData([[maybe_unused]] Data data) const
{
// ISO-DEP layer is implemented internally in the RFAL, no need for special data handling
return ALIRO_ERROR_NOT_IMPLEMENTED;
}

AliroError NfcTransportRfal::_PrepareRats()
AliroError NfcTransportRfal::_PrepareRats() const
{
// RATS is sent by the driver internally as an activation procedure, so we can presume the tag is fully selected
// a this point
return ALIRO_ERROR_NOT_IMPLEMENTED;
}

AliroError NfcTransportRfal::_HandleReceivedData(NfcTransport::Data data, int transferError)
AliroError NfcTransportRfal::_HandleReceivedData([[maybe_unused]] Data data, [[maybe_unused]] int transferError) const
{
// No specific processing needed, all ISO-DEP specific data handling happens in driver's internals
return ALIRO_ERROR_NOT_IMPLEMENTED;
}

AliroError NfcTransportRfal::_ReportTimeout()
AliroError NfcTransportRfal::_ReportTimeout() const
{
// No special handling needed with RFAL
return ALIRO_ERROR_NOT_IMPLEMENTED;
Expand Down Expand Up @@ -219,7 +212,7 @@ AliroError NfcTransportRfal::_Init(NfcDriver::Callbacks callbacks)
return ALIRO_ERROR_INTERNAL;
}

k_tid_t thread = ncs_pal_nfc_worker_start([](void *, void *, void *) -> void { return Instance().Run(); });
const k_tid_t thread = ncs_pal_nfc_worker_start([](void *, void *, void *) { Instance().Run(); });

VerifyOrReturnStatus(thread, ALIRO_INVALID_STATE, LOG_ERR("RFAL: Cannot spawn the NFC driver thread"));

Expand All @@ -228,14 +221,6 @@ AliroError NfcTransportRfal::_Init(NfcDriver::Callbacks callbacks)
return ALIRO_ERROR_INTERNAL;
}

k_timer_init(
&mRxTimer,
[](k_timer *) {
LOG_DBG("RFAL: RX timer expired");
Instance().mRxTimeout = true;
},
nullptr);

k_timer_init(
&mIdleTimer,
[](k_timer *) {
Expand All @@ -247,7 +232,7 @@ AliroError NfcTransportRfal::_Init(NfcDriver::Callbacks callbacks)
return ALIRO_NO_ERROR;
}

AliroError NfcTransportRfal::_Send(NfcTransport::Data data, uint32_t maximumFrameDelayTime)
AliroError NfcTransportRfal::_Send(Data data, [[maybe_unused]] uint32_t maximumFrameDelayTime)
{
k_timer_stop(&mIdleTimer);

Expand All @@ -256,14 +241,13 @@ AliroError NfcTransportRfal::_Send(NfcTransport::Data data, uint32_t maximumFram
// use RFAL_FWT_NONE as FWT because the driver with ISO-DEP enabled will ignore it anyway
ReturnCode err = rfalNfcDataExchangeStart(data.mData, data.mLength, &mRxData, &mRcvLen, RFAL_FWT_NONE);
if (!err) {
k_timer_start(&mRxTimer, K_MSEC(sRxTimerTimeoutMs), K_NO_WAIT);
return ALIRO_NO_ERROR;
}

return ALIRO_ERROR_INTERNAL;
}

AliroError NfcTransportRfal::_NfcOn()
AliroError NfcTransportRfal::_NfcOn() const
{
// The RF field is turned right after the STR25 boots
// The only thing that must be done is to activate the reader
Expand All @@ -277,7 +261,7 @@ AliroError NfcTransportRfal::_NfcOn()
return ALIRO_NO_ERROR;
}

AliroError NfcTransportRfal::_NfcOff()
AliroError NfcTransportRfal::_NfcOff() const
{
// RFAL handles this internally and knows when the field can be off
return ALIRO_ERROR_NOT_IMPLEMENTED;
Expand Down
Loading