This is an automated email from Gerrit. "Carlos Sanchez <carlossanc...@geotab.com>" just uploaded a new patch set to Gerrit, which you can find at https://review.openocd.org/c/openocd/+/8010
-- gerrit commit 53125f3e394becd261dd890a395eb8b218417915 Author: Sven van Ashbrook <svenvanasbro...@geotab.com> Date: Thu Apr 28 09:33:15 2022 -0400 flash/nor/kinetis: add support for NXP S32K series S32K General-Purpose Microcontrollers Scalable, low-power Arm® Cortex®-M series-based microcontrollers AEC-Q100 qualified with advanced safety and security and software support for industrial and automotive ASIL B/D applications in body, zone control, and electrification. Change-Id: Ic8176bb9c9e8049c262f39c8591f1a6332e93509 Signed-off-by: Sven van Ashbrook <svenvanasbro...@geotab.com> diff --git a/src/flash/nor/kinetis.c b/src/flash/nor/kinetis.c index eece80f97d..6ac0b31438 100644 --- a/src/flash/nor/kinetis.c +++ b/src/flash/nor/kinetis.c @@ -230,6 +230,22 @@ #define KINETIS_SDID_PROJECTID_KE1XF 0x00000080 #define KINETIS_SDID_PROJECTID_KE1XZ 0x00000100 +/* The S32K series uses a different, incompatible SDID layout : + * Bit 31-28 : GENERATION + * Bit 27-24 : SUBSERIES + * Bit 23-20 : DERIVATE + * Bit 19-16 : RAMSIZE + * Bit 15-12 : REVID + * Bit 11-8 : PACKAGE + * Bit 7-0 : FEATURES + */ + +#define S32K_SDID_SERIES_MASK 0xFF000000 /* GENERATION + SUBSERIES */ +#define S32K_SDID_SERIES_K14X 0x14000000 + +#define S32K_SDID_DERIVATE_MASK 0x00F00000 +#define S32K_SDID_DERIVATE_KXX8 0x00800000 + struct kinetis_flash_bank { struct kinetis_chip *k_chip; bool probed; @@ -2060,9 +2076,82 @@ static int kinetis_write(struct flash_bank *bank, const uint8_t *buffer, static int s32k_probe_chip(struct kinetis_chip *k_chip) { - LOG_ERROR("NXP S32K is unsupported"); + int result; + uint32_t sim_sdid, sim_fcfg1; + uint8_t fcfg1_depart; + struct target *target = k_chip->target; + + k_chip->probed = false; + k_chip->sim_base = SIM_BASE; + k_chip->pflash_base = 0; + k_chip->nvm_base = 0x10000000; + + result = target_read_u32(target, k_chip->sim_base + SIM_SDID_OFFSET, &sim_sdid); + if (result != ERROR_OK) + return result; + + result = target_read_u32(target, k_chip->sim_base + SIM_FCFG1_OFFSET, &sim_fcfg1); + if (result != ERROR_OK) + return result; + fcfg1_depart = (sim_fcfg1 >> 12) & 0x0F; + + switch (sim_sdid & S32K_SDID_SERIES_MASK) { + case S32K_SDID_SERIES_K14X: + k_chip->flash_support = FS_PROGRAM_PHRASE | FS_PROGRAM_SECTOR; + k_chip->watchdog_type = KINETIS_WDOG32_KE1X; + k_chip->cache_type = KINETIS_CACHE_MSCM; + k_chip->progr_accel_ram = FLEXRAM; + + switch (sim_sdid & S32K_SDID_DERIVATE_MASK) { + case S32K_SDID_DERIVATE_KXX8: + /* S32K148 chip: all "partitions" are interleaved + * - double sector size (2x2K = 4K) + * - double program size (2x512 = 1K) + */ + snprintf(k_chip->name, sizeof(k_chip->name), "S32K148"); + k_chip->max_flash_prog_size = 1 << 10; + /* 3x 512K Program Flash "partitions" */ + k_chip->pflash_size = 3 * (512 << 10); + k_chip->pflash_sector_size = 4 << 10; + k_chip->num_pflash_blocks = 3; + /* 1x 512K S32K-FlexNVM "partition" */ + k_chip->num_nvm_blocks = 1; + k_chip->nvm_size = 512 << 10; + k_chip->nvm_sector_size = 4 << 10; + /* optional eeprom emulation */ + switch (fcfg1_depart) { + case 0x4: + k_chip->dflash_size = k_chip->nvm_size - (64 << 10); + k_chip->ee_size = 4 << 10; + break; + default: + k_chip->dflash_size = k_chip->nvm_size; + k_chip->ee_size = 0; + break; + } + break; + + default: + LOG_ERROR("Unsupported S32K-family derivate"); + return ERROR_FLASH_OPER_UNSUPPORTED; + } + break; - return ERROR_FLASH_OPER_UNSUPPORTED; + default: + LOG_ERROR("Unsupported S32K-family series"); + return ERROR_FLASH_OPER_UNSUPPORTED; + } + + LOG_INFO("%s detected: %u flash blocks", k_chip->name, k_chip->num_pflash_blocks + k_chip->num_nvm_blocks); + LOG_INFO("%u PFlash blocks: %" PRIu32 "k total", k_chip->num_pflash_blocks, k_chip->pflash_size / 1024); + LOG_INFO("%u FlexNVM blocks: %" PRIu32 "k total, %" PRIu32 "k available as data flash, %" PRIu32 "k as eeram", + k_chip->num_nvm_blocks, k_chip->nvm_size >> 10, k_chip->dflash_size >> 10, k_chip->ee_size >> 10); + + kinetis_create_missing_banks(k_chip); + + k_chip->probed = true; + + return ERROR_OK; } --