flash: nor: use binary prefixes consistently
[openocd.git] / src / flash / nor / kinetis.c
index c1a49fd54acf624a3554af63dc331001cad0187d..61e7b17abde73875b25a70ee50e0236669801d12 100644 (file)
@@ -1,3 +1,5 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
 /***************************************************************************
  *   Copyright (C) 2011 by Mathias Kuester                                 *
  *   kesmtp@freenet.de                                                     *
  *                                                                         *
  *   Copyright (C) 2015 Tomas Vanek                                        *
  *   vanekt@fbl.cz                                                         *
- *                                                                         *
- *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
- *                                                                         *
- *   This program is distributed in the hope that it will be useful,       *
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
- *   GNU General Public License for more details.                          *
- *                                                                         *
- *   You should have received a copy of the GNU General Public License     *
- *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
  ***************************************************************************/
 
 #ifdef HAVE_CONFIG_H
 #define SMC_PMSTAT     0x4007E003
 #define SMC32_PMCTRL   0x4007E00C
 #define SMC32_PMSTAT   0x4007E014
+#define PMC_REGSC      0x4007D002
+#define MC_PMCTRL      0x4007E003
 #define MCM_PLACR      0xF000300C
 
 /* Offsets */
 #define KINETIS_K_SDID_K60_M150  0x000001C0
 #define KINETIS_K_SDID_K70_M150  0x000001D0
 
+#define KINETIS_K_REVID_MASK   0x0000F000
+#define KINETIS_K_REVID_SHIFT  12
+
 #define KINETIS_SDID_SERIESID_MASK 0x00F00000
 #define KINETIS_SDID_SERIESID_K   0x00000000
 #define KINETIS_SDID_SERIESID_KL   0x00100000
@@ -309,6 +303,7 @@ struct kinetis_chip {
        enum {
                KINETIS_SMC,
                KINETIS_SMC32,
+               KINETIS_MC,
        } sysmodectrlr_type;
 
        char name[40];
@@ -1548,6 +1543,17 @@ static int kinetis_read_pmstat(struct kinetis_chip *k_chip, uint8_t *pmstat)
                if (result == ERROR_OK)
                        *pmstat = stat32 & 0xff;
                return result;
+
+       case KINETIS_MC:
+               /* emulate SMC by reading PMC_REGSC bit 3 (VLPRS) */
+               result = target_read_u8(target, PMC_REGSC, pmstat);
+               if (result == ERROR_OK) {
+                       if (*pmstat & 0x08)
+                               *pmstat = PM_STAT_VLPR;
+                       else
+                               *pmstat = PM_STAT_RUN;
+               }
+               return result;
        }
        return ERROR_FAIL;
 }
@@ -1588,6 +1594,10 @@ static int kinetis_check_run_mode(struct kinetis_chip *k_chip)
                case KINETIS_SMC32:
                        result = target_write_u32(target, SMC32_PMCTRL, PM_CTRL_RUNM_RUN);
                        break;
+
+               case KINETIS_MC:
+                       result = target_write_u32(target, MC_PMCTRL, PM_CTRL_RUNM_RUN);
+                       break;
                }
                if (result != ERROR_OK)
                        return result;
@@ -2154,6 +2164,24 @@ static int kinetis_probe_chip(struct kinetis_chip *k_chip)
                        }
                }
 
+               /* first revision of some devices has no SMC */
+               switch (mcu_type) {
+               case KINETIS_K_SDID_K10_M100:
+               case KINETIS_K_SDID_K20_M100:
+               case KINETIS_K_SDID_K30_M100:
+               case KINETIS_K_SDID_K40_M100:
+               case KINETIS_K_SDID_K60_M100:
+                       {
+                               uint32_t revid = (k_chip->sim_sdid & KINETIS_K_REVID_MASK) >> KINETIS_K_REVID_SHIFT;
+                                /* highest bit set corresponds to rev 2.x */
+                               if (revid <= 7) {
+                                       k_chip->sysmodectrlr_type = KINETIS_MC;
+                                       strcat(name, " Rev 1.x");
+                               }
+                       }
+                       break;
+               }
+
        } else {
                /* Newer K-series or KL series MCU */
                familyid = (k_chip->sim_sdid & KINETIS_SDID_FAMILYID_MASK) >> KINETIS_SDID_FAMILYID_SHIFT;
@@ -2634,12 +2662,12 @@ static int kinetis_probe_chip(struct kinetis_chip *k_chip)
 
        snprintf(k_chip->name, sizeof(k_chip->name), name, flash_marking);
        LOG_INFO("Kinetis %s detected: %u flash blocks", k_chip->name, num_blocks);
-       LOG_INFO("%u PFlash banks: %" PRIu32 "k total", k_chip->num_pflash_blocks, pflash_size_k);
+       LOG_INFO("%u PFlash banks: %" PRIu32 " KiB total", k_chip->num_pflash_blocks, pflash_size_k);
        if (k_chip->num_nvm_blocks) {
                nvm_size_k = k_chip->nvm_size / 1024;
                dflash_size_k = k_chip->dflash_size / 1024;
-               LOG_INFO("%u FlexNVM banks: %" PRIu32 "k total, %" PRIu32 "k available as data flash, %" PRIu32 "bytes FlexRAM",
-                        k_chip->num_nvm_blocks, nvm_size_k, dflash_size_k, ee_size);
+               LOG_INFO("%u FlexNVM banks: %" PRIu32 " KiB total, %" PRIu32 " KiB available as data flash, %"
+                        PRIu32 " bytes FlexRAM", k_chip->num_nvm_blocks, nvm_size_k, dflash_size_k, ee_size);
        }
 
        k_chip->probed = true;

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)