svd2mem-sqlite¶
The end of 2021 approaches with only three days remaining so I thought I’d get this new project out.
This is a new take on SVD2FORTH which only ran on Unix and was a bit complex to set up and use. so I’ve simplified the process of finding the hex address values for STM32xxxx peripheral registers to use in your sourcecode. It’s a manual alternative to C headers.
My idea is that this is run in a open Xterm or a GUI app where you can search for any register using simple SQL syntax, then copy and paste the value into your Forth source. Of course you can also generate any output formats and use more complex SQL queries from shell or batch files as desired. The database can be added to, edited etc to suit any additions you may desire.
Note
The addresses are ABSOLUTE being precomputed from the CMSIS-SVD “base + offset” values, see Example Usage at the end of the document.
Another advantage is that there are a number of cross platform FLOSS web browser and stand alone client apps that will read and modify SQLite databases. i.e. https://sqlitebrowser.org, Google Chrome plus many others, so you have choices of GUI and CLI clients to suit your personal preference.
DOWNLOAD: https://sourceforge.net/projects/mecrisp-stellaris-folkdoc/files/svd2mem-sqlite-29.12.21-F95f2.zip
Details¶
Project: svd2mem-sqlite
Created: Tue 28 Dec 2021 17:50:07 AEDT
Author Copyright 2021 by t.j.porter <terry@tjporter.com.au>
Purpose: A easy to use CMSIS-SVD compliant STM32F051 register memorymap database.
Intended Audience: Forth users
MCUs: As of 29 Dec 2021: STM32F051, STM32L07x, STM32F103xx, STM32F7x, STM32H7x3
Board: any
Core: Cortex-M
Required: SQLite3
OS?: Should work on *BSD, Linux, OSX, Windows
Critical: SQLite3
References: https://www.tutorialspoint.com/sqlite/index.htm
license: MIT, please see COPYING
Note: Addresses are ABSOLUTE and names are CMSIS-SVD compliant.
Operation¶
Although a STM32F051 is used here, exactly the same operations apply to any other MCU release.
Uncompress The Database¶
gunzip STM32F051.sqlite.memmap.db.gz
Run The Database¶
This starts a new xterm and protects the database from those ‘oops’ moments.
xterm -e sqlite3 --readonly STM32F051.sqlite.memmap.db &
SQlite Output Formats¶
The sqlite3 program is able to show the results of a query in 14 different formats:
ascii
box
csv
column
html
insert
json
line
list
markdown
quote
table
tabs
tcl
Set Output Format¶
.mode column
.width 25 15 15 50
Display All Peripherals¶
sqlite> .tables
ADC DAC Flash GPIOD I2C2 RCC SYSCFG TIM16 TIM6 WWDG
CEC DBGMCU GPIOA GPIOE IWDG RTC TIM1 TIM17 TSC
COMP DMA GPIOB GPIOF NVIC SPI1 TIM14 TIM2 USART1
CRC EXTI GPIOC I2C1 PWR SPI2 TIM15 TIM3 USART2
Search Examples¶
Display All TIM2 Registers¶
SELECT * FROM 'TIM3';
TIM3 - - General-purpose-timers
TIM3_CR1 $40000400 read-write control register 1
TIM3_CR2 $40000404 read-write control register 2
TIM3_SMCR $40000408 read-write slave mode control register
TIM3_DIER $4000040C read-write DMA/Interrupt enable register
TIM3_SR $40000410 read-write status register
TIM3_EGR $40000414 write-only event generation register
TIM3_CCMR1_Output $40000418 read-write capture/compare mode register 1 output mode
TIM3_CCMR1_Input $40000418 read-write capture/compare mode register 1 input mode
TIM3_CCMR2_Output $4000041C read-write capture/compare mode register 2 output mode
TIM3_CCMR2_Input $4000041C read-write capture/compare mode register 2 input mode
TIM3_CCER $40000420 read-write capture/compare enable register
TIM3_CNT $40000424 read-write counter
TIM3_PSC $40000428 read-write prescaler
TIM3_ARR $4000042C read-write auto-reload register
TIM3_CCR1 $40000434 read-write capture/compare register 1
TIM3_CCR2 $40000438 read-write capture/compare register 2
TIM3_CCR3 $4000043C read-write capture/compare register 3
TIM3_CCR4 $40000440 read-write capture/compare register 4
TIM3_DCR $40000448 read-write DMA control register
TIM3_DMAR $4000044C read-write DMA address for full transfer
Find ARR Bitfield(s)¶
SELECT * FROM 'TIM3' WHERE name LIKE '%ARR%';
TIM3_ARR $4000042C read-write auto-reload register
Find CCR Bitfield(s)¶
sqlite> SELECT * FROM 'TIM3' WHERE name LIKE '%CCR%';
TIM3_CCR1 $40000434 read-write capture/compare register 1
TIM3_CCR2 $40000438 read-write capture/compare register 2
TIM3_CCR3 $4000043C read-write capture/compare register 3
TIM3_CCR4 $40000440 read-write capture/compare register 4
Example Usage¶
See STMicro document RM0091, section 18.4.1 TIM2 and TIM3 control register 1 (TIM2_CR1 and TIM3_CR1)
Mecrisp-Stellaris Forth syntax used.
Magic Numbers¶
%1 %3 lshift $40000400 \ set OPM; 1: Counter stops counting at the next update event (clearing the bit CEN)
Labels¶
$40000400 constant TIM3_CR1
%1 %3 lshift TIM3_CR1 bis \ set OPM; 1: Counter stops counting at the next update event (clearing the bit CEN)
GUI Interfaces¶
Many exist for all OS’s inc *BSD Linux, OSX, Windows.
Here are some examples:
Bitfield Viewer¶
This is a preview of my prototype Bitfield Viewer and select tool.
The aim was to make a easy to use Bitfield viewer that can preselect any peripheral and then easily scroll to find the right bitfield before copying it to the programmers source.
The bitfield data resides in a Sqlite3 database built automatically by swd2forth-v6, which means any client that can read Sqlite3 databases can use it. In this picture the reader is https://github.com/inloop/sqlite-viewer
Visual Simplification¶
Understanding Cortex-M peripheral registers and bitfields can be daunting because of their abundance, so the Bitfield Viewer was also designed to present this information in a simpler way.
By selecting one peripheral at a time to reduce visual noise.
listing the number of rows in a peripheral. Apart from the “Reset Value” row at start of each register, all the other rows are bitfields. For instance TIM6 has 22 rows, but TIM1 has 150, so straight away you can see which is the more complex timer.
Tim6 Peripheral View¶
IWDG Peripheral View¶
How complex is the Watchdog peripheral ?
Peripheral Selection View¶
All the MCU (STM32F051) peripherals are in this list for easy choice.