This is an automated email from Gerrit.

Michele Sardo ([email protected]) just uploaded a new patch set to Gerrit, 
which you can find at http://openocd.zylin.com/4389

-- gerrit

commit 9a54f4f26eb5f0739ed5a6d9da803529aed15c77
Author: Michele Sardo <[email protected]>
Date:   Thu Feb 1 10:32:50 2018 +0000

    Added documentation for bluenrg-x flash driver in openocd.texi
    Implemented suggestion by Tomas Vanek and using target_write_buffer to
    overcome endianess problems
    
    Change-Id: I2553badfce1141decb1a5337d92ea86178a8684f
    Signed-off-by: Michele Sardo <[email protected]>

diff --git a/doc/openocd.texi b/doc/openocd.texi
index 483b27b..efb40a8 100644
--- a/doc/openocd.texi
+++ b/doc/openocd.texi
@@ -5341,6 +5341,30 @@ The AVR 8-bit microcontrollers from Atmel integrate 
flash memory.
 @comment - defines mass_erase ... pointless given flash_erase_address
 @end deffn
 
+@deffn {Flash Driver} bluenrg-x
+STMicroelectronics BlueNRG-1 and BlueNRG-2 Bluetooth low energy wireless 
system-on-chip. They include ARM Cortex-M0 core and internal flash memory.
+The driver automatically recognizes these chips using
+the chip identification registers, and autoconfigures itself.
+
+@example
+flash bank $_FLASHNAME bluenrg-x 0 0 0 0 $_TARGETNAME
+@end example
+
+Note that when users ask to erase all the sectors of the flash, a mass erase 
command is used which is faster than erasing
+each single sector one by one.
+
+@example
+flash erase_sector 0 0 79 # It will perform a mass erase on BlueNRG-1
+@end example
+
+@example
+flash erase_sector 0 0 127 # It will perform a mass erase on BlueNRG-2
+@end example
+
+Triggering a mass erase is also useful when users want to disable readout 
protection.
+
+@end deffn
+
 @deffn {Flash Driver} efm32
 All members of the EFM32 microcontroller family from Energy Micro include
 internal flash and use ARM Cortex-M3 cores. The driver automatically recognizes
diff --git a/src/flash/nor/bluenrg-x.c b/src/flash/nor/bluenrg-x.c
index 58d1db9..43e85fc 100644
--- a/src/flash/nor/bluenrg-x.c
+++ b/src/flash/nor/bluenrg-x.c
@@ -195,7 +195,9 @@ static int bluenrgx_write_word(struct target *target, 
uint32_t address_base, uin
        for (uint32_t i = 0; i < count; i++) {
                uint32_t address = address_base + i * FLASH_WORD_LEN;
                uint32_t read_back;
-               uint32_t val = (values[0] | (values[1] << 8) |  (values[2] << 
16) |  (values[3] << 24));
+               uint32_t val;
+
+               memcpy(&val, values + (i * FLASH_WORD_LEN), FLASH_WORD_LEN);
 
                retval = target_write_u32(target, FLASH_REG_ADDRESS, address >> 
2);
                if (retval != ERROR_OK) {
@@ -203,7 +205,7 @@ static int bluenrgx_write_word(struct target *target, 
uint32_t address_base, uin
                        return retval;
                }
 
-               retval = target_write_u32(target, FLASH_REG_DATA, val);
+               retval = target_write_buffer(target, FLASH_REG_DATA, 4, 
(uint8_t *) &val);
                if (retval != ERROR_OK) {
                        LOG_ERROR("Register write failed, error code: %d", 
retval);
                        return retval;
@@ -233,7 +235,7 @@ static int bluenrgx_write_word(struct target *target, 
uint32_t address_base, uin
                        }
                }
 
-               retval = target_read_u32(target, address, &read_back);
+               retval = target_read_buffer(target, address, 4, (uint8_t *) 
&read_back);
                if (retval != ERROR_OK) {
                        LOG_ERROR("Flash read failed, error code: %d", retval);
                        return retval;
@@ -253,6 +255,11 @@ static int bluenrgx_write_bytes(struct target *target, 
uint32_t address_base, ui
        uint8_t *new_buffer = NULL;
        uint32_t pre_bytes = 0, post_bytes = 0, pre_word, post_word, 
pre_address, post_address;
 
+       if (count == 0) {
+         /* Just return if there are no bytes to write */
+         return retval;
+       }
+
        if (address_base & 3) {
                pre_bytes = address_base & 3;
                pre_address = address_base - pre_bytes;
@@ -301,7 +308,7 @@ static int bluenrgx_write_bytes(struct target *target, 
uint32_t address_base, ui
                buffer = new_buffer;
        }
 
-       retval = bluenrgx_write_word(target, address_base - pre_bytes, 
new_buffer, count/4);
+       retval = bluenrgx_write_word(target, address_base - pre_bytes, buffer, 
count/4);
 
        if (new_buffer)
                free(new_buffer);

-- 

------------------------------------------------------------------------------
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

Reply via email to