Skip to content

Commit

Permalink
Merge pull request #75 from canokeys/feature/fm11nt
Browse files Browse the repository at this point in the history
fix fm11nt initialization
  • Loading branch information
z4yx committed Dec 16, 2023
2 parents 7c90969 + 31c1410 commit 4db715b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion include/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions include/nfc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -56,6 +59,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

Expand Down
20 changes: 11 additions & 9 deletions interfaces/NFC/fm.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,23 +121,25 @@ 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};
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);
Expand Down

0 comments on commit 4db715b

Please sign in to comment.