hydrabus / hydrafw_hydranfc_shield_v2

HydraFW dedicated to HydraBus v1 / HydraNFC Shield v2
Apache License 2.0
39 stars 11 forks source link

Incorrect management of nfc_mode/nfc_mode_tx_bitrate/nfc_mode_rx_bitrate value with set-nfc-mode in dnfc menu #9

Closed gvinet closed 3 years ago

gvinet commented 3 years ago

I want to use a vicinity card in dfnc menu, so I want to configure it like in rfalNfcvPollerInitialize:

    EXIT_ON_ERR( ret, rfalSetMode( RFAL_MODE_POLL_NFCV, RFAL_BR_26p48, RFAL_BR_26p48 ) );

I go in dnfc mode to set NFCV

dnfc2> set-nfc-mode nfc-mode 7
nfc-mode = 7
nfc-mode-tx_br = 0
nfc-mode-rx_br = 0
rfalSetMode Error 7

But, the error 7 is raised. Why? We go in hydranfc_v2_dnfc_mode.c file, in exec function. First, the mode is copied

memcpy(&nfc_mode, p->buf + p->tokens[t], sizeof(int));

Then, it is set

        case T_SET_NFC_MODE:
        {
            ReturnCode err;
            cprintf(con, "nfc-mode = %d\r\n", nfc_mode);
            cprintf(con, "nfc-mode-tx_br = %d\r\n", nfc_mode_tx_bitrate);
            cprintf(con, "nfc-mode-rx_br = %d\r\n", nfc_mode_rx_bitrate);
            err = rfalSetMode(nfc_mode, nfc_mode_tx_bitrate, nfc_mode_rx_bitrate);

but the default value for nfc_mode_tx_bitrate/nfc_mode_rx_bitrate are not compatible, so an error is raised.

Ok, but if I want to update the rx mode for instance, the mode modification is not taken into account:

dnfc2> set-nfc-mode nfc-mode-tx_br 236
nfc-mode = 0
nfc-mode-tx_br = 236
nfc-mode-rx_br = 0
rfalSetMode Error 15

It comes from the previous modification was not recorded: default value are retrieved at the beginning of exec function:

    action = nfc_mode =  nfc_mode_tx_bitrate = nfc_mode_rx_bitrate = 0;

nfc_mode, nfc_mode_tx_bitrate, nfc_mode_rx_bitrate could be move out the function and be defined as global to resolve this problem.

bvernoux commented 3 years ago

About error with

dnfc2> set-nfc-mode nfc-mode 7
nfc-mode = 7
nfc-mode-tx_br = 0
nfc-mode-rx_br = 0
rfalSetMode Error 7

It is normal to have an error with that configuration as RFAL_MODE_POLL_NFCV does not support nfc-mode-tx_br / nfc-mode-rx_br RFAL_BR_106 (0) It support only nfc-mode-tx_br => RFAL_BR_1p66 or RFAL_BR_26p48 nfc-mode-rx_br =>RFAL_BR_26p48 or RFAL_BR_52p97

    RFAL_BR_52p97                    = 0xEB, /*!< Bit Rate 52.97 kbit/s (fc/256) Fast Mode VICC->VCD               */
    RFAL_BR_26p48                    = 0xEC, /*!< Bit Rate 26,48 kbit/s (fc/512) NFCV VICC->VCD & VCD->VICC 1of4   */
    RFAL_BR_1p66                     = 0xED, /*!< Bit Rate 1,66 kbit/s (fc/8192) NFCV VCD->VICC 1of256             */

Yes so far it is intended to be done in one step like that

dnfc2> set-nfc-mode nfc-mode 7 nfc-mode-tx_br 236 nfc-mode-rx_br 236
nfc-mode = 7
nfc-mode-tx_br = 236
nfc-mode-rx_br = 236
rfalSetMode OK
dnfc2> get-nfc-mode
nfc-mode = 7
nfc-mode-tx_br = 236
nfc-mode-rx_br = 236

I'm agree that it can be improved to keep previous value if they are not defined

bvernoux commented 3 years ago

Now it is fixed and tested with different cases

dnfc2> set-nfc-mode nfc-mode 7
nfc-mode = 7
nfc-mode-tx_br = 0
nfc-mode-rx_br = 0
rfalSetMode Error 7
dnfc2> set-nfc-mode nfc-mode-tx_br 236
nfc-mode = 7
nfc-mode-tx_br = 236
nfc-mode-rx_br = 0
rfalSetMode Error 7
dnfc2> set-nfc-mode nfc-mode-rx_br 236
nfc-mode = 7
nfc-mode-tx_br = 236
nfc-mode-rx_br = 236
rfalSetMode OK
dnfc2> set-nfc-mode nfc-mode 1 nfc-mode-tx_br 0 nfc-mode-rx_br 0
nfc-mode = 1
nfc-mode-tx_br = 0
nfc-mode-rx_br = 0
rfalSetMode OK
dnfc2> set-nfc-mode nfc-mode 7 nfc-mode-tx_br 236 nfc-mode-rx_br 236
nfc-mode = 7
nfc-mode-tx_br = 236
nfc-mode-rx_br = 236
rfalSetMode OK