Piu' sotto, al termine della lingua inglese trovi il testo in italiano. _
Below the English text you'll find the Italian version
External Loader is a plug-in for STM32CubeProgrammer allowing to read/write an external memory through an STM32 uC.
Through the library shown above it is possible to create an External Loader for an STM32 project having a Winbond external SPI Flash chip .
Next, you will see how you can use the same external loader program in STM32CubeIDE to program external Flash memory directly while creating a project: CubeIDE uses the CubeProgrammer modules to program uC internal and external flash memory.
-
Supposing you already defined the project configuration having an external flash memory (e.g. having defined the SPI port and CS pin and 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. (see above details about SPI port configuration on CubeMX)
Warning:
if prototyping with a flash on a breadboard, in the External Loader project I recommend to setup an SPI port speed lower than 2Mbit/s
- 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.
- setup the SPI port and the CS pin for your flash memory. (see above details about SPI port configuration on CubeMX)
-
in CubeIDE:
-
in Core/inc folder, copy files:
-
z_flash_W25QXXX.h
Dev_Inf.h
-
in Core/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 (xrw) : ORIGIN = 0x20000004, LENGTH = xxxK ...
change value 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 remove flag in Discard Unused Sections
3 click "Apply and Close"
-
set the memory size as per uC available RAM:
-
in Core/inc folder, copy files:
THIS IS THE EXTERNAL LOADER
-
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.
-
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.
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 che ha 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.
-
Ipotizzando che hai gia' creato la configurazione del progetto di memoria esterna (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:
se usato in prototipazione, per External Loader e' consigliabile configurare una velocià inferiore a 2Mbit/s
- 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.
- configura una porta SPI ed il pin CS per la memoria flash (vedi sopra il dettaglio per la configurazione CubeMX)
-
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:
alla riga 30 trovi il testo:
(EL_linker.ld) ... RAM (xrw) : ORIGIN = 0x20000004, LENGTH = xxxK ...
modifica il valore 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 togliere flag da Discard Unused Sections
3 cliccare "Apply and Close"
-
modificare la dimensione della memoria indicando la RAM disponibile sul uC:
-
copiare in include folder
Questo e' l'external loader
-
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
-
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.