From 7cba71ab8b8457f6ad8f68273971da239a6df0f6 Mon Sep 17 00:00:00 2001 From: Fan DANG Date: Wed, 13 Dec 2023 22:03:03 +0800 Subject: [PATCH 1/2] fix fm11nt initialization --- include/nfc.h | 1 + interfaces/NFC/fm.c | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/include/nfc.h b/include/nfc.h index 23a73c3e..a5f5ad15 100644 --- a/include/nfc.h +++ b/include/nfc.h @@ -56,6 +56,7 @@ #define FM_EEPROM_USER_CFG0 0x0390 #define FM_EEPROM_USER_CFG1 0x0391 #define FM_EEPROM_USER_CFG2 0x0392 +#define FM_EEPROM_ATS 0x03B0 #define FM_EEPROM_ATQA 0x03BC #define FM_EEPROM_CRC8 0x03BB diff --git a/interfaces/NFC/fm.c b/interfaces/NFC/fm.c index b34491ad..33d081e3 100644 --- a/interfaces/NFC/fm.c +++ b/interfaces/NFC/fm.c @@ -135,9 +135,11 @@ void fm11_init(void) { uint8_t crc_buffer[13]; const uint8_t user_cfg[] = {0x91, 0x82, 0x21, 0xCD}; const uint8_t atqa_sak[] = {0x44, 0x00, 0x04, 0x20}; + const uint8_t ats[] = {0x05, 0x72, 0x80, 0x57, 0x00, 0x99, 0x00}; fm_csn_low(); - device_delay_us(200); + device_delay_us(500); fm_write_eeprom(FM_EEPROM_USER_CFG0, user_cfg, sizeof(user_cfg)); + fm_write_eeprom(FM_EEPROM_ATS, ats, sizeof(ats)); fm_write_eeprom(FM_EEPROM_ATQA, atqa_sak, sizeof(atqa_sak)); fm_read_eeprom(FM_EEPROM_SN, crc_buffer, 9); DBG_MSG("SN: "); PRINT_HEX(crc_buffer, 9); From 31c1410165dbc8b259334826928fd6fe5f62b607 Mon Sep 17 00:00:00 2001 From: Fan DANG Date: Fri, 15 Dec 2023 21:32:00 +0800 Subject: [PATCH 2/2] fix NFC warnings and rename constants --- include/device.h | 2 +- include/nfc.h | 3 +++ interfaces/NFC/fm.c | 16 ++++++++-------- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/include/device.h b/include/device.h index 9df09ce1..d277c36e 100644 --- a/include/device.h +++ b/include/device.h @@ -66,7 +66,7 @@ void fm_csn_low(void); */ void fm_csn_high(void); #if NFC_CHIP == NFC_CHIP_FM11NC -void spi_transmit(uint8_t *buf, uint8_t len); +void spi_transmit(const uint8_t *buf, uint8_t len); void spi_receive(uint8_t *buf, uint8_t len); #elif NFC_CHIP == NFC_CHIP_FM11NT void i2c_start(void); diff --git a/include/nfc.h b/include/nfc.h index a5f5ad15..61db157b 100644 --- a/include/nfc.h +++ b/include/nfc.h @@ -27,6 +27,9 @@ #define FM_REG_NFC_CFG 0xD #define FM_REG_REGU_CFG 0xE +#define FM_EEPROM_ATQA 0x03A0 +#define FM_EEPROM_ATS 0x03B0 + #define RF_STATE_MASK 0xE0 #elif NFC_CHIP == NFC_CHIP_FM11NT diff --git a/interfaces/NFC/fm.c b/interfaces/NFC/fm.c index 33d081e3..a94c8d44 100644 --- a/interfaces/NFC/fm.c +++ b/interfaces/NFC/fm.c @@ -121,16 +121,16 @@ void fm_write_fifo(uint8_t *buf, uint8_t len) { void fm11_init(void) { #if NFC_CHIP == NFC_CHIP_FM11NC uint8_t buf[7]; - uint8_t data1[] = {0x44, 0x00, 0x04, 0x20}; - uint8_t data2[] = {0x05, 0x72, 0x02, 0x00, 0xB3, 0x99, 0x00}; + uint8_t atqa_sak[] = {0x44, 0x00, 0x04, 0x20}; + uint8_t ats[] = {0x05, 0x72, 0x02, 0x00, 0xB3, 0x99, 0x00}; do { - fm_write_eeprom(0x3A0, data1, sizeof(data1)); - fm_read_eeprom(0x3A0, buf, sizeof(data1)); - } while (memcmp(data1, buf, sizeof(data1)) != 0); + fm_write_eeprom(FM_EEPROM_ATQA, atqa_sak, sizeof(atqa_sak)); + fm_read_eeprom(FM_EEPROM_ATQA, buf, sizeof(atqa_sak)); + } while (memcmp(atqa_sak, buf, sizeof(atqa_sak)) != 0); do { - fm_write_eeprom(0x3B0, data2, sizeof(data2)); - fm_read_eeprom(0x3B0, buf, sizeof(data2)); - } while (memcmp(data2, buf, sizeof(data2)) != 0); + fm_write_eeprom(FM_EEPROM_ATS, ats, sizeof(ats)); + fm_read_eeprom(FM_EEPROM_ATS, buf, sizeof(ats)); + } while (memcmp(ats, buf, sizeof(ats)) != 0); #elif NFC_CHIP == NFC_CHIP_FM11NT uint8_t crc_buffer[13]; const uint8_t user_cfg[] = {0x91, 0x82, 0x21, 0xCD};