stm32f2x: Fix byte order bug. 66/2466/2
authorJens Bauer <jens@gpio.dk>
Fri, 16 Jan 2015 22:57:09 +0000 (23:57 +0100)
committerPaul Fertser <fercerpav@gmail.com>
Fri, 30 Jan 2015 08:55:23 +0000 (08:55 +0000)
Do not use buf_set_u32 on integers; they're not buffers.
If using buf_set_u32 on integers, bytes will be exchanged on Big Endian targets.
In this particular case, FLASH_OPTCR was incorrectly written, causing it to often
contain one of these values: 0x00aaaae1, 0x00aaffef, 0x00ffabe1 or 0x00abffe1.
This write-protected the device before flash-programming, causing this command...
flash write_image erase unlock myfile.elf
... to fail, complaining about write-protection.
Repeating the above command would change the OPTCR register each time.
After applying this patch, the OPTCR remains "unchanged".

Change-Id: I73d510fcc2e81a01973ad5c6e1aa22715ebd2743
Signed-off-by: Jens Bauer <jens@gpio.dk>
Reviewed-on: http://openocd.zylin.com/2466
Tested-by: jenkins
Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
src/flash/nor/stm32f2x.c

index 8f35845b4516caf2230d64fd9cec2866be08b6f6..422eac1b4f28f3cf4b4fb67044497c16e72c264c 100644 (file)
@@ -344,8 +344,8 @@ static int stm32x_write_options(struct flash_bank *bank)
 
        /* rebuild option data */
        optiondata = stm32x_info->option_bytes.user_options;
-       buf_set_u32(&optiondata, 8, 8, stm32x_info->option_bytes.RDP);
-       buf_set_u32(&optiondata, 16, 12, stm32x_info->option_bytes.protection);
+       optiondata |= stm32x_info->option_bytes.RDP << 8;
+       optiondata |= (stm32x_info->option_bytes.protection & 0x0fff) << 16;
 
        /* program options */
        retval = target_write_u32(target, STM32_FLASH_OPTCR, optiondata);
@@ -355,7 +355,7 @@ static int stm32x_write_options(struct flash_bank *bank)
        if (stm32x_info->has_large_mem) {
 
                uint32_t optiondata2 = 0;
-               buf_set_u32(&optiondata2, 16, 12, stm32x_info->option_bytes.protection >> 12);
+               optiondata2 |= (stm32x_info->option_bytes.protection & 0x00fff000) << 4;
                retval = target_write_u32(target, STM32_FLASH_OPTCR1, optiondata2);
                if (retval != ERROR_OK)
                        return retval;

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)