This is an automated email from Gerrit. Stefan Arnold ([email protected]) just uploaded a new patch set to Gerrit, which you can find at http://openocd.zylin.com/4260
-- gerrit commit 765ccdebbb0e01729367a5e47962eae90462bc8a Author: Stefan Arnold <[email protected]> Date: Tue Oct 17 10:50:13 2017 +0200 Add option "aux0" to "at91samd" for changing and reading AUX0 register which represents various fuses. Change-Id: I6382cc4ac15e6b9681e2f30b0ae60397a6289c3b Signed-off-by: Stefan Arnold <[email protected]> diff --git a/src/flash/nor/at91samd.c b/src/flash/nor/at91samd.c index ad88c51..97c9070 100644 --- a/src/flash/nor/at91samd.c +++ b/src/flash/nor/at91samd.c @@ -944,6 +944,95 @@ COMMAND_HANDLER(samd_handle_eeprom_command) return res; } + +static uint8_t hexchar_to_value(char c) +{ + if (isalpha(c)) + return tolower(c) - 'a' + 10; + + return c - '0'; +} + + +static int get_u32_from_hex(const char *str, uint32_t *value) +{ + unsigned int i; + + if (strlen(str) == 0 || strlen(str) > 8) + return 0; + + *value = 0; + for (i = 0 ; i < strlen(str) ; i++) { + if (!isxdigit(str[i])) + return 0; + + *value = (*value << 4) | (uint32_t)hexchar_to_value(str[i]); + } + return 1; +} + + +static int get_u32_from_str(const char *str, uint32_t *value) +{ + unsigned int i; + + if (strlen(str) == 0 || strlen(str) > 10) + return 0; + + *value = 0; + for (i = 0 ; i < strlen(str) ; i++) { + if (!isdigit(str[i])) + return 0; + + *value = *value * 10 + (str[i] - '0'); + } + if (*value > 0xFFFFFFFF) + return 0; + + return 1; +} + + +COMMAND_HANDLER(samd_handle_aux0_command) +{ + int res = ERROR_OK; + struct target *target = get_current_target(CMD_CTX); + + if (target) { + if (target->state != TARGET_HALTED) { + LOG_ERROR("Target not halted"); + return ERROR_TARGET_NOT_HALTED; + } + + if (CMD_ARGC >= 1) { + uint32_t value; + if (strlen(CMD_ARGV[0]) >= 3 && + CMD_ARGV[0][0] == '0' && + CMD_ARGV[0][1] == 'x') { + const char *value_str = &(CMD_ARGV[0][2]); + if (!get_u32_from_hex(value_str, &value)) { + command_print(CMD_CTX, "Invalid Hex value for 32-bit register."); + return ERROR_COMMAND_SYNTAX_ERROR; + } + } else { + if (!get_u32_from_str(CMD_ARGV[0], &value)) { + command_print(CMD_CTX, "Invalid value for 32-bit register."); + return ERROR_COMMAND_SYNTAX_ERROR; + } + } + + res = samd_modify_user_row(target, value, 0, 31); + } else { + uint32_t val; + res = target_read_u32(target, SAMD_USER_ROW, &val); + if (res == ERROR_OK) + command_print(CMD_CTX, "AUX0: 0x%08"PRIX32, val); + } + } + + return res; +} + COMMAND_HANDLER(samd_handle_bootloader_command) { int res = ERROR_OK; @@ -1094,6 +1183,13 @@ static const struct command_registration at91samd_exec_command_handlers[] = { "Changes are stored immediately but take affect after the MCU is" "reset.", }, + { + .name = "aux0", + .usage = "[value]", + .handler = samd_handle_aux0_command, + .mode = COMMAND_EXEC, + .help = "Show or set the AUX0 register, stored in the User Row.", + }, COMMAND_REGISTRATION_DONE }; -- ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ OpenOCD-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openocd-devel
