Skip to content

Conversation

@ankuns
Copy link
Contributor

@ankuns ankuns commented Jan 8, 2026

Background:
The NFC TNEP handling is encapsulated by sdk-nrf file subsys/nfc/tnep/tag.c.
This file relied on Zephyr-provided primitives like k_poll_event, which are not available in Bare Metal option.

Changes:
This PR adds NFC TNEP handling to the Bare Metal by:

  • Use sdk-nrf covered by the PR nfc: tnep tag separate signalling layer for Bare Metal sdk-nrf#26440 which separates subsys/nfc/tnep/tag.c implementation from signalling implementation. The implementation subsys/nfc/tnep/tag.c with these modifications is re-used in Bare Metal.
  • Provide implementation of NFC TNEP signalling ( sdk-nrf-bm file subsys/nfc/tnep/tag_signalling_bm.c) using only atomic operations.

ankuns added 2 commits January 8, 2026 14:30
The NFC TNEP signalling must be provided by sdk-nrf-bm.

Signed-off-by: Andrzej Kuros <[email protected]>
The Kconfig NFC_TNEP_TAG_SIGNALLING choice is given the
NFC_TNEP_TAG_SIGNALLING_BM option for Bare Metal platform.
This option enables the NFC TNEP tag signalling appropriate for
Bare Metal platform, where Zephyr primitives are not available.

Signed-off-by: Andrzej Kuros <[email protected]>
@github-actions github-actions bot added manifest changelog-entry-required Update changelog before merge. Remove label if entry is not needed or already added. labels Jan 8, 2026
@NordicBuilder
Copy link

NordicBuilder commented Jan 8, 2026

The following west manifest projects have changed revision in this Pull Request:

Name Old Revision New Revision Diff
nrf nrfconnect/[email protected] nrfconnect/sdk-nrf#26440 nrfconnect/sdk-nrf#26440/files

DNM label due to: 1 project with PR revision

Note: This message is automatically posted and updated by the Manifest GitHub Action.

@github-actions
Copy link

github-actions bot commented Jan 8, 2026

You can find the documentation preview for this PR here.

@ankuns ankuns force-pushed the nfc_tnep_tag_sample_v4 branch from c06721c to 284f36a Compare January 8, 2026 14:21
The sample is based on sdk-nrf samples/nfc/tnep_tag sample
and it's behavior is the same.

Signed-off-by: Andrzej Kuros <[email protected]>

#include <stdint.h>

int nfc_tnep_tag_signalling_init(void);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add description to the API

int err;
static const char svc_one_msg[] = "Service pi = 3.14159265358979323846";

printk("Service one selected\n");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you decide which log backend is used, here and below are printk and in main() function also LOG_ are used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will fix, thanks.

Comment on lines +93 to +94
err = nfc_ndef_msg_record_add(&NFC_NDEF_MSG(app_msg),
&NFC_NDEF_TEXT_RECORD_DESC(svc_one_rec));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing error handling for nfc_ndef_msg_record_add()

Comment on lines +112 to +115
static void tnep_svc_one_msg_received(const uint8_t *data, size_t len)
{
int err;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
static void tnep_svc_one_msg_received(const uint8_t *data, size_t len)
{
int err;
static void tnep_svc_one_msg_received(const uint8_t *data, size_t len)
{
ARG_UNUSED(data);
ARG_UNUSED(len);
int err;

Do the same in the functions below where arguments are not used

Comment on lines +269 to +272
err = bm_buttons_init(configs, ARRAY_SIZE(configs), BM_BUTTONS_DETECTION_DELAY_MIN_US);
if (err) {
return err;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
err = bm_buttons_init(configs, ARRAY_SIZE(configs), BM_BUTTONS_DETECTION_DELAY_MIN_US);
if (err) {
return err;
}
int err = bm_buttons_init(configs, ARRAY_SIZE(configs), BM_BUTTONS_DETECTION_DELAY_MIN_US);
if (err) {
return err;
}

then you can remove line 240

static const uint8_t svc_two_uri[] = "svc:e";

static uint8_t tag_buffer[NDEF_TNEP_MSG_SIZE];
static uint8_t tag_buffer2[NDEF_TNEP_MSG_SIZE];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
static uint8_t tag_buffer2[NDEF_TNEP_MSG_SIZE];
static uint8_t swap_buffer[NDEF_TNEP_MSG_SIZE];

?

enum tnep_event e = atomic_get(msg_event);

if (e != TNEP_EVENT_DUMMY) {
(void)atomic_cas(msg_event, e, TNEP_EVENT_DUMMY);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When atomic_cas fails then the event may be duplicated. The atomic_cas() result should be handled.

Copy link
Contributor Author

@ankuns ankuns Jan 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't agree, if the atomic_cas fails it simply means that between atomic_get and atomic_cas (the write inside) the value of event has changed. The return value is intentionally ignored in this case to not loose the new updated value. There is no duplication of event.

Comment on lines +170 to +172
if (data_length > 0) {
nfc_tnep_tag_rx_msg_indicate(nfc_t4t_ndef_file_msg_get(data),
data_length);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about:

Suggested change
if (data_length > 0) {
nfc_tnep_tag_rx_msg_indicate(nfc_t4t_ndef_file_msg_get(data),
data_length);
if (nfc_t4t_ndef_file_msg_get(data_length) > 0) {
nfc_tnep_tag_rx_msg_indicate(nfc_t4t_ndef_file_msg_get(data),
nfc_t4t_ndef_file_msg_get(data_length));

Due to fact that that nfc_t4t_ndef_file_msg_get() gets data with offset this should be safer.
https://github.com/nrfconnect/sdk-nrf/blob/cd414710184846fd1a3bd7213db5ae8199a801b9/include/nfc/t4t/ndef_file.h#L43

Comment on lines +212 to +213
err = nfc_ndef_msg_record_add(&NFC_NDEF_MSG(app_msg),
&NFC_NDEF_TEXT_RECORD_DESC(svc_two_rec));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing error handling.

err = nfc_tnep_tag_initial_msg_create(TNEP_INITIAL_MSG_RECORD_COUNT,
tnep_initial_msg_encode);
if (err) {
printk("Cannot create initial TNEP message, err: %d\n", err);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing goto fail;?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog-entry-required Update changelog before merge. Remove label if entry is not needed or already added. DNM Do not merge manifest manifest-nrf

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants