1. Article purpose[edit | edit source]
This article describes how to read or write to the STM32MPU internal peripherals registers using CMSIS-SVD file through GDB.
2. Information about CMSIS-SVD files[edit | edit source]
Extracted from Arm® Keil® web page[1]:
- The CMSIS System View Description format(CMSIS-SVD) formalizes the description of the system contained in Arm Cortex-M processor-based microcontrollers, in particular, the memory mapped registers of peripherals. The detail contained in system view descriptions is comparable to the data in device reference manuals. The information ranges from high level functional descriptions of a peripheral all the way down to the definition and purpose of an individual bit field in a memory mapped register.
Arm® also specifies on an other web page that CMSIS-SVD[2] is not restricted to only for Cortex®-M:
- For every supported microcontroller, debuggers can provide detailed views to the device peripherals that display the current register state.
3. Python scripts environment for GDB[edit | edit source]
3.1. CMSIS-SVD file parser[edit | edit source]
A CMSIS-SVD file parser is proposed by Paul Osborne and shared is on github: https://github.com/posborne/cmsis-svd.
This package is reused as is. Add STM32MPU microprocessor if it is missing from the CMSIS-SVD files.
For licensing, following information is provided:
In general, the following rules apply:
- Under data, the license from each Vendor is provided along with the SVDs from that vendor. Please review this license before use of the SVDs contained therein. Look for files named the following for license information.
- All other code is licensed under the terms of the Apache License v2.0 (See LICENSE-APACHE).
In our case, we will only add new files in data/STMicro sub-directory, so STMicroelectronics license is applied.
This package is part of the OpenSTLinux Developer Package.
3.2. Python scripts for GDB[edit | edit source]
svd-tools[3] github repository provides a gdb-svd python module for gdb which adds some instructions to:
- get information on peripherals | registers | fields
- get registers values | register fields
- set registers values | register fields
For more information, refer to the README[4] file of the repository.
This package is part of the OpenSTLinux Developer Package.
3.3. Setting environment[edit | edit source]
As pre-requisites, the gdb setup must be installed and running.
As CMSIS-SVD scripts are also part of the OpenSTLinux Developer Package, the environment is set by using the instructions below :
# Get the sysroot path from your SDK show environment OECORE_NATIVE_SYSROOT OECORE_NATIVE_SYSROOT = <path_to_sysroot> cd <path_to_sysroot> source usr/share/svd-tools/gdb-svd.py
4. Python scripts usage for GDB[edit | edit source]
4.1. Load svd file for the requested SoC[edit | edit source]
The svd instruction loads the appropriate SOC svd files.
4.1.1. For STM32MP13x lines [edit | edit source]
svd usr/share/cmsis-svd/cmsis_svd/data/STMicro/STM32MP13xx.svd
4.1.2. For STM32MP15x lines [edit | edit source]
Since ecosystem release v5.1.0
svd usr/share/cmsis-svd/cmsis_svd/data/STMicro/STM32MP151x.svd svd usr/share/cmsis-svd/cmsis_svd/data/STMicro/STM32MP153x.svd svd usr/share/cmsis-svd/cmsis_svd/data/STMicro/STM32MP157x.svd
For ecosystem release v5.0.0
svd usr/share/cmsis-svd/cmsis_svd/data/STMicro/STM32MP15xx.svd
4.1.3. For STM32MP25x lines [edit | edit source]
svd usr/share/cmsis-svd/cmsis_svd/data/STMicro/STM32MP25_CA35.svd svd usr/share/cmsis-svd/cmsis_svd/data/STMicro/STM32MP25_CM0P.svd svd usr/share/cmsis-svd/cmsis_svd/data/STMicro/STM32MP25_CM33.svd
Note: for all svd instructions described below, instruction completion for register name is working.
4.2. Getting peripheral / register / field information[edit | edit source]
This instruction displays any peripheral, register, and field information.
The last parameter can be part of the name, a filter is applied with the string.
svd info <peripheral> [register] [field]
Please refer to the following examples:
- Getting information on all available ADC peripherals
svd info ADC +Peripherals-+------------+--------+-----------------------------+ | name | base | access | description | +------------+------------+--------+-----------------------------+ | ADC2 | 0x48003100 | None | ADC2 | | ADC | 0x48003000 | None | ADC | | ADC_common | 0x48003300 | None | Analog-to-Digital Converter | +------------+------------+--------+-----------------------------+
- Getting information on all ADC2 registers beginning by S
svd info ADC2 ADC_S +Registers--+------------+------------+---------------------------------+ | name | address | access | description | +-----------+------------+------------+---------------------------------+ | ADC_SMPR1 | 0x48003114 | read-write | ADC sample time register 1 | | ADC_SMPR2 | 0x48003118 | read-write | ADC sample time register 2 | | ADC_SQR1 | 0x48003130 | read-write | ADC regular sequence register 1 | | ADC_SQR2 | 0x48003134 | read-write | ADC regular sequence register 2 | | ADC_SQR3 | 0x48003138 | read-write | ADC regular sequence register 3 | | ADC_SQR4 | 0x4800313c | read-write | ADC regular sequence register 4 | +-----------+------------+------------+---------------------------------+
- Getting information on all fields (peripheral: ADC2 register: CR) beginning by J
svd info ADC2 ADC_CR J
+Fields----+-----------+--------+-------------+
| name | [msb:lsb] | access | description |
+----------+-----------+--------+-------------+
| JADSTART | [3:3] | None | JADSTART |
| JADSTP | [5:5] | None | JADSTP |
+----------+-----------+--------+-------------+
4.3. Getting register(s) value(s)[edit | edit source]
This instruction provides the register list and field values.
svd get [peripheral] [register]
Please refer to the following examples:
- Getting all the information for an entire peripheral
svd get DLYBSD1
+Registers---+------------+------------+------------------------------------------------------------+
| name | address | value | fields |
+------------+------------+------------+------------------------------------------------------------+
| DLYB_CR | 0x58006000 | 0x00000000 | DEN[0:0]=0x0 SEN[1:1]=0x0 |
| DLYB_CFGR | 0x58006004 | 0x80000000 | SEL[3:0]=0x0 UNIT[14:8]=0x0 LNG[27:16]=0x0 LNGF[31:31]=0x1 |
| DLYB_VERR | 0x580063f4 | 0x00000000 | MINREV[3:0]=0x0 MAJREV[7:4]=0x0 |
| DLYB_IPIDR | 0x580063f8 | 0x00000000 | ID[31:0]=0x0 |
| DLYB_SIDR | 0x580063fc | 0x00000000 | SID[31:0]=0x0 |
+------------+------------+------------+------------------------------------------------------------+
- Getting information for just one register
svd get DLYBSD1 DLYB_CFGR
+Registers--+------------+------------+------------------------------------------------------------+
| name | address | value | fields |
+-----------+------------+------------+------------------------------------------------------------+
| DLYB_CFGR | 0x58008004 | 0x00000000 | SEL[3:0]=0x0 UNIT[14:8]=0x0 LNG[27:16]=0x0 LNGF[31:31]=0x0 |
+-----------+------------+------------+------------------------------------------------------------+
4.4. Writing register value[edit | edit source]
This instruction sets the register value.
svd set <peripheral> <register> [field] <value>
Please refer to the following examples.
- Set register values
svd set QUADSPI QUADSPI_LPTR 0x50
- Set field values
svd set QUADSPI QUADSPI_LPTR TIMEOUT 0x10
5. References[edit | edit source]