X-Git-Url: https://review.openocd.org/gitweb?p=openocd.git;a=blobdiff_plain;f=src%2Fflash%2Fnor%2Fefm32.c;h=35c0732089a40cbcf57513801f66da81d57293d5;hp=295c70700f3c85453b5343684f1ebbcccf8e7959;hb=889aa89c8125d510100f78463f71b29b1c156d5a;hpb=feddedb6db72b81714780fae5d0b3a51dc1ddedc diff --git a/src/flash/nor/efm32.c b/src/flash/nor/efm32.c index 295c70700f..35c0732089 100644 --- a/src/flash/nor/efm32.c +++ b/src/flash/nor/efm32.c @@ -10,7 +10,10 @@ * * * Copyright (C) 2013 by Roman Dmitrienko * * me@iamroman.org * - * + * * + * Copyright (C) 2014 Nemui Trinomius * + * nemuisan_kawausogasuki@live.jp * + * * * 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 * @@ -24,7 +27,7 @@ * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * ***************************************************************************/ #ifdef HAVE_CONFIG_H @@ -42,6 +45,8 @@ #define EFM_FAMILY_ID_GIANT_GECKO 72 #define EFM_FAMILY_ID_TINY_GECKO 73 #define EFM_FAMILY_ID_LEOPARD_GECKO 74 +#define EFM_FAMILY_ID_WONDER_GECKO 75 +#define EFM_FAMILY_ID_ZERO_GECKO 76 #define EFM32_FLASH_ERASE_TMO 100 #define EFM32_FLASH_WDATAREADY_TMO 100 @@ -85,7 +90,7 @@ struct efm32x_flash_bank { int probed; - uint8_t lb_page[LOCKBITS_PAGE_SZ]; + uint32_t lb_page[LOCKBITS_PAGE_SZ/4]; }; struct efm32_info { @@ -97,7 +102,7 @@ struct efm32_info { uint16_t page_size; }; -static int efm32x_write(struct flash_bank *bank, uint8_t *buffer, +static int efm32x_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count); static int efm32x_get_flash_size(struct flash_bank *bank, uint16_t *flash_sz) @@ -139,8 +144,12 @@ static int efm32x_read_info(struct flash_bank *bank, if (((cpuid >> 4) & 0xfff) == 0xc23) { /* Cortex M3 device */ + } else if (((cpuid >> 4) & 0xfff) == 0xc24) { + /* Cortex M4 device(WONDER GECKO) */ + } else if (((cpuid >> 4) & 0xfff) == 0xc60) { + /* Cortex M0plus device(ZERO GECKO) */ } else { - LOG_ERROR("Target is not CortexM3"); + LOG_ERROR("Target is not Cortex-Mx Device"); return ERROR_FAIL; } @@ -167,6 +176,8 @@ static int efm32x_read_info(struct flash_bank *bank, if (EFM_FAMILY_ID_GECKO == efm32_info->part_family || EFM_FAMILY_ID_TINY_GECKO == efm32_info->part_family) efm32_info->page_size = 512; + else if (EFM_FAMILY_ID_ZERO_GECKO == efm32_info->part_family) + efm32_info->page_size = 1024; else if (EFM_FAMILY_ID_GIANT_GECKO == efm32_info->part_family || EFM_FAMILY_ID_LEOPARD_GECKO == efm32_info->part_family) { if (efm32_info->prod_rev >= 18) { @@ -191,6 +202,18 @@ static int efm32x_read_info(struct flash_bank *bank, LOG_ERROR("Invalid page size %u", efm32_info->page_size); return ERROR_FAIL; } + } else if (EFM_FAMILY_ID_WONDER_GECKO == efm32_info->part_family) { + uint8_t pg_size = 0; + ret = target_read_u8(bank->target, EFM32_MSC_DI_PAGE_SIZE, + &pg_size); + if (ERROR_OK != ret) + return ret; + + efm32_info->page_size = (1 << ((pg_size+10) & 0xff)); + if (2048 != efm32_info->page_size) { + LOG_ERROR("Invalid page size %u", efm32_info->page_size); + return ERROR_FAIL; + } } else { LOG_ERROR("Unknown MCU family %d", efm32_info->part_family); return ERROR_FAIL; @@ -292,7 +315,7 @@ static int efm32x_erase_page(struct flash_bank *bank, uint32_t addr) int ret = 0; uint32_t status = 0; - LOG_DEBUG("erasing flash page at 0x%08x", addr); + LOG_DEBUG("erasing flash page at 0x%08" PRIx32, addr); ret = target_write_u32(bank->target, EFM32_MSC_ADDRB, addr); if (ERROR_OK != ret) @@ -307,13 +330,13 @@ static int efm32x_erase_page(struct flash_bank *bank, uint32_t addr) if (ERROR_OK != ret) return ret; - LOG_DEBUG("status 0x%x", status); + LOG_DEBUG("status 0x%" PRIx32, status); if (status & EFM32_MSC_STATUS_LOCKED_MASK) { LOG_ERROR("Page is locked"); return ERROR_FAIL; } else if (status & EFM32_MSC_STATUS_INVADDR_MASK) { - LOG_ERROR("Invalid address 0x%x", addr); + LOG_ERROR("Invalid address 0x%" PRIx32, addr); return ERROR_FAIL; } @@ -370,7 +393,7 @@ static int efm32x_read_lock_data(struct flash_bank *bank) data_size = bank->num_sectors / 8; /* number of data bytes */ data_size /= 4; /* ...and data dwords */ - ptr = (uint32_t *)efm32x_info->lb_page; + ptr = efm32x_info->lb_page; for (i = 0; i < data_size; i++, ptr++) { ret = target_read_u32(target, EFM32_MSC_LOCK_BITS+i*4, ptr); @@ -383,7 +406,7 @@ static int efm32x_read_lock_data(struct flash_bank *bank) /* also, read ULW, DLW and MLW */ /* ULW, word 126 */ - ptr = ((uint32_t *)efm32x_info->lb_page) + 126; + ptr = efm32x_info->lb_page + 126; ret = target_read_u32(target, EFM32_MSC_LOCK_BITS+126*4, ptr); if (ERROR_OK != ret) { LOG_ERROR("Failed to read ULW"); @@ -391,7 +414,7 @@ static int efm32x_read_lock_data(struct flash_bank *bank) } /* DLW, word 127 */ - ptr = ((uint32_t *)efm32x_info->lb_page) + 127; + ptr = efm32x_info->lb_page + 127; ret = target_read_u32(target, EFM32_MSC_LOCK_BITS+127*4, ptr); if (ERROR_OK != ret) { LOG_ERROR("Failed to read DLW"); @@ -399,7 +422,7 @@ static int efm32x_read_lock_data(struct flash_bank *bank) } /* MLW, word 125, present in GG and LG */ - ptr = ((uint32_t *)efm32x_info->lb_page) + 125; + ptr = efm32x_info->lb_page + 125; ret = target_read_u32(target, EFM32_MSC_LOCK_BITS+125*4, ptr); if (ERROR_OK != ret) { LOG_ERROR("Failed to read MLW"); @@ -420,14 +443,14 @@ static int efm32x_write_lock_data(struct flash_bank *bank) return ret; } - return efm32x_write(bank, efm32x_info->lb_page, EFM32_MSC_LOCK_BITS, + return efm32x_write(bank, (uint8_t *)efm32x_info->lb_page, EFM32_MSC_LOCK_BITS, LOCKBITS_PAGE_SZ); } static int efm32x_get_page_lock(struct flash_bank *bank, size_t page) { struct efm32x_flash_bank *efm32x_info = bank->driver_priv; - uint32_t dw = ((uint32_t *)efm32x_info->lb_page)[page >> 5]; + uint32_t dw = efm32x_info->lb_page[page >> 5]; uint32_t mask = 0; mask = 1 << (page & 0x1f); @@ -438,7 +461,7 @@ static int efm32x_get_page_lock(struct flash_bank *bank, size_t page) static int efm32x_set_page_lock(struct flash_bank *bank, size_t page, int set) { struct efm32x_flash_bank *efm32x_info = bank->driver_priv; - uint32_t *dw = &((uint32_t *)efm32x_info->lb_page)[page >> 5]; + uint32_t *dw = &efm32x_info->lb_page[page >> 5]; uint32_t mask = 0; mask = 1 << (page & 0x1f); @@ -484,7 +507,7 @@ static int efm32x_protect(struct flash_bank *bank, int set, int first, int last) return ERROR_OK; } -static int efm32x_write_block(struct flash_bank *bank, uint8_t *buf, +static int efm32x_write_block(struct flash_bank *bank, const uint8_t *buf, uint32_t offset, uint32_t count) { struct target *target = bank->target; @@ -578,8 +601,7 @@ static int efm32x_write_block(struct flash_bank *bank, uint8_t *buf, }; ret = target_write_buffer(target, write_algorithm->address, - sizeof(efm32x_flash_write_code), - (uint8_t *)efm32x_flash_write_code); + sizeof(efm32x_flash_write_code), efm32x_flash_write_code); if (ret != ERROR_OK) return ret; @@ -681,13 +703,13 @@ static int efm32x_write_word(struct flash_bank *bank, uint32_t addr, if (ERROR_OK != ret) return ret; - LOG_DEBUG("status 0x%x", status); + LOG_DEBUG("status 0x%" PRIx32, status); if (status & EFM32_MSC_STATUS_LOCKED_MASK) { LOG_ERROR("Page is locked"); return ERROR_FAIL; } else if (status & EFM32_MSC_STATUS_INVADDR_MASK) { - LOG_ERROR("Invalid address 0x%x", addr); + LOG_ERROR("Invalid address 0x%" PRIx32, addr); return ERROR_FAIL; } @@ -721,7 +743,7 @@ static int efm32x_write_word(struct flash_bank *bank, uint32_t addr, return ERROR_OK; } -static int efm32x_write(struct flash_bank *bank, uint8_t *buffer, +static int efm32x_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count) { struct target *target = bank->target; @@ -747,9 +769,9 @@ static int efm32x_write(struct flash_bank *bank, uint8_t *buffer, "for padding buffer"); return ERROR_FAIL; } - LOG_INFO("odd number of bytes to write (%d), extending to %d " + LOG_INFO("odd number of bytes to write (%" PRIu32 "), extending to %" PRIu32 " " "and padding with 0xff", old_count, count); - memset(buffer, 0xff, count); + memset(new_buffer, 0xff, count); buffer = memcpy(new_buffer, buffer, old_count); } @@ -826,6 +848,12 @@ static int efm32x_probe(struct flash_bank *bank) case EFM_FAMILY_ID_LEOPARD_GECKO: LOG_INFO("Leopard Gecko MCU detected"); break; + case EFM_FAMILY_ID_WONDER_GECKO: + LOG_INFO("Wonder Gecko MCU detected"); + break; + case EFM_FAMILY_ID_ZERO_GECKO: + LOG_INFO("Zero Gecko MCU detected"); + break; default: LOG_ERROR("Unsupported MCU family %d", efm32_mcu_info.part_family); @@ -936,6 +964,12 @@ static int get_efm32x_info(struct flash_bank *bank, char *buf, int buf_size) case EFM_FAMILY_ID_LEOPARD_GECKO: printed = snprintf(buf, buf_size, "Leopard Gecko"); break; + case EFM_FAMILY_ID_WONDER_GECKO: + printed = snprintf(buf, buf_size, "Wonder Gecko"); + break; + case EFM_FAMILY_ID_ZERO_GECKO: + printed = snprintf(buf, buf_size, "Zero Gecko"); + break; } buf += printed;