From ba46863c427eaffab21ed2658d791816580b5fdf Mon Sep 17 00:00:00 2001 From: "heikki.rautakoski" Date: Thu, 24 May 2018 14:52:18 +0300 Subject: [PATCH] Fix write_enable commands and method. -This only has effect if sector protection enabled. --- DataFlashBlockDevice.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/DataFlashBlockDevice.cpp b/DataFlashBlockDevice.cpp index a5d9d3da8c..cbff1948f3 100644 --- a/DataFlashBlockDevice.cpp +++ b/DataFlashBlockDevice.cpp @@ -60,8 +60,8 @@ enum opcode { /* non-exhaustive command list */ enum command { - DATAFLASH_COMMAND_WRITE_DISABLE = 0x3D2A7F9A, - DATAFLASH_COMMAND_WRITE_ENABLE = 0x3D2A7FA9, + DATAFLASH_COMMAND_WRITE_DISABLE = 0x3D2A7FA9, + DATAFLASH_COMMAND_WRITE_ENABLE = 0x3D2A7F9A, DATAFLASH_COMMAND_BINARY_PAGE_SIZE = 0x3D2A80A6, DATAFLASH_COMMAND_DATAFLASH_PAGE_SIZE = 0x3D2A80A7, }; @@ -525,22 +525,20 @@ void DataFlashBlockDevice::_write_enable(bool enable) /* enable writing, disable write protection */ if (enable) { + /* if not-write-protected pin is connected, select it */ + if (_nwp.is_connected()) { + _nwp = 1; + } /* send 4 byte command enabling writes */ _write_command(DATAFLASH_COMMAND_WRITE_ENABLE, NULL, 0); + } else { /* if not-write-protected pin is connected, deselect it */ if (_nwp.is_connected()) { _nwp = 0; } - } else { - - /* if not-write-protected pin is connected, select it */ - if (_nwp.is_connected()) { - _nwp = 1; - } - /* send 4 byte command disabling writes */ _write_command(DATAFLASH_COMMAND_WRITE_DISABLE, NULL, 0); }