Cart New Account Login

HomeAbout usProductsSupportForumsBlogCustomer Service

Please accept the use of cookies on our site

At PEmicro we use web browser cookies in order to provide you with an enhanced experience and in order to be able to do things like shopping cart processing and identify you when you login to our website.

Click here to accept

search inside this forum
search inside all forums
STM32Lxxxx, algorithms and RESETs
Jon G. Oct 19, 2015 at 10:45 AM (10:45 hours)
Staff: Kevin M.

  • I'm having to design an algorithm for fixing up STM32Lxxx devices that have had incorrect option bytes programmed (see STMicro document RM0038 rev.13, sect.3.5).

    Ideally, I'd like to be able to program the ROM within the same algorithm file, but it requires a device RESET after the option bytes are fixed, before ROM programming can start.

    So: can I reset the device (by asserting the OBL_LAUNCH bit), and continue within the same algorithm file after a suitable DELAY=.../ to allow the device to restart, or will the reset upset the Cyclone to the point where further operations within the same algorithm file are not possible?

    Here's what I have so far:

    ;;;;;;;;;; Excerpt from file ;;;;;;;;;;


    ;; This algorithm does not attempt to program the ROM at all. It's purely to
    ;; reset the option bytes to something sane. At the end, it

    ; Sort out the option bytes. We have to do this FAST, before the MCU watchdogs

    ; Set watchdog prescaler to max to buy us time. These operations should
    ; allow us over 28s to do our job.
    WRITE_LONG=0000AAAA/40003000/   ; Reset watchdog
    WRITE_LONG=00000007/40003004/   ; Prescaler /256

    ; Unlock the option block
    WRITE_LONG=FBEAD9C8/40023C14/   ; FLASH_OPTKEYR unlock option bytes
    ; Write correct option values
    WRITE_LONG=FF5500AA/1FF80000/   ; Disable memory protection
    WRITE_LONG=FF870078/1FF80004/   ; Revert to virgin defaults
    WRITE_LONG=FFFF0000/1FF80008/   ; No protection
    WRITE_LONG=00003F00/40023C18/   ; FLASH_SR clear error bits
    ; A brief wait
    DELAY=0001/         ; 1ms pause
    ; Now force an option-load reset
    WRITE_LONG=00040007/40023C04/   ; FLASH_PECR OBL_LAUNCH to force RESET
    DELAY=0032/         ; 50ms for restart

    ;Pages 512-256 ($000..$1FF)
    USER=PE Page Erase 3Page > /00000000/000001FF/
    USER=ER Erase page Range 3Beg Page >/00000000/000001FF/3End Page >/00000000/000001FF/

    ;;;;;;;;;; End of excerpt ;;;;;;;;;;

    Thanks for all assistance!


  • WHy do you want to use one file? You can put multiple alg files in one image.

    The option bytes alg resets the part when you call the launch option bytes command.

  • Thanks Kevin,

    It would be convenient to do it all in one file, but more than one within a SAP file is not a problem. We must program the option bytes first, amd reset, before programming the device ROM.

    I'm aware that we induce a reset from the above file. That's necessary, in order to latch the amended option bytes. I'm equally happy if we omit that, and have separate algorithm files for option byte and main ROM programming, with a RE command between if needed.

    However - I am not finding that the option bytes are being programmed at all at the moment, using variations on the above file. (Note that I accidentally omitted WRITE_LONG=FFFF0000/1FF8000C/ from the above. Adding it doesn't change behaviour. BLOCKING_MASK should also be set to 0x00000003 too, I guess.)

    For clarification, we're programming a STM32L100RB device, using a Cyclone for ARM Devices, with firmware v.1.61-0.7.

    So, a couple of questions, if you'd be so kind:

    1. At which point do the WRITE_LONG=... commands get executed? When the algorithm's loaded, when it executes a program (PM/PR/...) command, or at some other juncture?

    2. Do you already have a known good algorithm for programming option bytes on our device? If so, please provide!



  • this issue was resolved by providing a option bytes algorithm to the user.

Add comment

   Want to comment? Please login or create a new PEMicro account.

© 2018 P&E Microcomputer Systems Inc.
Website Terms of Use and Sales Agreement