From 66850be6e55085126677aa4ab5cbcda8647cfe02 Mon Sep 17 00:00:00 2001 From: Donatien Garnier Date: Tue, 28 Aug 2018 16:53:06 +0100 Subject: [PATCH] Fix NFCEEPROM erasing flow --- features/nfc/nfc/NFCEEPROM.h | 3 ++- features/nfc/source/nfc/NFCEEPROM.cpp | 26 +++++++++++++++++++------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/features/nfc/nfc/NFCEEPROM.h b/features/nfc/nfc/NFCEEPROM.h index 7587c443c0..312af06f3d 100644 --- a/features/nfc/nfc/NFCEEPROM.h +++ b/features/nfc/nfc/NFCEEPROM.h @@ -133,8 +133,9 @@ private: nfc_eeprom_read_end_session, nfc_eeprom_erase_start_session, + nfc_eeprom_erase_write_max_size, nfc_eeprom_erase_erase_bytes, - nfc_eeprom_erase_write_size, + nfc_eeprom_erase_write_0_size, nfc_eeprom_erase_end_session }; diff --git a/features/nfc/source/nfc/NFCEEPROM.cpp b/features/nfc/source/nfc/NFCEEPROM.cpp index 582722b573..1ad9486b32 100644 --- a/features/nfc/source/nfc/NFCEEPROM.cpp +++ b/features/nfc/source/nfc/NFCEEPROM.cpp @@ -125,9 +125,10 @@ void NFCEEPROM::erase_ndef_message() _driver->start_session(); // 1 - Start session - // 2 - Erase bytes (can be repeated) - // 3 - Set NDEF message size to 0 - // 4 - End session + // 2 - Set addressable size to the max + // 3 - Erase bytes (can be repeated) + // 4 - Set addressable size to 0 + // 5 - End session } void NFCEEPROM::on_session_started(bool success) @@ -156,8 +157,9 @@ void NFCEEPROM::on_session_started(bool success) handle_error(NFC_ERR_CONTROLLER); return; } - _current_op = nfc_eeprom_erase_erase_bytes; - continue_erase(); + + _current_op = nfc_eeprom_erase_write_max_size; + _driver->write_size(_driver->get_max_size()); break; default: @@ -276,7 +278,17 @@ void NFCEEPROM::on_size_written(bool success) _operation_result = NFC_OK; _driver->end_session(); break; - case nfc_eeprom_erase_write_size: + case nfc_eeprom_erase_write_max_size: + if (!success) { + handle_error(NFC_ERR_CONTROLLER); + return; + } + + // Start erasing bytes + _current_op = nfc_eeprom_erase_erase_bytes; + continue_erase(); + break; + case nfc_eeprom_erase_write_0_size: if (!success) { handle_error(NFC_ERR_CONTROLLER); return; @@ -373,7 +385,7 @@ void NFCEEPROM::continue_erase() _driver->erase_bytes(_eeprom_address, _driver->get_max_size() - _eeprom_address); } else { // Now update size - _current_op = nfc_eeprom_erase_write_size; + _current_op = nfc_eeprom_erase_write_0_size; _driver->write_size(0); } }