roloFlash kann erkennen, welche Mikrocontroller angeschlossen sind und in Abhängigkeit davon zu verschiedenen Skripten verzweigen. Diese Kurzanleitung demonstriert das Vorgehen bei SWD und JTAG. Folgendes ist mit dem hier vorgestelltem Skript möglich:
Verwenden Sie die Vorlage BRANCH.BAS, welche Sie für Ihre MCU anpassen können. Darin finden Sie fast am Anfang der Datei folgenden Abschnitt:
! *** Please adapt to your requirements! ***
! List of names of targets of interest, for example:
dbNames = vari("STM32F103RB", "STM32WB55RG")
! List of corresponding device identifiers in the DBGMCU register for STM32
! devices, otherwise type 0 as a value. Must correspond to the list of dbNames,
! for example:
identifiers = long($410, $495)
! Corresponding list of scripts to chain to
scripts = vari("F103RB.BIN", "WB55RG.BIN")
busSpeed = 100000 ! Bus speed in Hertz. 100 kHz are a conservative
! choice, to ensure reliable operation at a low
! target CPU clock or low roloFlash CPU clock.
! The scripts we will chain to, will reopen with
! an individual speed.
busType = JTAG ! Choose between SWD and JTAG
roloFlashHiSpeedMode = 0 ! 0 (false): ca. 20mA@3.3V, is slower
! 1 (true): ca. 80mA@3.3V, is faster
Die zu erkennenden MCUs werden in diesem Beispielskript durch die
Bezeichner "STM32F103RB"
und "STM32WB55RG"
festgelegt und in der Liste dbNames
abgelegt. Verwenden Sie
hier eine Liste mit Bezeichnern für die MCUs, welche Sie unterscheiden
wollen. Die hier zu verwendenden Bezeichner müssen exakt den im Handbuch im Kapitel “IX
Spezifikationen” angegebenen Bezeichnern entsprechen:
dbNames = vari("STM32F103RB", "STM32WB55RG")
Bei STM32-MCUs gibt es ein DBGMCU-Register, welches einen 12-Bit Device Identifier enthält. Dieser kann zusätzlich überprüft werden. Die von ST Microelectronics fest vorgegebenen Werte finden Sie im jeweiligen Handbuch des Herstellers. Ein Wert 0 legt fest, daß diese Prüfung nicht stattfinden soll.
Wichtig ist, daß die Elemente der Liste identifiers
zur
Liste dbNames
passen müssen. Folglich müssen auch beide
Listen exakt dieselbe Anzahl an Elementen haben.
! List of corresponding device identifiers in the DBGMCU register for STM32
! devices, otherwise type 0 as a value. Must correspond to the list of dbNames,
! for example:
identifiers = long($410, $495)
Die aufzurufenden Skripte werden in einer weiteren Liste
scripts
angegeben. Diese Liste muß ebenfalls genau zur
Liste dbNames
passen:
scripts = vari("F103RB.BIN", "WB55RG.BIN")
Weiterhin werden Einstellungen für den Bustakt, den verwendeten Bustyp (JTAG oder SWD), sowie den Geschwindigkeits-Modus für den roloFlash benötigt.
busSpeed = 100000 ! Bus speed in Hertz. 100 kHz are a conservative
! choice, to ensure reliable operation at a low
! target CPU clock or low roloFlash CPU clock.
! The scripts we will chain to, will reopen with
! an individual speed.
busType = JTAG ! Choose between SWD and JTAG
roloFlashHiSpeedMode = 0 ! 0 (false): ca. 20mA@3.3V, is slower
! 1 (true): ca. 80mA@3.3V, is faster
Passen Sie all diese Werte und Parameter passend für Ihr Projekt an,
und benennen Sie die Skriptdatei um zu
RUN_V07.BAS
. (Großschreibung muß
beachtet werden!) Übersetzen Sie diese Datei durch den Aufruf von
compile.bat
in die Datei
RUN_V07.BIN
, kopieren Sie diese
gegebenenfalls auf die SD-Karte und stecken Sie diese in den
roloFlash.
Zum Testen empfehlen wir zuerst keine weiteren Skripte auf der SD-Karte zu haben. So können Sie jede Ihrer MCUs testen. Es wird zwar eine Exception gesetzt und der roloFlash blinkt nach der Ausführung rot, da das weiterführenden Skript nicht existiert. Aber sie können in LOG.TXT prüfen, ob das richtige Skript aufgerufen worden wäre.
Eine Ausgabe kann z.B. lauten:
target STM32F103RB found, chain to F103RB.BIN
Nachdem Ihre Tests abgeschlossen sind, fahren Sie mit dem nächsten Kapitel fort.
Für die einzelnen Skripte für die verschiedenen MCU empfehlen wir, sich aus den Beispielen eine passende Vorlage auszuwählen und anzupassen. Weitere Informationen finden Sie hierzu in der Kurzanleitung “roloFlash mit SD-Karte benutzen”.
Wählen Sie dabei die Dateinamen so wie Sie diese in dem Array scripts
eingetragen hatten. Rufen Sie den Compiler
rbc_v07.exe
mit dem Namen Ihres zu
übersetzendes Skripts auf, z.B.:
rbc_v07.exe F103RB.BAS
Sie erhalten in diesem Fall die Datei F103RB.BIN
, auf
die sie in Ihrem Array scripts
referenziert haben.
Sie finden dieses Skript auch hier als BRANCH.BAS.
#roloFlash 2, v07+
! ***************************************************************************
! *
! * Sample script for JTAG or SWD determine which target is conneced:
! * - via IDCODE
! * - in case of STM32, if wanted: additionally via device identifiers in
! * the DBGMCU register
! * - in case of JTAG and STM32: additionally via IDCODE of secondary
! * JTAG-device (boundary scan controller)
! *
! * Task: Read the IDCODE via JTAG or SWD and then chain to the corresponding
! * script
! *
! * Copyright (C) 2009-2025 by halec embedded solutions, https://www.halec.de
! *
! ***************************************************************************
! For all files on the microSD card, the following applies:
! - File name has to be in 8.3 format
! - File name must contain only CAPITAL LETTERS
! - (see manual, chapter "Files")
! *** Please adapt to your requirements! ***
! List of names of targets of interest, for example:
dbNames = vari("STM32F103RB", "STM32WB55RG")
! List of corresponding device identifiers in the DBGMCU register for STM32
! devices, otherwise type 0 as a value. Must correspond to the list of dbNames,
! for example:
identifiers = long($410, $495)
! Corresponding list of scripts to chain to
scripts = vari("F103RB.BIN", "WB55RG.BIN")
busSpeed = 100000 ! Bus speed in Hertz. 100 kHz are a conservative
! choice, to ensure reliable operation at a low
! target CPU clock or low roloFlash CPU clock.
! The scripts we will chain to, will reopen with
! an individual speed.
busType = JTAG ! Choose between SWD and JTAG
roloFlashHiSpeedMode = 0 ! 0 (false): ca. 20mA@3.3V, is slower
! 1 (true): ca. 80mA@3.3V, is faster
! Set LED 1 to green -> symbolizes script starting
led_on 1, COLOR_GREEN
! ---- Preparations ----
! Delete old log file, if present
f = "LOG.TXT"
if fs_fileExists(0, f)
fs_remove 0, f
endif
! Write software version of roloFlash and script name to LOG.TXT
print "softwareVersion=", sys_softwareVersion, "\r\n"
print "Running script copied from scripts/???/ ...\r\n"
! If roloFlashHiSpeedMode has been selected, set CPU clock of roloFlash to
! the maximum
if roloFlashHiSpeedMode
sys_setCpuClock CPU_CLOCKMAX
endif
! ---- Scan JTAG / SWD bus ----
if busType = JTAG
print "Scanning JTAG bus ...\r\n"
else
print "Scanning SWD bus ...\r\n"
endif
busHandle = bus_open(busType, 0, busSpeed)
devices = bus_scan(busHandle)
print "Number of devices:", size(devices), "\r\n"
for i = 0 to size(devices) - 1
print " Found device: id=", devices[i], "\r\n"
next
! ---- If no JTAG / SWD device has been found, abort ----
if size(devices) < 1
print "ERROR: no device found!\r}n"
throw USEREXCEPTION + 1
endif
print "Checking MCUs ...\r\n"
for i = 0 to size(dbNames) - 1
! ---- Compare the idcode with the idcode of the MCUs in the list ----
dbHandle = db_getHandle(dbNames[i])
expectedCoreIDCODE = db_get(dbHandle, db_coreIDCODE)
print "expectedCoreIDCODE: ", expectedCoreIDCODE, "\r\n"
if busType = JTAG
mask = $0fffffff
else
mask = $0fff0fff
endif
if ((devices[0] and mask) = (expectedCoreIDCODE and mask))
print "idcode cpu ok..\r\n"
! ---- idcode match: ----
! JTAG: STM32 devices adds a second device on the bus, the
! boundaryscan controller
catch exceptionOld
if (exceptionOld = 0) and (busType = JTAG)
expectedBoundaryScanIDCODE = db_get(dbHandle, db_boundaryScanIDCODE)
endif
catch exceptionNew ! no boundaryScanIDCODE in the database
if exceptionOld
throw exceptionOld
endif
if (expectedBoundaryScanIDCODE = 0) xor (size(devices) = 2)
match = 1
if size(devices)
if((devices[1] and mask) <> (expectedBoundaryScanIDCODE and mask))
print "idcode bs nok..\r\n"
match = 0
endif
endif
if match and (identifiers[i] <> 0)
print "check device identifier..\r\n"
! ---- Read the DBGMCU from the target and get the lowest 12 bits for
! ---- the device identifier
targetHandle = target_open(busHandle, 0, DB_get(dbHandle, db_family))
target_setMode targetHandle, PROGRAMMODE
dbgmcu = target_read(targetHandle, readMemory , $E0042000, 4) ! $E0042000: DBGMCU register
target_close targetHandle
identifier = (dbgmcu[0] + dbgmcu[1] * 256) and ((1 << 12) - 1)
! ---- Compare the device identifier with the list ----
match = (identifier = identifiers[i])
endif
if match
print "MATCH..\r\n"
! ---- idcode and device identifier match: ----
! ---- Prepare and chain to the corresponding script in the list ----
bus_close busHandle
print "target ", dbNames[i], " found, chain to ", scripts[i], "..\r\n"
sys_setLogMode LOGMODE_IMMEDIATE
sys_setLogMode LOGMODE_NORMAL
sys_setCpuClock CPU_CLOCKMIN
chain SDCARD,scripts[i]
endif
endif
endif
next
bus_close busHandle
! ---- device is not in the list of expected devices ----
throw USEREXCEPTION + 900 ! avoid collisions with other user exceptions
! ---- Postprocessing ----
! ---- Check for possibly occurred exceptions, write ----
! ---- evaluation to log file and signal it via LEDs ----
catch exception
print "Duration [ms]: ", sys_getSystemTime(), "\r\n"
if exception <> 0
! There has been an error, record the error in LOG.TXT
print "ERROR: Exception ", exception
! Throw exception again, after it has been caught. As a result, the number
! of the exception gets displayed via LED blink codes. The blink codes
! are documented in the manual, chapter "Meaning of LED Codes", subchapter
! "Exception has Occurred"
throw exception
else
! No errors: write to log file and switch LED 5 to green
print "Script ran successfully.\r\n"
led_on 5, COLOR_GREEN
endif