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

-- gerrit

commit 05fb62779c3aec3c709db0a5b6572fff70adeeef
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]>

diff --git a/src/flash/nor/stm32lx.c b/src/flash/nor/stm32lx.c
index fc0fb9e..c7e1150 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,10 +533,12 @@ 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.");
@@ -547,9 +551,10 @@ static int stm32lx_probe(struct flash_bank *bank)
        /* 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;
+               LOG_WARNING("STM32 flash size failed, probe inaccurate - 
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
@@ -557,15 +562,24 @@ static int stm32lx_probe(struct flash_bank *bank)
 
        /* 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 +950,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..95baa05 100644
--- a/tcl/target/stm32lx_stlink.cfg
+++ b/tcl/target/stm32lx_stlink.cfg
@@ -19,6 +19,15 @@ 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
        echo "STM32L: Enabling HSI"

-- 

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