Menu

#317 STM32L5 wrong page size

0.11.0
closed
nobody
fixed with 6546
2022-10-21
2021-08-25
No

Hi,
I have issue with OpenOCD and STM32L552 (256 kiB FLASH).
STM32L5x has 2 option bytes telling what dual-bank config is used: DBANK and DB256K.
Issues it, that page size depends only on DBANK, even for devices with 256kiB.
Tested with STM32CUbeProgrammer and STM32L552. Also tested with OpenOCD which erases only 2kiB, even though OpenOCD reports 4kiB pages.
In commit 092cfe16fb9cf6d6a308d62246fb648b0709ecd3 introducing support of L5 devices, there seems to be the culprit of issue.

if ((use_dbank_bit && (options & BIT(22))) ||
                      (!use_dbank_bit && (options & BIT(21)))) {

STM32 flash driver code for these MCUs decides by DBANK for 512 kiB and by DB256K for 256 kiB and this is not correct.

From my understanding and observations:
for 512 kiB devices, DBANK affects page size and single-bank/dual-bank selection
for 256 kiB devices, DBANK affects page size and DB256K affects single-bank/dual-bank selection (probably, not tested)

This issue causes flash programming fail when there is already something in flash and page needs to be erased at first. I assume, that problem is wrong page erasure.

On which devices was this code tested?

Related

Tickets: #317

Discussion

  • Tarek BOCHKATI

    Tarek BOCHKATI - 2021-08-25

    Hi Patrik,

    Thanks for reporting the issue.
    this change was tested on NUCLEO-L552ZE-Q containing STM32L552ZET6QU device
    BTW the device contains 512K of flash

    I will check and come back with further details.

     
  • Tarek BOCHKATI

    Tarek BOCHKATI - 2021-09-02

    Hi Patrik,

    could you check if the proposed patch works for you:
    https://review.openocd.org/c/openocd/+/6538

    PS: I was not able to test on a device with 256k Flash

     
  • Patrik Bachan

    Patrik Bachan - 2021-09-04

    Hi Tarek,
    I've built patched version of openocd, but I was unable to flash MCU in any configuration. Probably due to different issue. Page size detection seems to be correct. At least according to output of "flash info 0".
    (Initial report was done on older openocd release https://github.com/xpack-dev-tools/openocd-xpack/releases/tag/v0.11.0-1)

    Configuration:
    STlink V2-1 (NUCLEO-L552ZE-Q), (STlink V2 clone with same results)
    MCU STM32L552RCT6 on separate board, external (stable) power supply

    Please see following logs:

    OpenOCD output:

    ./openocd -f ~/openocd.cfg -s ../tcl  -c "init; reset halt; adapter speed 2000"
    Open On-Chip Debugger 0.11.0+dev-00376-g3a73b22cd (2021-09-04-10:33)
    Licensed under GNU GPL v2
    For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
    Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
    Info : DEPRECATED target event trace-config
    adapter speed: 1800 kHz
    
    Info : clock speed 1800 kHz
    Info : STLINK V2J34M25 (API v2) VID:PID 0483:374B
    Info : Target voltage: 3.264253
    Info : stm32l5x.cpu: hardware has 8 breakpoints, 4 watchpoints
    Info : starting gdb server for stm32l5x.cpu on 3333
    Info : Listening on port 3333 for gdb connections
    stm32l5x.dap
    Error executing event halted on target stm32l5x.cpu:
    ../tcl/target/stm32l5x.cfg:116: Error: 
    in procedure 'ocd_process_reset' 
    in procedure 'ocd_process_reset_inner' called at file "embedded:startup.tcl", line 788
    in procedure 'ahb_ap_non_secure_access' called at file "../tcl/target/stm32l5x.cfg", line 152
    at file "../tcl/target/stm32l5x.cfg", line 116
    target halted due to debug-request, current mode: Thread 
    xPSR: 0xf9000000 pc: 0xfffffffe msp: 0xfffffffc
    Info : Unable to match requested speed 2000 kHz, using 1800 kHz
    Info : Unable to match requested speed 2000 kHz, using 1800 kHz
    adapter speed: 1800 kHz
    
    Info : Listening on port 6666 for tcl connections
    Info : Listening on port 4444 for telnet connections
    Info : accepting 'telnet' connection on tcp/4444
    Info : device idcode = 0x20016472 (STM32L55/L56xx - Rev 'unknown' : 0x2001)
    Info : TZEN = 0 : TrustZone disabled by option bytes
    Info : RDP level 0 (0xAA)
    Info : flash size = 256kbytes
    Info : flash mode : single-bank
    Error: timeout waiting for algorithm, a target reset is recommended
    Error: error executing stm32l4 flash write algorithm
    Error: block write failed
    Error: error writing to flash at address 0x08000000 at offset 0x00000000
    

    Telnet commands:

    telnet localhost 4444
    Trying ::1...
    Connection failed: Connection refused
    Trying 127.0.0.1...
    Connected to localhost.
    Escape character is '^]'.
    Open On-Chip Debugger
    > flash write_image /home/diggit/dev/blob.hex
    device idcode = 0x20016472 (STM32L55/L56xx - Rev 'unknown' : 0x2001)
    TZEN = 0 : TrustZone disabled by option bytes
    RDP level 0 (0xAA)
    flash size = 256kbytes
    flash mode : single-bank
    timeout waiting for algorithm, a target reset is recommended
    error executing stm32l4 flash write algorithm
    block write failed
    error writing to flash at address 0x08000000 at offset 0x00000000
    >
    

    Could it be, due to HLA SWD only probe?

     
  • Tarek BOCHKATI

    Tarek BOCHKATI - 2021-09-05

    well, as you said the current cfg file do support the STM32L5 devices using non HLA adapters
    since secure debugging requires changing the AP CSW when changing from secure to non-secure and vice versa

    but nothing prevent us from modifying the cfg to work with STM32L5 with HLA adapters but only when the device is non-secure

    IDK if ST-Link clones do support non-hla mode aka dapdirect using the "interface/stlink-dap.cfg"

    I would be interested if you can give it a try
    meanwhile I will try to adapt the cfg to work with HLA adapters

     
  • Tarek BOCHKATI

    Tarek BOCHKATI - 2021-09-06

    again here is a WIP change that permits to use the target/stm3él5x.cfg with HLA adapters
    please let me know if this permits to debug the device in non-secure mode :
    https://review.openocd.org/c/openocd/+/6546

    please be aware that as it's stated in the commit msg using HLA adapters does not permit to debug the device in secure mode.

     
  • Tarek BOCHKATI

    Tarek BOCHKATI - 2021-09-13

    Hi Patrik,

    could you please check if the following changes fixes your issues:
    https://review.openocd.org/c/openocd/+/6538/3
    https://review.openocd.org/c/openocd/+/6546/3

     
    • Patrik Bachan

      Patrik Bachan - 2021-09-13

      Hi Tarek,
      I am currently away from my equipment and that won't change till the end of this week. After that, I'll be keen to check your changes and give a feedback.

      Patrik

      13 Sep 2021 16:14:01 Tarek BOCHKATI tarekboch@users.sourceforge.net:

      Hi Patrik,

      could you please check if the following changes fixes your issues:
      https://review.openocd.org/c/openocd/+/6538/3
      https://review.openocd.org/c/openocd/+/6546/3


      [tickets:#317][https://sourceforge.net/p/openocd/tickets/317/] STM32L5 wrong page size

      Status: new
      Milestone: 0.11.0
      Labels: stm32lx flash
      Created: Wed Aug 25, 2021 02:33 PM UTC by Patrik Bachan
      Last Updated: Mon Sep 06, 2021 12:44 PM UTC
      Owner: nobody

      Hi,
      I have issue with OpenOCD and STM32L552 (256 kiB FLASH).
      STM32L5x has 2 option bytes telling what dual-bank config is used: DBANK and DB256K.
      Issues it, that page size depends only on DBANK, even for devices with 256kiB.
      Tested with STM32CUbeProgrammer and STM32L552. Also tested with OpenOCD which erases only 2kiB, even though OpenOCD reports 4kiB pages.
      In commit 092cfe16fb9cf6d6a308d62246fb648b0709ecd3[https://review.openocd.org/gitweb?p=openocd.git;a=commitdiff;h=092cfe16fb9cf6d6a308d62246fb648b0709ecd3] introducing support of L5 devices, there seems to be the culprit of issue.

      if ((use_dbank_bit && (options & BIT(22))) ||
                            (!use_dbank_bit && (options & BIT(21)))) {

      STM32 flash driver code for these MCUs decides by DBANK for 512 kiB and by DB256K for 256 kiB and this is not correct.

      From my understanding and observations:
      for 512 kiB devices, DBANK affects page size and single-bank/dual-bank selection
      for 256 kiB devices, DBANK affects page size and DB256K affects single-bank/dual-bank selection (probably, not tested)

      This issue causes flash programming fail when there is already something in flash and page needs to be erased at first. I assume, that problem is wrong page erasure.

      On which devices was this code tested?


      Sent from sourceforge.net because you indicated interest in https://sourceforge.net/p/openocd/tickets/317/

      To unsubscribe from further messages, please visit https://sourceforge.net/auth/subscriptions/

       

      Related

      Tickets: #317

  • Patrik Bachan

    Patrik Bachan - 2021-10-04

    Hi,
    sorry for late reply.
    Both change sets seems to work in my scenario. I was able to erase/flash pages on L552 256kiB flash version, when DBANK was set (2kiB pages) with ST-Link v2. No issues.

     
  • Tarek BOCHKATI

    Tarek BOCHKATI - 2021-10-04
    • labels: stm32lx flash --> stm32l5x flash
    • status: new --> accepted
    • Resolution: --> ongoing
     
  • Tarek BOCHKATI

    Tarek BOCHKATI - 2021-10-04

    Thanks Patrik !
    hopefully #6538 : flash/stm32l4x: fix dual bank support for STM32L552xC devices is already merged
    awaiting the merge of #6546 : tcl/stm32l5x|u5x: support HLA adapters in non-secure mode only
    then I will close the ticket.

     
    • Patrik Bachan

      Patrik Bachan - 2022-08-24

      Hi, any progress on #6546? I t looks like there are several small fixes required and then it would be ready for merge.

       
  • Antonio Borneo

    Antonio Borneo - 2022-10-21
    • status: accepted --> closed
    • Resolution: ongoing --> fixed with 6546
     
  • Antonio Borneo

    Antonio Borneo - 2022-10-21

    6546 merged, closing the ticket

     

Log in to post a comment.

MongoDB Logo MongoDB