cancel
Showing results for 
Search instead for 
Did you mean: 

Setting GPO from Android app throws exception - on some mobile phones

MLuki.1
Associate II

Hi,

I am trying to set the GPO pin on a ST25DV based device from an Android app. I am using the following code:

AndroidReaderInterface reader = AndroidReaderInterface.newInstance(mTag);
try {
   ST25DVTag mTag = new ST25DVTag(reader, ((Type5Tag) mNFCTag).getUid());
   byte response = mTag.manageGpoCommand(ST25DVTag.GpoCommand.SET, (byte)0x00);
   Log.i(TAG, "Response: " + Helper.convertByteToHexString(response));
} catch (STException | Exception e) {
   Log.w(TAG, "ManageGPO failed: " + e.getMessage());
}

This is what we concluded so far:

1. The NFC device really receive the command and set the GPO. We confirmed this with oscilloscope.

2. We tested the app on 2 different Samsung phones and Xiaomi. The same code executed fine on one mobile phone but throws an exception on two others.

What are we doing wrong?

Many thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
MLuki.1
Associate II

Dear France,

Thank you for your answer. We played a bit with flags and we find out that the command executes with Response: 00 (and without throwing exception in android.nfc nor iOS nfc library) if we use flags 02 instead 00.

We tested it on X-NUCLEO board and confirmed that Manage GPO is set to zero with 0x02 a9 02 00 and set to one with 0x 02 a9 02 01.

Many thanks for your help!

Marko

View solution in original post

4 REPLIES 4
Ulysses HERNIOSUS
ST Employee

Hello,

I think the actual logged information will be quite interesting for people analyzing this.

Regards, Ulysses

MLuki.1
Associate II

I don't know what else to add here. The command I try to send is 00 A9 02 01. I tried same thing in various ways:

// try: #1
NfcV nfcV = NfcV.get(mTag);
byte[] command = new byte[]{0, -87, 2, 1};
try {
    byte[] result = nfcV.transceive(command);
    Log.i(TAG, "Response: " + Helper.convertByteArrayToHexString(result));
} catch (IOException e) {
    Log.w(TAG, "ManageGPO failed: " + e.getMessage());
}
// try: #2
AndroidReaderInterface reader = AndroidReaderInterface.newInstance(mTag);
try {
    ST25DVTag mTag = new ST25DVTag(reader, ((Type5Tag) mNFCTag).getUid());
    byte result = mTag.manageGpoCommand(ST25DVTag.GpoCommand.SET, (byte)0x00);
    Log.i(TAG, "Response: " + Helper.convertByteToHexString(result));
} catch (STException | Exception e) {
    Log.w(TAG, "ManageGPO failed: " + e.getMessage());
}
//try: #3
AndroidReaderInterface reader = AndroidReaderInterface.newInstance(mTag);
Iso15693CustomCommand mIso15693CustomCommand = new Iso15693CustomCommand(reader, mTag.getId());
try {
    byte result = mIso15693CustomCommand.manageGpo((byte)0x01, (byte)0x00, mTag.getId());
    Log.i(TAG, "Response: " + Helper.convertByteToHexString(result));
} catch (STException | Exception e) {
    Log.w(TAG, "ManageGPO failed: " + e.getMessage());
}

They all end up calling mTag.getTagService().transceive(...) from BasicTagTechnology.java

The transcieve method returns result with mResult = 2 and mResponseData = null. This raises TagLostException.

The mobile phone is literally lying on NFC antenna of the ST25 device and is continuously successfully discovering the tag.

This is Console output:

I/ManageGPO: Starting Tag discovery
V/TagDiscovery: Starting TagDiscovery
D/Iso15693Command: ==> Send getSystemInfo command: 22 2b 1b 07 59 3e 02 26 02 e0
D/Iso15693Command: Response: 00 0b 1b 07 59 3e 02 26 02 e0 00 00 26
D/Iso15693Command: ==> Send extendedGetSystemInfo command: 22 3b 7f 1b 07 59 3e 02 26 02 e0
D/Iso15693Command: Response: 00 3f 1b 07 59 3e 02 26 02 e0 00 00 ff 07 03 26 ff 3f 3f 00
D/Iso15693Command: ==> Send readSingleBlock command: 22 20 1b 07 59 3e 02 26 02 e0 00
D/Iso15693Command: Response: 00 e2 40 00 01
D/Iso15693CustomCommand: ==> Send extendedGetSystemInfo command: 22 3b 7f 1b 07 59 3e 02 26 02 e0
D/Iso15693CustomCommand: Response: 00 3f 1b 07 59 3e 02 26 02 e0 00 00 ff 07 03 26 ff 3f 3f 00
D/Iso15693CustomCommand: ==> Send readConfig command: 22 a0 02 1b 07 59 3e 02 26 02 e0 05
D/Iso15693CustomCommand: Response: 00 07
D/Iso15693CustomCommand: ==> Send readConfig command: 22 a0 02 1b 07 59 3e 02 26 02 e0 07
D/Iso15693CustomCommand: Response: 00 0f
D/Iso15693CustomCommand: ==> Send readConfig command: 22 a0 02 1b 07 59 3e 02 26 02 e0 09
D/Iso15693CustomCommand: Response: 00 ff
I/ManageGPO: Tag discovery done. Found tag: ST25DV64K-I
W/ManageGPO: ManageGPO failed: Tag was lost.

Edit:

After testing with ST25 Android app, we noticed that the same CustomCommand (00 A9 02 01) executes well on one Samsung phone (S20, Android 12, with S3NRN4V NFC chip) but returns TAG NOT IN THE FIELD on another Samsung phone (S21, Android 12, with SN110UV3 NFC chip).

France Berthelot
ST Employee

Hello

Not easy to get same context, but here a possible reason:

On receiving the Manage GPO command. Depending on the command argument, the ST25DV force the GPO output level if RF_USER interrupt is enabled, or send a pulse on GPO output if RF_INTERRUPT is enabled. If neither RF_USER nor RF_INTERRUPT was enabled, the command is not executed and ST25DVxxx responds an Error code “0F�? ...

here after some tests:

2023-05-10 09:45:11.358 21531-21642 Iso15693Protocol    com.st.st25nfc.dbg          D ==> Send custom_cmd command: 22 a9 02 09 0e 66 02 00 24 02 e0 01

2023-05-10 09:45:11.368 21531-21642 Iso15693Protocol    com.st.st25nfc.dbg          D Response: 00

Registers:


_legacyfs_online_stmicro_images_0693W00000bjlNoQAI.pngPlease check that :

bits b0 RF_USER_EN=1 and b7 GPO_EN=1


_legacyfs_online_stmicro_images_0693W00000bjlONQAY.pngConcerning behaviors on mobiles, no ideas at this stage

Best regards, FB

MLuki.1
Associate II

Dear France,

Thank you for your answer. We played a bit with flags and we find out that the command executes with Response: 00 (and without throwing exception in android.nfc nor iOS nfc library) if we use flags 02 instead 00.

We tested it on X-NUCLEO board and confirmed that Manage GPO is set to zero with 0x02 a9 02 00 and set to one with 0x 02 a9 02 01.

Many thanks for your help!

Marko