I've been trying to use the new cmsis-dap implementation (from http://openocd.zylin.com/1542) to work with a Freescale FRDM-KL46Z board (comes with a MKL46Z256VLL4 uc) and have found a couple of issues with the kinetis.c flash code.

The first problem was that when 'flash info 0' was run, the code would quit with an assert(bank->num_sectors > 0); This turned out to be a simple fix: size and count reversed when calling target_read_memory to get config registers from the IC. Patch attached.

The kinetis_read_part_info function still isn't getting the flash sector sizes right though which stops erase working properly. The part in question has 1kb sectors but the code determines them as 4kb.

Looking through the comments, this is the logic that is used to determine sector sizes:

 * Although not documented as such by Freescale, it appears that bits
 * 8:7 of the read-only SIM_SDID register reflect the granularity
 * settings 0..3, so sector sizes and block counts are applicable
 * according to the following table.
 */
const struct {
    unsigned pflash_sector_size_bytes;
    unsigned nvm_sector_size_bytes;
    unsigned num_blocks;
} kinetis_flash_params[4] = {
    { 1<<10, 1<<10, 2 },
    { 2<<10, 1<<10, 2 },
    { 2<<10, 2<<10, 2 },
    { 4<<10, 4<<10, 4 }
};

On the part that I'm using, bits 8:7 of SDID are '11' pointing to 4kb sector sizes.

What's the best way of going about fixing this?
A maintained lookup table for Kinetis sub-families?
I can't see how to set a flash sector size through a .cfg file.

Regards
Chris
diff --git a/src/flash/nor/kinetis.c b/src/flash/nor/kinetis.c
index 31483cc..dcf5d53 100644
--- a/src/flash/nor/kinetis.c
+++ b/src/flash/nor/kinetis.c
@@ -481,18 +481,18 @@ static int kinetis_read_part_info(struct flash_bank *bank)
 		first_nvm_bank = 0, reassign = 0;
 	struct kinetis_flash_bank *kinfo = bank->driver_priv;
 
-	result = target_read_memory(bank->target, SIM_SDID, 1, 4, buf);
+	result = target_read_memory(bank->target, SIM_SDID, 4, 1, buf);
 	if (result != ERROR_OK)
 		return result;
 	kinfo->sim_sdid = target_buffer_get_u32(bank->target, buf);
 	granularity = (kinfo->sim_sdid >> 7) & 0x03;
 
-	result = target_read_memory(bank->target, SIM_FCFG1, 1, 4, buf);
+	result = target_read_memory(bank->target, SIM_FCFG1, 4, 1, buf);
 	if (result != ERROR_OK)
 		return result;
 	kinfo->sim_fcfg1 = target_buffer_get_u32(bank->target, buf);
 
-	result = target_read_memory(bank->target, SIM_FCFG2, 1, 4, buf);
+	result = target_read_memory(bank->target, SIM_FCFG2, 4, 1, buf);
 	if (result != ERROR_OK)
 		return result;
 	kinfo->sim_fcfg2 = target_buffer_get_u32(bank->target, buf);
------------------------------------------------------------------------------
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk
_______________________________________________
OpenOCD-devel mailing list
OpenOCD-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openocd-devel

Reply via email to