NFC-Based Secure Memory

by payodhisharma15 in Circuits > Microcontrollers

39 Views, 2 Favorites, 0 Comments

NFC-Based Secure Memory

16acb5f9-8a9a-4ff3-8864-0e645210f70f.png

In this project, we demonstrate an NFC-Based Secure Memory Reader using the Renesas EK-RA2E1 microcontroller board and PTX105R NFC Reader PMOD. A specific NFC tag, when brought near the reader, authenticates via UID match and unlocks a secret message stored in the Data Flash memory of the microcontroller.

This simple yet effective system mimics real-world access control, secure logbooks, or hidden data triggers, making it ideal for IoT security demos, embedded learners, and product showcases.

Supplies

ek-ra2e1.jpeg
PTX105RQC.jpeg
NFC_tags.jpeg

Supplies Used

  1. Renesas EK-RA2E1 Evaluation Kit

https://www.renesas.com/en/products/ra2e1?srsltid=AfmBOorvPBsiHj2679XLs7sD_E7rcTcs7_1eSP49A6vlWJEWLttK7L4V

  1. PTX105R NFC Reader Board

https://www.renesas.com/en/design-resources/boards-kits/ptx105rqc?srsltid=AfmBOop_cqV49axDF26y9LKSfA7QkwGIRcvbT-C7pG-DZY2jHgyeucU-

  1. NFC Type A Tags (UID readable)

Use an NFC tag with a fixed (non-random) UID.

Recommended: NTAG213 / NTAG215 / NTAG216, or MIFARE Classic.

Avoid: Tags with random or writable UIDs, authentication will fail.

  1. Micro USB Cable
  2. e² studio (Renesas IDE)

https://www.renesas.com/en/software-tool/e-studio?queryID=50d98d1cfacd7e2bbc031706981b40a1

  1. SEGGER RTT Viewer

https://www.segger.com/products/debug-probes/j-link/tools/rtt-viewer/

Hardware Setup

Connection.jpeg

🔧 Assembly Instructions:

  1. Connect the PTX105R module to the PMOD1 header on the EK-RA2E1 board. Make sure it's firmly seated and aligned properly.
  2. Power the board using the Micro USB cable connected to your PC or power source.
  3. The onboard green LED (P914) and red LED (P913) are used to indicate authentication status:
  4. Green LED turns on when a correct NFC tag is detected.
  5. Red LED lights up if the tag is unauthenticated or incorrect.

🔌 Pinout Info:

  1. Green LED: Connected to P914
  2. Red LED: Connected to P913

Import and Setup Project to E2 Studio

Update_static_uid.png

Now that the hardware is ready, let's import the pre-built project and get it running on your RA2E1 board.

1. Download the Project

  1. Click this Google Drive link.
  2. Download the ZIP file named RA2E1_nfc_dataFlash.zip.

2. Extract the ZIP

  1. Right-click on the ZIP file → Extract All (Windows) or Unzip (macOS/Linux).
  2. You should now see a folder named RA2E1_nfc_dataFlash.

3. Launch e² studio

  1. Open e² studio.
  2. Wait for the workspace to load.

4. Import the Project

  1. In the top menu, go to File → Import...
  2. In the Import Wizard:
  3. Expand General
  4. Select Existing Projects into Workspace → Click Next
  5. Click Browse… and select the folder you just extracted.
  6. Ensure the project RA2E1_nfc_dataFlash is checked → Click Finish.

5. Replace the Static UID

By default, the project authenticates one specific NFC tag using a static UID.

You must replace that UID with your own NFC tag’s UID.

How to find your tag’s UID:
  1. Run the project as-is by following the rest of this step.
  2. Open SEGGER RTT Viewer (we’ll guide you in Step 3).
  3. When you bring any NFC tag close to the reader, its UID will be printed on the RTT console like this:
NFCID1: A1B2C3D4
  1. Copy this 4-byte UID.
How to update your UID in code:
  1. In Project Explorer, navigate to:
src → STACK → EXAMPLE → IOT_APP → ptx_IOT_RD_Main.c
  1. Find this block of code (image attached):
if (memcmp(cardRegistry->ActiveCard->TechParams.CardAParams.NFCID1,
(uint8_t[]){ 0xA8, 0x94, 0x6A, 0x12 }, 4) == 0)
  1. Replace the 4-byte array with your own UID
  2. Save the file.

You’ve now authenticated your own tag!

6. Generate Project Content

  1. Double-click on configuration.xml to open the FSP Configuration GUI.
  2. Click the Generate Project Content button (top-right corner).

7. Build the Project

  1. Right-click the project RA2E1_nfc_dataFlash → Select Build Project.
  2. Let the build finish; confirm it completes with 0 errors.

8. Connect and Debug

  1. Connect the RA2E1 board to your PC using a USB cable.
  2. Once connected:
  3. Right-click the project → Select Debug As → Renesas GDB Hardware Debugging
  4. The firmware will be flashed to the board, and execution will start.

Once done, your project is now running and ready to detect your authenticated NFC tag.

View NFC Tag Output Via SEGGER RTT Viewer

Segger_authenticated.png
Segger_unauthenticated.png
Segger_configuration.png

To verify if your NFC tag is being correctly detected and authenticated, you’ll use SEGGER RTT Viewer, a powerful debugging console that prints real-time logs from the RA2E1 board.

How to Setup SEGGER RTT Viewer

Follow these steps carefully:

1. Locate the SEGGER Address

  1. After building the project, go to the Debug folder inside your project.
RA2E1_nfc_dataFlash → Debug
  1. Open the file named:
RA2E1_nfc_dataFlash.map
  1. Press Ctrl + F and search for _SEGGER_RTT.
  2. Copy the address listed beside _SEGGER_RTT.
  3. It will look like:
_SEGGER_RTT 0x20005570

2. Launch SEGGER RTT Viewer

  1. Open the SEGGER RTT Viewer application.
  2. Select the correct device part number(You can verify the part number in configuration.xml → BSP tab → Device Name).
  3. In the setup window:
  4. Select J-Link Device as your RA2E1 board.
  5. Choose Interface = SWD
  6. In the RTT Control Block section, paste the address you copied from .map file (e.g., 0x20000400).
  7. Click OK.

3. Monitor Output

Once connected:

  1. You’ll start seeing real-time logs in SEGGER RTT Viewer.
  2. Bring an NFC tag close to the reader.
  3. If the UID matches the one you hardcoded earlier, you’ll see:
AUTHENTICATED: UID matched A1B2C3D4
DataFlash Read: Hello Renesas!

If the UID does not match, you’ll see:

UNAUTHENTICATED: UID did NOT match


Note: Only tags with static UIDs (not randomly generated each time) can be reliably authenticated in this setup.

We recommend you use tags with fixed UID, these are often labeled as “NTAG213,” “NTAG215,” etc.

How the Project Works?

Application_flow_diagram.png

This project is a compact implementation of secure NFC-based authentication using the Renesas RA2E1 microcontroller and the PTX105R NFC reader. It combines concepts from wireless communication, non-volatile memory handling, and event-driven embedded systems into a seamless application.

NFC UID Authentication

At the core of this system is UID-based NFC authentication. Every NFC tag has a unique identifier (UID) hardcoded during manufacturing (only some tags have static UIDs, this is crucial). When a tag is detected via the Type-A protocol, the firmware checks the UID against a pre-stored value (you can find and update this UID in ptx_IOT_RD_Main.c, under the Prot_T2T switch-case).

Only if the UID matches, access is granted and a secret message is revealed. Otherwise, the system politely denies access and lights the red LED.

This simulates a real-world secure access scenario, imagine using this concept in smart locks, contactless IDs, or medical records access.

Data Flash Memory Integration

Instead of simply printing a hardcoded message, we demonstrate secure readout from on-chip Data Flash memory. This non-volatile storage is ideal for sensitive data that must persist across power cycles.

Our flash operations include:

  1. Blank check (to verify memory is clean)
  2. Erase (to prepare memory)
  3. Write (store the message)
  4. Read (extract message only upon authentication)

All these operations use the Renesas Flash LP (Low Power) driver, configured in flash_lp_ep.c.

Modular Design

Here's how everything ties together:

  1. hal_entry.c: Entry point and system status output
  2. ptx_IOT_RD_Main.c: Handles card detection and UID logic
  3. flash_lp_ep.c/h: Manages all data flash operations
  4. configuration.xml: Sets up board-level peripherals (FSP GUI)

A successful authentication results in:

  1. Green LED on
  2. Message printed over SEGGER RTT Viewer (accessed via the memory-mapped _SEGGER_RTT symbol)

Authentication failure? Red LED and a friendly denial message.

Conclusion

And that’s a wrap! With just an NFC tag and a Renesas RA2E1 board, you’ve built a simple yet secure system to store and unlock secret messages. It’s a fun and practical way to dive into embedded security and a great base to build even cooler applications!

Thank you for reading!