The extended tutorial explains how to work with larger Standard Data files on a Mifare DESFire NFC card on an ESP32 with a connected PN5232 reader.
This is the accompanying repository for my article "How to read and write large data files on a Mifare DESFire EVx NFC tag on an ESP32 with PN532 reader" available here: https://medium.com/@androidcrypto/how-to-read-and-write-large-data-files-on-a-mifare-desfire-evx-nfc-tag-on-an-esp32-with-pn532-c32e26396dfb
Please note: The sketch is just the tutorial code and does not contain any code for displaying any data on a TFT display !
The DESFire library contains just the code (commands) needed for the tutorial but not a full implementation of the DESFire EVx commands.
I'm recommending two NFC readers, but please be aware that I read some negative comments on the "Red" PCB one - some seem to have design flaws.
To use the SPI mode you have to bring the switch in the right position:
// settings for ESP32 ST7789 1.9-inches TFT display
#define PN532_SCK (33)
#define PN532_MOSI (32)
#define PN532_SS (25)
#define PN532_MISO (34)
#define PN532_IRQ (-1) // not connected
#define PN532_RESET (-1) // not connected
// The VCC pin of the reader is connected to the 3.3V pin of the ESP32
// settings for ESP32-S3 Developmentboard with TFT Display
#define PN532_SCK (42)
#define PN532_MOSI (2)
#define PN532_SS (40)
#define PN532_MISO (41)
#define PN532_IRQ (-1) // not connected
#define PN532_RESET (-1) // not connected
// The VCC pin of the reader is connected to the 3.3V pin of the ESP32
Adafruit_PN532 by Adafruit version 1.3.4 (https://github.com/adafruit/Adafruit-PN532)
data sheet Rev. 3.0 — 31 January 2019: https://www.nxp.com/docs/en/data-sheet/NT4H2421Gx.pdf (NT4H2421Gx_NTAG_424_DNA_data_sheet_rev_3_0_2019_01_31.pdf)
Features and Hints Application note Rev. 2.0 — 4 March 2025: https://www.nxp.com/docs/en/application-note/AN12196.pdf (AN12196_NTAG424_Features_and_Hints_Rev_2_0_2025_03_04.pdf)
data sheet Rev. 3.3 — 5 April 2019: https://www.nxp.com/docs/en/data-sheet/MF2DLHX0.pdf (MF2DLHX0_MIFARE_DESFire_Light_data_sheet_rev_3_3_2019_04_05.pdf)
Features and Hints Application note Rev. 1.1 — 20 January 2020: https://www.nxp.com/docs/en/application-note/AN12343.pdf (AN12343_MIFARE_DESFire_Light_Features_and_Hints_Rev_1_1_2020_01_20.pdf)
Short data sheet Rev. 3.1 — 11 January 2024: https://www.nxp.com/docs/en/data-sheet/MF3D_H_X3_SDS.pdf (MF3D_H_X3_SDS_MIFARE_DESFire_EV3_short_data_sheet_Rev_3_1_2024_01_11.pdf)
Mifare DESFire protocol: https://raw.githubusercontent.com/revk/DESFireAES/master/DESFire.pdf (NXP_MIFARE_DESFire_EV1_Protocol.pdf)
MIFARE DESFire EV3 feature and functionality comparison to other MIFARE DESFire products Rev. 1.4 — 24 July 2023: https://www.nxp.com/docs/en/application-note/AN12752.pdf (AN12752_MIFARE_DESFire_EV3_feature_and_functionality_comparison_Rev_1_4_2023_07_24.pdf)
Arduino IDE Version 2.3.6 (Windows)
arduino-esp32 boards Version 3.2.0 (https://github.com/espressif/arduino-esp32)
ESP32 Adafruit PN532 DESFire Starter Extended V03
Found chip PN532
Firmware ver. 1.6
ESP32_DESFire library version: 3
Waiting for an ISO14443A card
Tag number: 1
Found a card!
-------------------------------------------------------------------------
T02 Large File Handling
-------------------------------------------------------------------------
Get Free Memory
Send length 5
90 6E 00 00 00
Recv length 5
40 01 00 91 00
SUCCESS
GetFreeMemory response length 3 data: 40 01 00
-------------------------------------------------------------------------
Get Version
Send length 5
90 60 00 00 00
Recv length 9
04 01 01 33 00 18 05 91 AF
Send length 5
90 AF 00 00 00
Recv length 9
04 01 01 03 00 18 05 91 AF
Send length 5
90 AF 00 00 00
Recv length 16
04 35 68 DA 05 1A 90 20 82 62 30 30 34 23 91 00
SUCCESS
GetVersion response length 28 data: 04 01 01 33 00 18 05 04 01 01 03 00 18 05 04 35 68 DA 05 1A 90 20 82 62 30 30 34 23
-------------------------------------------------------------------------
Create an Application
Send length 11
90 CA 00 00 05 56 78 9A 0F 85 00
Recv length 2
91 DE
DUPLICATE ERROR
-------------------------------------------------------------------------
Select an Application
Send length 9
90 5A 00 00 03 56 78 9A 00
Recv length 2
91 00
SUCCESS
-------------------------------------------------------------------------
Create a Standard Data file with Free Access Rights and fileSize 255 bytes
Send length 13
90 CD 00 00 07 03 00 EE EE FF 00 00 00
Recv length 2
91 DE
DUPLICATE ERROR
-------------------------------------------------------------------------
Get File Settings
Send length 7
90 F5 00 00 01 03 00
Recv length 9
00 00 EE EE FF 00 00 91 00
SUCCESS
-------------------------------------------------------------------------
File Settings for file 03
File Type : 00 (Standard Data File)
File Options : 00
File Comm Mode : PLAIN
File RW/CAR AccRg : EE
File R/W AccRg : EE
File Size : 255
-------------------------------------------------------------------------
Read from a Standard Data file with Free Access Rights and fileSize 255 bytes (Simple)
Send length 13
90 BD 00 00 07 03 00 00 00 FF 00 00 00
Recv length 60
01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F 30 31 32 33 34 35 36 37 38 39 3A 91 AF
Additional Frame -> Get More Data
-------------------------------------------------------------------------
Select an Application
Send length 9
90 5A 00 00 03 56 78 9A 00
Recv length 2
91 00
SUCCESS
-------------------------------------------------------------------------
Create a Standard Data file with Free Access Rights and fileSize 255 bytes
Send length 13
90 CD 00 00 07 03 00 EE EE FF 00 00 00
Recv length 2
91 DE
DUPLICATE ERROR
-------------------------------------------------------------------------
Get File Settings
Send length 7
90 F5 00 00 01 03 00
Recv length 9
00 00 EE EE FF 00 00 91 00
SUCCESS
-------------------------------------------------------------------------
File Settings for file 03
File Type : 00 (Standard Data File)
File Options : 00
File Comm Mode : PLAIN
File RW/CAR AccRg : EE
File R/W AccRg : EE
File Size : 255
-------------------------------------------------------------------------
Read from a Standard Data file with Free Access Rights and fileSize 255 bytes (Simple)
Send length 13
90 BD 00 00 07 03 00 00 00 FF 00 00 00
Recv length 60
01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F 30 31 32 33 34 35 36 37 38 39 3A 91 AF
Additional Frame -> Get More Data
-------------------------------------------------------------------------
Read from a Standard Data file with Free Access Rights and fileSize 255 bytes (Extended)
Send length 13
90 BD 00 00 07 03 00 00 00 FF 00 00 00
Recv length 60
01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F 30 31 32 33 34 35 36 37 38 39 3A 91 AF
Send length 5
90 AF 00 00 00
Recv length 60
3B 3C 3D 3E 3F 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F 50 51 52 53 54 55 56 57 58 59 5A 5B 5C 5D 5E 5F 60 61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F 70 71 72 73 74 91 AF
Get_More_Data Returning ADDITIONAL_FRAME
Send length 5
90 AF 00 00 00
Recv length 60
75 76 77 78 79 7A 7B 7C 7D 7E 7F 80 81 82 83 84 85 86 87 88 89 8A 8B 8C 8D 8E 8F 90 91 92 93 94 95 96 97 98 99 9A 9B 9C 9D 9E 9F A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 AA AB AC AD AE 91 AF
Get_More_Data Returning ADDITIONAL_FRAME
Send length 5
90 AF 00 00 00
Recv length 60
AF B0 B1 B2 B3 B4 B5 B6 B7 B8 B9 BA BB BC BD BE BF C0 C1 C2 C3 C4 C5 C6 C7 C8 C9 CA CB CC CD CE CF D0 D1 D2 D3 D4 D5 D6 D7 D8 D9 DA DB DC DD DE DF E0 E1 E2 E3 E4 E5 E6 E7 E8 91 AF
Get_More_Data Returning ADDITIONAL_FRAME
Send length 5
90 AF 00 00 00
Recv length 25
E9 EA EB EC ED EE EF F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 FA FB FC FD FE FF 91 00
Get_More_Data Returning DF_STATUS_OK
SUCCESS
Read Data response length 255 data: 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F 50 51 52 53 54 55 56 57 58 59 5A 5B 5C 5D 5E 5F 60 61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F 70 71 72 73 74 75 76 77 78 79 7A 7B 7C 7D 7E 7F 80 81 82 83 84 85 86 87 88 89 8A 8B 8C 8D 8E 8F 90 91 92 93 94 95 96 97 98 99 9A 9B 9C 9D 9E 9F A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 AA AB AC AD AE AF B0 B1 B2 B3 B4 B5 B6 B7 B8 B9 BA BB BC BD BE BF C0 C1 C2 C3 C4 C5 C6 C7 C8 C9 CA CB CC CD CE CF D0 D1 D2 D3 D4 D5 D6 D7 D8 D9 DA DB DC DD DE DF E0 E1 E2 E3 E4 E5 E6 E7 E8 E9 EA EB EC ED EE EF F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 FA FB FC FD FE FF
-------------------------------------------------------------------------
Write to a file with Free Access Rights and fileSize 255 bytes
Generated data length 255 data: 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F 50 51 52 53 54 55 56 57 58 59 5A 5B 5C 5D 5E 5F 60 61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F 70 71 72 73 74 75 76 77 78 79 7A 7B 7C 7D 7E 7F 80 81 82 83 84 85 86 87 88 89 8A 8B 8C 8D 8E 8F 90 91 92 93 94 95 96 97 98 99 9A 9B 9C 9D 9E 9F A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 AA AB AC AD AE AF B0 B1 B2 B3 B4 B5 B6 B7 B8 B9 BA BB BC BD BE BF C0 C1 C2 C3 C4 C5 C6 C7 C8 C9 CA CB CC CD CE CF D0 D1 D2 D3 D4 D5 D6 D7 D8 D9 DA DB DC DD DE DF E0 E1 E2 E3 E4 E5 E6 E7 E8 E9 EA EB EC ED EE EF F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 FA FB FC FD FE FF
Send length 12
90 8D 00 00 06 03 00 00 00 FF 00 00
Recv length 2
91 7E
-------------------------------------------------------------------------
Write 242 bytes to a file with Free Access Rights and fileSize 255 bytes
Send length 255
90 8D 00 00 F9 03 00 00 00 F2 00 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F 50 51 52 53 54 55 56 57 58 59 5A 5B 5C 5D 5E 5F 60 61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F 70 71 72 73 74 75 76 77 78 79 7A 7B 7C 7D 7E 7F 80 81 82 83 84 85 86 87 88 89 8A 8B 8C 8D 8E 8F 90 91 92 93 94 95 96 97 98 99 9A 9B 9C 9D 9E 9F A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 AA AB AC AD AE AF B0 B1 B2 B3 B4 B5 B6 B7 B8 B9 BA BB BC BD BE BF C0 C1 C2 C3 C4 C5 C6 C7 C8 C9 CA CB CC CD CE CF D0 D1 D2 D3 D4 D5 D6 D7 D8 D9 DA DB DC DD DE DF E0 E1 E2 E3 E4 E5 E6 E7 E8 E9 EA EB EC ED EE EF F0 F1 F2 00
Recv length 255
6D 07 40 3F 48 00 00 00 00 FF 00 00 00 00 FF 00 64 1A FC 3F CE 2B 0D 80 F0 21 FB 3F 64 1A FC 3F 6D 07 40 3F 6F 21 FB 3F AC 21 FB 3F AB 21 FB 3F 64 1A FC 3F 92 2C 0D 80 10 22 FB 3F CC 17 FC 3F 22 EF AB 11 F2 00 00 00 AB 21 FB 3F 00 00 00 00 80 8D FB 3F 6B 7F 0D 80 50 22 FB 3F 00 00 00 00 03 00 00 00 0A 00 00 00 0C 22 FB 3F FF 00 00 00 FF 00 00 00 6B 7F 0D 80 50 22 FB 3F 00 00 00 00 07 56 78 9A D0 17 FC 3F C8 17 FC 3F 64 DB FB 3F 64 1A FC 3F 65 91 08 80 70 22 FB 3F 00 00 00 00 00 00 00 00 01 00 00 00 FF FF FF FF FF FF FF FF 64 1A FC 3F 00 00 00 00 90 22 FB 3F 38 7F 0D 40 00 00 00 00 01 00 00 00 94 26 FC 3F 8C 81 FB 3F 01 00 00 00 00 00 00 00 B0 22 FB 3F 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
-------------------------------------------------------------------------
Write increasing bytes to a file with Free Access Rights and fileSize 255 bytes
new data length: 209
Send length 222
90 8D 00 00 D8 03 00 00 00 D1 00 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F 50 51 52 53 54 55 56 57 58 59 5A 5B 5C 5D 5E 5F 60 61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F 70 71 72 73 74 75 76 77 78 79 7A 7B 7C 7D 7E 7F 80 81 82 83 84 85 86 87 88 89 8A 8B 8C 8D 8E 8F 90 91 92 93 94 95 96 97 98 99 9A 9B 9C 9D 9E 9F A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 AA AB AC AD AE AF B0 B1 B2 B3 B4 B5 B6 B7 B8 B9 BA BB BC BD BE BF C0 C1 C2 C3 C4 C5 C6 C7 C8 C9 CA CB CC CD CE CF D0 D1 00
Recv length 2
91 00
SUCCESS
new data length: 210
Send length 223
90 8D 00 00 D9 03 00 00 00 D2 00 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F 50 51 52 53 54 55 56 57 58 59 5A 5B 5C 5D 5E 5F 60 61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F 70 71 72 73 74 75 76 77 78 79 7A 7B 7C 7D 7E 7F 80 81 82 83 84 85 86 87 88 89 8A 8B 8C 8D 8E 8F 90 91 92 93 94 95 96 97 98 99 9A 9B 9C 9D 9E 9F A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 AA AB AC AD AE AF B0 B1 B2 B3 B4 B5 B6 B7 B8 B9 BA BB BC BD BE BF C0 C1 C2 C3 C4 C5 C6 C7 C8 C9 CA CB CC CD CE CF D0 D1 D2 00
Recv length 2
91 00
SUCCESS
new data length: 211
Send length 224
90 8D 00 00 DA 03 00 00 00 D3 00 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F 50 51 52 53 54 55 56 57 58 59 5A 5B 5C 5D 5E 5F 60 61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F 70 71 72 73 74 75 76 77 78 79 7A 7B 7C 7D 7E 7F 80 81 82 83 84 85 86 87 88 89 8A 8B 8C 8D 8E 8F 90 91 92 93 94 95 96 97 98 99 9A 9B 9C 9D 9E 9F A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 AA AB AC AD AE AF B0 B1 B2 B3 B4 B5 B6 B7 B8 B9 BA BB BC BD BE BF C0 C1 C2 C3 C4 C5 C6 C7 C8 C9 CA CB CC CD CE CF D0 D1 D2 D3 00
Recv length 255
5C 21 FB 3F 92 2C 0D 80 10 22 FB 3F CC 17 FC 3F D3 00 00 00 15 2C 0D 80 F0 21 FB 3F D3 00 00 00 AB 21 FB 3F 00 00 00 00 80 8D FB 3F AB 21 FB 3F 07 00 00 00 92 2C 0D 80 F0 21 FB 3F C0 21 FB 3F 22 EF AB 11 D3 00 00 00 AB 21 FB 3F 00 00 00 00 80 8D FB 3F 6B 7F 0D 80 50 22 FB 3F 00 00 00 00 03 00 00 00 0A 00 00 00 0C 22 FB 3F FF 00 00 00 FF 00 00 00 6B 7F 0D 80 50 22 FB 3F 00 00 00 00 07 56 78 9A D0 17 FC 3F C8 17 FC 3F 64 DB FB 3F 64 1A FC 3F 65 91 08 80 70 22 FB 3F 00 00 00 00 00 00 00 00 01 00 00 00 FF FF FF FF FF FF FF FF 64 1A FC 3F 00 00 00 00 90 22 FB 3F 38 7F 0D 40 00 00 00 00 01 00 00 00 94 26 FC 3F 8C 81 FB 3F 01 00 00 00 00 00 00 00 B0 22 FB 3F 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
FAIL (not categorized)
-------------------------------------------------------------------------
Write to a Standard Data file with Free Access Rights
and fileSize 255 bytes in chunks
Send length 223
90 8D 00 00 D9 03 00 00 00 D2 00 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F 50 51 52 53 54 55 56 57 58 59 5A 5B 5C 5D 5E 5F 60 61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F 70 71 72 73 74 75 76 77 78 79 7A 7B 7C 7D 7E 7F 80 81 82 83 84 85 86 87 88 89 8A 8B 8C 8D 8E 8F 90 91 92 93 94 95 96 97 98 99 9A 9B 9C 9D 9E 9F A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 AA AB AC AD AE AF B0 B1 B2 B3 B4 B5 B6 B7 B8 B9 BA BB BC BD BE BF C0 C1 C2 C3 C4 C5 C6 C7 C8 C9 CA CB CC CD CE CF D0 D1 D2 00
Recv length 2
91 00
Send length 58
90 8D 00 00 34 03 D2 00 00 2D 00 00 D3 D4 D5 D6 D7 D8 D9 DA DB DC DD DE DF E0 E1 E2 E3 E4 E5 E6 E7 E8 E9 EA EB EC ED EE EF F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 FA FB FC FD FE FF 00
Recv length 2
91 00
SUCCESS
-------------------------------------------------------------------------
T02 Large File Handling END
-------------------------------------------------------------------------







