Skip to content

Latest commit

 

History

History
319 lines (289 loc) · 11.4 KB

File metadata and controls

319 lines (289 loc) · 11.4 KB

Piu' sotto, al termine della lingua inglese trovi il testo in italiano.
Below the English text you'll find the Italian version



2) Creating a low-RAM-demanding EXTERNAL LOADER for STM32CubeProgrammer and STM32CubeIDE

External Loader is a plug-in for STM32CubeProgrammer/CubeIDE allowing to read/write an external memory through an STM32 uC.
Following the below instruction you can create an External Loader for an STM32 project having a Winbond external SPI Flash chip, adding it then to CubeProgrammer and CubeIDE.

"How to" create an External Loader for a specific project:

    After defining the CubeMX configuration details of your projectwith an external flash memory (e.g. having defined the SPI port and CS pin and the other details needed to communicate with Flash memory)

  • Create a new project in CubeIDE.
    Give the project a name with this format:
    "external flash used"_"uC or board name"_"other info, if any, - e.g. SPI port, CS pin, etc."
    (character "_", dividing the three fields, must non be used elsewhere)
    Here some examples for a valid project name:
      W25Q80_STM32F411_SPI1
      W25Q80_BLACKPILL-F411 (third field is optional and here it is not used)
      W25Q64_NUCLEO32-L432_SPI1-PA4CS
      etc.
  • in CubeMX:
    • setup the SPI port and the CS pin for your flash memory, as per your project.
      Warning:
      I always recommend to setup the External Loader with a low SPI port speed (e.g. lower than 2Mbit/s)

    • enable CRC (you just need to set "Activated" checkbox)
    • If on your board, you have available a led connected to a uC pin (GPIO_Output): you can use it in the External Loader. Useful for troubleshooting.
      give the uC led pin the name: LED.
    • in "Project Manager"->"Code Generator", mark "Generate peripheral initialization as a pair of '.c/.h' files per peripheral" to have peripheral initializing files separated by main.c
    • generate "c" code.
  • in CubeIDE:
    • in include folder, copy files:
        z_flash_W25QXXX.h
        Dev_Inf.h
    • in src folder, copy files:
        z_flash_W25QXXX.c
        Dev_Inf.c
        Loader_Src.c
    • in root folder, copy files:
        EL_linker.ld
        Post-Build command.txt
    • Setup "z_flash_W25QXXX.h"
        registering flash chip characteristics (see above the setup of "z_flash_W25QXXX.h" Step 1 to 4)
    • Setup Loader_Src.c:
        follow inside file: Step1, Step2, Step3
    • Setup Dev_Inf.c:
        update first struct field assigning a name to the External Loader: copy here the project name
        update third struct field indicating address where external flash is mapped
        leave unchanged other fields.
    • open file "Post-Build command.txt"
        copy the text row and paste it into the field in
        project->properties->C/C++ Build->settings->Build Steps->Post-Build Steps->Command
        click "Apply and Close"
    • edit EL_linker.ld
      • set the memory size as per uC available RAM:
        around line 30 you find text:
        (EL_linker.ld)
        ...
        RAM_LOADER (xrw)      : ORIGIN = 0x20000004, LENGTH = 8M-4
        ...

        change value "8M" after "LENGTH =" indicating the uC RAM size
      • save changes
      • in project->properties->C/C++ Build->settings->Tool Setting->MCU GCC Linker->General->linker script:
          1 change the name of the .ld file into "EL_linker.ld". Parameter should become: ${workspace_loc:/${ProjName}/EL_linker.ld}
          2 click "Apply and Close"


FOR YOUR INFORMATION: You don't need to unmark flag Discard Unused Sections in Project->Properties as indicated in my youtube video "Part One".
Characteristics and needs of this library are described in "Part Two".


Now "Compile" the project: If everithing goes fine you'll find the file project_name.stldr into the project root folder

THIS IS THE EXTERNAL LOADER

"How to" add External Loader to STM32CubeProgrammer

  • Go to the STM32CubeProgrammer program folder
    (right-click the program icon and choose "open file location")
  • once in the STM32CubeProgrammer program folder go into "ExternalLoader" subfolder
  • copy here the External Loader created (.stldr file)

    Opening STM32CubeProgrammer program you can select the new External Loader to access the external flash memory.

"How to" add External Loader to STM32CubeIDE

  • Go to the STM32Cubeide program folder
    (right-click the program icon and choose "open file location")
  • once in the STM32CubeProgrammer program folder go subfolder: ./plugins/xxxxxx.externaltools.cubeprogrammer.xxxxx/tools/bin/ExternalLoader
  • copy here the External Loader created (.stldr file)

    Now the External Loader is available to CubeIDE and can be selected in "Run/Debug Settings":
    in CubeIDE, go to Project->Properties->Run/Debug Settings
    select the launch configuration file and click "Edit"
    go to "Debugger"
    scroll to "External Loaders" and click "Add"
    select, in the external loader list, the external loader to use. Click "OK" and "Apply" until you close all the "properties" windows open.





Back to the home page







creare un EXTERNAL LOADER a basso utilizzo di RAM per STM32CubeProgrammer e STM32CubeIDE

External Loader e' un plug-in per STM32CubeProgrammer per leggere e/o programmare un chip di memoria gestito attraverso da un uC STM32.
Attraverso la libreria di funzioni indicata sopra e' possibile creare un external loader per un progetto STM32 con una memoria SPI Flash Winbond esterna .
Lo stesso plugin puo' essere utilizzato in STM32CubeIDE per programmare la memoria Flash direttamente durante la creazione di un progetto: CubeIDE usa i moduli CubeProgrammer per programmare la memoria flash interna od esterna del uC.

"How to" come creare an External Loader relativo ad un progetto:

    Dopo aver definito i dettagli di configurazione CubeMX del tuo progetto con una memoria flash via SPI (es. hai già definito la porta SPI ed il pin CS da usare per la comunicazione con la memoria Flash).

  • Crea un nuovo progetto in CubeIDE.
    Assegna al progetto un nome con questa forma:
    "external flash in uso"_"nome uC o board in uso"_"eventuali altre informazioni - es. Porta SPI, CS pin, ecc."
    (il carattere "_" separa i tre campi e non deve essere utilizzato nel nome se non per questa separazione)
    Esempi di nomi di progetto protrebbero essere:
      W25Q80_STM32F411_SPI1
      W25Q80_BLACKPILL-F411 (il terzo campo è opzionale e qui non c'e')
      W25Q64_NUCLEO32-L432_SPI1-PA4CS
      ecc.
  • in CubeMX:
    • configura una porta SPI ed il pin CS per la memoria flash (vedi sopra il dettaglio per la configurazione CubeMX)
      Attenzione:
      E' sempre consigliabile configurare una velocià ridotta in un External Loader (es. inferiore a 2Mbit/s)

    • abilita CRC (devi solo spuntare "Activated")
    • Se hai un led a disposizione sulla scheda, puoi usarlo nell'External Loader (utile nel troubleshooting)
      dai al pin del led il nome: LED
    • in "Project Manager"->"Code Generator", spunta "Generate peripheral initialization as a pair of '.c/.h' files per peripheral" per avere i file di inizializzazione separati da main.c
    • genera il codice.
  • in CubeIDE:
    • copiare in include folder
        z_flash_W25QXXX.h
        Dev_Inf.h
    • copiare in src folder
        z_flash_W25QXXX.c
        Dev_Inf.c
        Loader_Src.c
    • copiare in root folder
        EL_linker.ld
        Post-Build command.txt
    • definire i parametri in "z_flash_W25QXXX.h"
        definire le caratteristiche della memoria (vedi piu' sopra la configurazione di "z_flash_W25QXXX.h" da Step 1 a 4)
    • configurare Loader_Src.c:
        seguire gli step di configurazione: Step1, Step2, Step3
    • configurare Dev_Inf.c:
        aggiorna il primo campo della struct assegnando il nome all'External Loader: deve essere "rif alla flash" _ "rif alla board" _ "altre info (es versione)" (copiare il nome del progetto)
        aggiorna il terzo campo della struct indicando l'indirizzo su cui e' mappata la flash
        non modificare gli altri campi
    • aprire il file "Post-Build command.txt"
        copiare il contenuto e incollarlo nel campo in
        project->properties->C/C++ Build->settings->Build Steps->Post-Build Steps->Command
        scegliere "Apply and Close"
    • modificare EL_linker.ld
      • modificare la dimensione della memoria indicando la RAM disponibile sul uC:
        attorno alla riga 30 trovi il testo:
        (EL_linker.ld)
        ...
        RAM_LOADER (xrw)      : ORIGIN = 0x20000004, LENGTH = 8M-4
        ...

        modifica il valore "8M" dopo "LENGTH =" specificando la dimensione della RAM del uC
      • salvare
      • in project->properties->C/C++ Build->settings->Tool Setting->MCU GCC Linker->General->linker script:
          1 cambiare il nome del file .ld in "EL_linker.ld": dovrebbe essere: ${workspace_loc:/${ProjName}/EL_linker.ld}
          2 cliccare "Apply and Close"


PER INFORMAZIONE:
Non hai bisogno di deselezionare il flag Discard Unused Sections in Project->Properties, come indicato nel mio video "Prima Parte".
Le caratteristiche e le necessità di questa libreria sono descritte in "Terza Seconda".


"Compila" il progetto: se tutto e' andato bene trovi il file "nomeprogetto".stldr nella cartella di root

Questo e' l'external loader

"How to": come aggiungere un External Loader a STM32CubeProgrammer

  • Andare nel folder del programma STM32CubeProgrammer
    (ad esempio click-destro del mouse sull'icona del programma e scegliere "Apri percorso file")
  • raggiunta la cartella di STM32CubeProgrammer, scegliere la cartella "ExternalLoader"
  • copiare qui il file .stldr creato

    Aprendo STM32CubeProgrammer si puo' selezionare il nuovo External Loader per accedere alla memoria Flash esterna

"How to" add External Loader to STM32CubeIDE

  • Andare nel folder del programma STM32CubeIDE
    (ad esempio click-destro del mouse sull'icona del programma e scegliere "Apri percorso file")
  • Raggiunta la cartella di STM32CubeIDE, andare nella sottocartella: ./plugins/xxxxxx.externaltools.cubeprogrammer.xxxxx/tools/bin/ExternalLoader
  • Copiare qui il file .stldr creato

    Ora l'External Loader è disponibile in CubeIDE e puo' essere selezionato in "Run/Debug Settings":
    in CubeIDE andare in: Project->Properties->Run/Debug Settings
    selezionare il file di configurazione run e cliccare "Edit"
    selezionare "Debugger"
    sorrere la pagina fino a "External Loaders" e cliccare "Add"
    Selezionare, Nella lista degli external loader, il modulo da usare. Cliccare "OK" and "Apply" chidendo la finestra "Properties" aperta.

Torna alla home page