This is an automated email from Gerrit.

"Martin Hierholzer <h...@beta-centauri.de>" just uploaded a new patch set to 
Gerrit, which you can find at https://review.openocd.org/c/openocd/+/7015

-- gerrit

commit 88618b17a0d61661adc904a6b0a8b82564bc879c
Author: Martin Hierholzer <martin.hierhol...@desy.de>
Date:   Fri May 27 15:22:25 2022 +0200

    fix Kinetis 100 MHz rev 1.x programming
    
    Kinetis 100 MHz rev 1.x devices have no SMC and hence need different
    checking of the run mode. Details about the differences between rev 1.x
    and 2.x of the Kinetis 100 MHz series can be found here:
    https://www.nxp.com.cn/docs/en/application-note/AN4445.pdf
    
    Signed-off-by: Martin Hierholzer <martin.hierhol...@desy.de>
    Change-Id: Ib705385a931275159bdae9b31caecc6ec9c0da1e

diff --git a/src/flash/nor/kinetis.c b/src/flash/nor/kinetis.c
index edb4eb58fe..6dc645e139 100644
--- a/src/flash/nor/kinetis.c
+++ b/src/flash/nor/kinetis.c
@@ -108,6 +108,8 @@
 #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 */
@@ -199,6 +201,9 @@
 #define KINETIS_K_SDID_K60_M150  0x000001C0
 #define KINETIS_K_SDID_K70_M150  0x000001D0
 
+#define KINETIS_K_REVID_TYPE_MASK      0x0000F000
+#define KINETIS_K_REVID_TYPE_SHIFT     12
+
 #define KINETIS_SDID_SERIESID_MASK 0x00F00000
 #define KINETIS_SDID_SERIESID_K   0x00000000
 #define KINETIS_SDID_SERIESID_KL   0x00100000
@@ -309,6 +314,7 @@ struct kinetis_chip {
        enum {
                KINETIS_SMC,
                KINETIS_SMC32,
+               KINETIS_MC,
        } sysmodectrlr_type;
 
        char name[40];
@@ -1529,6 +1535,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;
 }
@@ -1569,6 +1586,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;
@@ -2135,6 +2156,25 @@ 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_TYPE_MASK) >> KINETIS_K_REVID_TYPE_SHIFT;
+                                /* highest bit set corresponds to rev 2.x */
+                               if (revid <= 7) {
+                                       k_chip->sysmodectrlr_type = KINETIS_MC;
+                                       size_t l = strlen(name);
+                                       strcpy(name+l, " 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;

-- 

Reply via email to