Kinetis: fix preparation of FlexRAM before flash programming 90/2990/4
authorTomas Vanek <vanekt@fbl.cz>
Thu, 1 Oct 2015 21:35:12 +0000 (23:35 +0200)
committerAndreas Fritiofson <andreas.fritiofson@gmail.com>
Mon, 15 Feb 2016 19:45:40 +0000 (19:45 +0000)
FlexRAM should be requested before any section programming.
Test FCNFG RAMRDY bit before issuing FTFx_CMD_SETFLEXRAM
to speed up operation and to cover pflash only devices.

Change-Id: Ib0f2d8e8ab8b1507cbf2b7f8565178ab79941f5d
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: http://openocd.zylin.com/2990
Tested-by: jenkins
src/flash/nor/kinetis.c

index 5b618c03e30d7a4b8a0d45ea932a81156a7058e9..a1625ffee64bef805d74904a4eeca452f0f5e6ed 100644 (file)
@@ -984,11 +984,41 @@ static int kinetis_erase(struct flash_bank *bank, int first, int last)
        return ERROR_OK;
 }
 
        return ERROR_OK;
 }
 
+static int kinetis_make_ram_ready(struct target *target)
+{
+       int result;
+       uint8_t ftfx_fstat;
+       uint8_t ftfx_fcnfg;
+
+       /* check if ram ready */
+       result = target_read_memory(target, FTFx_FCNFG, 1, 1, &ftfx_fcnfg);
+       if (result != ERROR_OK)
+               return result;
+
+       if (ftfx_fcnfg & (1 << 1))
+               return ERROR_OK;        /* ram ready */
+
+       /* make flex ram available */
+       result = kinetis_ftfx_command(target, FTFx_CMD_SETFLEXRAM, 0x00ff0000,
+                                0, 0, 0, 0,  0, 0, 0, 0,  &ftfx_fstat);
+       if (result != ERROR_OK)
+               return ERROR_FLASH_OPERATION_FAILED;
+
+       /* check again */
+       result = target_read_memory(target, FTFx_FCNFG, 1, 1, &ftfx_fcnfg);
+       if (result != ERROR_OK)
+               return result;
+
+       if (ftfx_fcnfg & (1 << 1))
+               return ERROR_OK;        /* ram ready */
+
+       return ERROR_FLASH_OPERATION_FAILED;
+}
+
 static int kinetis_write(struct flash_bank *bank, const uint8_t *buffer,
                         uint32_t offset, uint32_t count)
 {
        unsigned int i, result, fallback = 0;
 static int kinetis_write(struct flash_bank *bank, const uint8_t *buffer,
                         uint32_t offset, uint32_t count)
 {
        unsigned int i, result, fallback = 0;
-       uint8_t buf[8];
        uint32_t wc;
        struct kinetis_flash_bank *kinfo = bank->driver_priv;
        uint8_t *new_buffer = NULL;
        uint32_t wc;
        struct kinetis_flash_bank *kinfo = bank->driver_priv;
        uint8_t *new_buffer = NULL;
@@ -1002,36 +1032,16 @@ static int kinetis_write(struct flash_bank *bank, const uint8_t *buffer,
                /* fallback to longword write */
                fallback = 1;
                LOG_WARNING("This device supports Program Longword execution only.");
                /* fallback to longword write */
                fallback = 1;
                LOG_WARNING("This device supports Program Longword execution only.");
-               LOG_DEBUG("flash write into PFLASH @08%" PRIX32, offset);
-
-       } else if (kinfo->flash_class == FC_FLEX_NVM) {
-               uint8_t ftfx_fstat;
-
-               LOG_DEBUG("flash write into FlexNVM @%08" PRIX32, offset);
-
-               /* make flex ram available */
-               result = kinetis_ftfx_command(bank->target, FTFx_CMD_SETFLEXRAM, 0x00ff0000,
-                               0, 0, 0, 0,  0, 0, 0, 0,  &ftfx_fstat);
-
-               if (result != ERROR_OK)
-                       return ERROR_FLASH_OPERATION_FAILED;
-
-               /* check if ram ready */
-               result = target_read_memory(bank->target, FTFx_FCNFG, 1, 1, buf);
-
-               if (result != ERROR_OK)
-                       return result;
-
-               if (!(buf[0] & (1 << 1))) {
-                       /* fallback to longword write */
+       } else {
+               result = kinetis_make_ram_ready(bank->target);
+               if (result != ERROR_OK) {
                        fallback = 1;
                        fallback = 1;
-
-                       LOG_WARNING("ram not ready, fallback to slow longword write (FCNFG: %02X)", buf[0]);
+                       LOG_WARNING("FlexRAM not ready, fallback to slow longword write.");
                }
                }
-       } else {
-               LOG_DEBUG("flash write into PFLASH @08%" PRIX32, offset);
        }
 
        }
 
+       LOG_DEBUG("flash write @08%" PRIX32, offset);
+
 
        /* program section command */
        if (fallback == 0) {
 
        /* program section command */
        if (fallback == 0) {

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)