I modified detection part inside "kinetis.c" file from OpenOCD to support K32L2 devices...
case KINETIS_SDID_SERIESID_KL:
/* KL-series */
k_chip->pflash_sector_size = 1<<10;
k_chip->nvm_sector_size = 1<<10;
/* autodetect 1 or 2 blocks */
k_chip->flash_support = FS_PROGRAM_LONGWORD;
k_chip->cache_type = KINETIS_CACHE_L;
k_chip->watchdog_type = KINETIS_WDOG_COP;
cpu_mhz = 48;
if ((k_chip->sim_sdid & KINETIS_SDID_SUBFAMID_MASK) == KINETIS_SDID_SUBFAMID_KX1) {
/* K32L2 series */
result = target_read_u32(target, k_chip->sim_base + SIM_FCFG1_OFFSET, &k_chip->sim_fcfg1);
if (result != ERROR_OK)
return result;
switch (k_chip->sim_sdid & KINETIS_SDID_FAMILYID_MASK) {
case KINETIS_SDID_FAMILYID_K4X:
subfamid = 7;
switch (k_chip->sim_fcfg1 >> 24) {
case 0x5: snprintf(name, sizeof(name), "K32L2B11"); break; /* flash 64k */
case 0x7: snprintf(name, sizeof(name), "K32L2B21"); break; /* flash 128k */
case 0x9: snprintf(name, sizeof(name), "K32L2B31"); break; /* flash 256k */
default: snprintf(name, sizeof(name), "K32L2Bxx");
}
break;
case KINETIS_SDID_FAMILYID_K2X:
cpu_mhz = 72;
k_chip->pflash_sector_size = 2 << 10;
num_blocks = 2;
k_chip->watchdog_type = KINETIS_WDOG32_KL28;
k_chip->sysmodectrlr_type = KINETIS_SMC32;
subfamid = 8;
switch (k_chip->sim_fcfg1 >> 24) {
case 0x9: snprintf(name, sizeof(name), "K32L2A31"); break; /* flash 256k */
case 0xB: snprintf(name, sizeof(name), "K32L2A41"); break; /* flash 512k */
default: snprintf(name, sizeof(name), "K32L2Axx");
}
break;
}
} else {
/* KL series */
switch (k_chip->sim_sdid & (KINETIS_SDID_FAMILYID_MASK | KINETIS_SDID_SUBFAMID_MASK)) {
case KINETIS_SDID_FAMILYID_K1X | KINETIS_SDID_SUBFAMID_KX3:
case KINETIS_SDID_FAMILYID_K2X | KINETIS_SDID_SUBFAMID_KX3:
subfamid = 7;
break;
case KINETIS_SDID_FAMILYID_K2X | KINETIS_SDID_SUBFAMID_KX8:
cpu_mhz = 72;
k_chip->pflash_sector_size = 2 << 10;
num_blocks = 2;
k_chip->watchdog_type = KINETIS_WDOG32_KL28;
k_chip->sysmodectrlr_type = KINETIS_SMC32;
break;
}
snprintf(name, sizeof(name), "MKL%u%uZ%%s%u", familyid, subfamid, cpu_mhz / 10);
}
break;
K32L2A are handed like KL28, and K32L2B like KL27. Unfortunately don't have K32L2B on hand to test it, but for K32L2A it is working fine...
D:\>OpenOCD\bin\openocd -c "adapter driver cmsis-dap" -f "target\klx.cfg" -c "program fb.hex verify reset exit"
Open On-Chip Debugger 0.11.0 (2021-10-16) [https://github.com/sysprogs/openocd]
Licensed under GNU GPL v2
libusb1 09e75e98b4d9ea7909e8837b7a3f00dda4589dc3
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "swd". To override use 'transport select <transport>'.
Info : add flash_bank kinetis klx.pflash
Info : CMSIS-DAP: SWD Supported
Info : CMSIS-DAP: JTAG Supported
Info : CMSIS-DAP: FW Version = 1.10
Info : CMSIS-DAP: Serial# = XXXXXXXXXXXX
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 1 TDO = 1 nTRST = 0 nRESET = 1
Info : CMSIS-DAP: Interface ready
Info : clock speed 1000 kHz
Info : SWD DPIDR 0x2ba01477
Info : klx.cpu: hardware has 2 breakpoints, 2 watchpoints
Info : starting gdb server for klx.cpu on 3333
Info : Listening on port 3333 for gdb connections
Error: DP initialisation failed
Info : SWD DPIDR 0x2ba01477
target halted due to debug-request, current mode: Thread
xPSR: 0x61000000 pc: 0x00004096 msp: 0x1fff8400
Info : SWD DPIDR 0x2ba01477
Error: Failed to read memory at 0x40048024
Info : Kinetis K32L2A31 detected: 2 flash blocks
Info : 2 PFlash banks: 256k total
Info : Disabling Kinetis watchdog (initial WDOG_CS 0x00002180)
** Programming Started **
Info : Padding image section 0 at 0x00000008 with 1016 bytes
Info : Flash write discontinued at 0x00000410, next section at 0x00001000
Warn : MAXADDR1 0x20 check failed, please report to OpenOCD mailing list
Info : This device supports Program Longword execution only.
Info : FOPT requested in the programmed file differs from current setting, set 'kinetis fopt 0x3d'.
Info : Trying to re-program FCF.
Info : This device supports Program Longword execution only.
Info : This device supports Program Longword execution only.
** Programming Finished **
** Verify Started **
** Verified OK **
** Resetting Target **
Error: DP initialisation failed
shutdown command invoked
Everything else except "kinetis.c" file (in OpenOCD 0.11) is untouched. You can replace original "kinetis.c" with attached modified version, build it and test it. Of course, I am not responsible for broken window or dead cat.