This is an automated email from Gerrit.

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

-- gerrit

commit 99f9befecb3d0fe7145469a5ca2b4639add7b33e
Author: Johan Almquist <[email protected]>
Date:   Thu Jan 24 13:49:08 2013 +0100

    Added missing support for the STM32Lx 384kb dual bank flash.
    
    This update adds support for the STM32Lx 384kb dual bank flash. Previously 
there was a problem when writing an image that was larger than 192Kb.
    That lead to openocd printing out two error messages like "Error: access 
denied / write protected" and "Error: invalid program address".
    The reason was that the stm32lx driver tried to write half pages which 
overlapped into the next flash bank.
    The configuration file for stm32lx is also updated to use the dual bank 
flash.
    
    Change-Id: I7b4a0b9f07dfba5bc770ab4c5da971d637df1ff6
    Signed-off-by: Johan Almquist <[email protected]>
    
    Removed attempt to read out flash bank size from chip, since it does not 
work for all chips.
    
    The stm32lx driver attempted to read out the flash size from an MCU 
register.  According to spec that should
    be fine, but that will not work for two reasons. First, some samples 
(STM32L162) answers 0 or 0xffff which is
    perhaps ok, but worse is that we had some other samples that answered 
incorrectly (7132Kb). Also, the driver
    needs to know the size of the current flash bank - not the total flash size.
    
    Change-Id: I334e0e5eb3c2ed27c77f44885d3de77e1dc4e5db
    Signed-off-by: Johan Almquist <[email protected]>

diff --git a/src/flash/nor/stm32lx.c b/src/flash/nor/stm32lx.c
index fc0fb9e..3fffa03 100644
--- a/src/flash/nor/stm32lx.c
+++ b/src/flash/nor/stm32lx.c
@@ -93,7 +93,7 @@
 #define FLASH_PAGE_SIZE 256
 #define FLASH_SECTOR_SIZE 4096
 #define FLASH_PAGES_PER_SECTOR 16
-#define FLASH_BANK0_ADDRESS 0x08000000
+#define FLASH_BASE_ADDRESS 0x08000000
 
 /* stm32lx option byte register location */
 #define OB_RDP                 0x1FF80000
@@ -349,6 +349,7 @@ static int stm32lx_write_half_pages(struct flash_bank 
*bank, uint8_t *buffer,
                buffer += this_count;
                address += this_count;
                count -= this_count;
+
        }
 
        /* restore previous flags */
@@ -515,8 +516,9 @@ static int stm32lx_probe(struct flash_bank *bank)
        struct target *target = bank->target;
        struct stm32lx_flash_bank *stm32lx_info = bank->driver_priv;
        int i;
+       int is_dual_bank = 0;
        uint16_t flash_size_in_kb;
-       uint16_t max_flash_size_in_kb;
+       uint16_t max_flash_bank_size_in_kb;
        uint32_t device_id;
 
        stm32lx_info->probed = 0;
@@ -531,41 +533,55 @@ static int stm32lx_probe(struct flash_bank *bank)
        /* set max flash size depending on family */
        switch (device_id & 0xfff) {
        case 0x416:
-               max_flash_size_in_kb = 128;
+               max_flash_bank_size_in_kb = 128;
                break;
        case 0x436:
-               max_flash_size_in_kb = 384;
+               /* this is a dual bank flash total 384Kb, each bank is 192Kb */
+               is_dual_bank = 1;
+               max_flash_bank_size_in_kb = 192;
                break;
        default:
                LOG_WARNING("Cannot identify target as a STM32L family.");
                return ERROR_FAIL;
        }
 
-       /* get flash size from target. */
-       retval = target_read_u16(target, F_SIZE, &flash_size_in_kb);
+       /* The flash size register on chip that according to spec should reflec
+               the size of the flash in kb is not always working.
+               Some samples we've seen does not have this number set, but 
worse is that we've seen
+               samples that has erronous numbers set.
 
-       /* failed reading flash size or flash size invalid (early silicon),
-        * default to max target family */
-       if (retval != ERROR_OK || flash_size_in_kb == 0xffff || 
flash_size_in_kb == 0) {
-               LOG_WARNING("STM32 flash size failed, probe inaccurate - 
assuming %dk flash",
-                       max_flash_size_in_kb);
-               flash_size_in_kb = max_flash_size_in_kb;
-       }
+               Also, this driver does not need to know the total flash size, 
it needs
+               to know the size of the flash bank.  Hence, we stick with the 
hard-coded
+               values set depending on device id above.
+       */
+       LOG_WARNING("STM32 flash size not probed - assuming %dkb in bank %d",
+                               max_flash_bank_size_in_kb,
+                               bank->bank_number);
+       flash_size_in_kb = max_flash_bank_size_in_kb;
 
        /* STM32L - we have 32 sectors, 16 pages per sector -> 512 pages
         * 16 pages for a protection area */
 
        /* calculate numbers of sectors (4kB per sector) */
        int num_sectors = (flash_size_in_kb * 1024) / FLASH_SECTOR_SIZE;
-       LOG_INFO("flash size = %dkbytes", flash_size_in_kb);
+       LOG_INFO("flash bank %d size = %dkb", bank->bank_number, 
flash_size_in_kb);
 
        if (bank->sectors) {
                free(bank->sectors);
                bank->sectors = NULL;
        }
 
-       bank->base = FLASH_BANK0_ADDRESS;
        bank->size = flash_size_in_kb * 1024;
+       if (0 == bank->bank_number) {
+               bank->base = FLASH_BASE_ADDRESS;
+       } else {
+               if (is_dual_bank) {
+                       bank->base = FLASH_BASE_ADDRESS + bank->size;
+               } else {
+                       LOG_ERROR("this is not dual bank");
+                       return ERROR_FAIL;
+               }
+       }
        bank->num_sectors = num_sectors;
        bank->sectors = malloc(sizeof(struct flash_sector) * num_sectors);
        if (bank->sectors == NULL) {
@@ -936,6 +952,7 @@ static int stm32lx_wait_until_bsy_clear(struct flash_bank 
*bank)
 
        if (status & FLASH_SR__WRPERR) {
                LOG_ERROR("access denied / write protected");
+               LOG_ERROR("status=0x%x", status);
                retval = ERROR_FAIL;
        }
 
diff --git a/tcl/target/stm32lx_stlink.cfg b/tcl/target/stm32lx_stlink.cfg
index 6bec2b5..af0fac3 100644
--- a/tcl/target/stm32lx_stlink.cfg
+++ b/tcl/target/stm32lx_stlink.cfg
@@ -16,8 +16,14 @@ if { [info exists WORKAREASIZE] == 0 } {
 
 source [find target/stm32_stlink.cfg]
 
-set _FLASHNAME $_CHIPNAME.flash
-flash bank $_FLASHNAME stm32lx 0 0 0 0 $_TARGETNAME
+# The stm32lx 384kb and 256kb have a dual bank flash, hence we define
+# two banks here, assuming this is this ok for all stm32l1x.
+# flash bank stm32lx <base> <size> 0 0 <target#> <variant>
+#  (base address and size will be probed)
+set _FLASHNAME $_CHIPNAME.flash0
+flash bank $_FLASHNAME stm32lx 0 0 0 0 0
+set _FLASHNAME $_CHIPNAME.flash1
+flash bank $_FLASHNAME stm32lx 0 0 0 0 0
 
 proc stm32l_enable_HSI {} {
        # Enable HSI as clock source

-- 

------------------------------------------------------------------------------
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. ON SALE this month only -- learn more at:
http://p.sf.net/sfu/learnnow-d2d
_______________________________________________
OpenOCD-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openocd-devel

Reply via email to