Memstat

Memstat is a Mecrisp Forth development aid to monitor both MCU Flash and Ram memory usage.

Details are in the source below.

STM32F103C8

_images/memstats-stm32f103.jpg

GD32VF103

_images/memstats-GD32VF103.jpg

Code

Download memstat.fs

~/projects/programming-languages/forth/mecrisp-stellaris/GD32VF103/memstat.fs.html
 1 \ Program Name: memstat.fs
 2 \ Date: Sun 12 Jan 2020 18:55:01 AEDT
 3 \ Copyright 2020 by t.j.porter <terry@tjporter.com.au>, licensed under the GPLV2
 4 \ For Mecrisp-Stellaris and Mecrisp-Quintus by Matthias Koch.
 5 \ https://sourceforge.net/projects/mecrisp/
 6 \ Standalone: no preloaded support files required
 7 \
 8 \ This Program : Displays memory statistics
 9 \
10 \ ---------------------------------------------------------------------------\
11 \     Usage:    " ramsize-kb flashmod flash-size-register-address memstats "
12 \
13 \     'ramsize-kb' = Get the MCU ram size from the datasheet as it's not 
14 \     available from the mcu directly like the flash size.
15 \
16 \     'flashmod' = flash size modifier
17 \        '1' = normal use, flash exactly as reported
18 \
19 \        '2' = doubles the reported flash size. Only for a STM32F103C8 which
20 \        reports 64kB of Flash but actually has DOUBLE (128kB) that size.
21 \        OR if you suspect your chip MAY have double the flash advertized. Note:
22 \        will crash this program with a Exception if it doesn't!
23 \
24 \     'flash-size-register-address' = "Flash size data register address". Check
25 \     your STM reference manual "Device electronic signature" section for the
26 \     correct address.
27 \
28 \     'memstats' = this program
29 \
30 \ --------------------------- MCU Type Examples -----------------------------\
31 \  
32 \ ram-size  flashmod    ram-size    MCU Type
33 \ -kb                   -register   
34 \                       -address
35 \ --------  ---------   ---------   --------
36 \  8        1           $1FFFF7CC   STM32F0
37 \  20       1           $1FFFF7E0   STM32F10
38 \  20       2           $1FFFF7E0   STM32F103C8 (2x indicated Flash)
39 \  20       1           $1FFFF7E0   CKS32F103C8T6 (Chinese STM32F103CB clone)
40 \  32       1           $1FFFF7E0   GD32VF103 RISC-V32, Mecrisp-Quintus
41 \  20       1           $1FF8007C   STM32L0x3
42 \  64       1           $1FFF7A22   STM32F407,415,427,437,429,439
43 \ 
44 \ ----------------------------- Screenshot ----------------------------------\
45 \
46 \ free 
47 \ Memory stats in bytes: 
48 \ Total Flash:131072  Free:27336  Used:103736 
49 \ Total Ram:20480  Free:18784  Used:1696 
50 \ ok.
51 \ ----------------------------- Screenshot ----------------------------------\
52 
53  \ compiletoram
54  compiletoflash
55 
56  : flashfree ( flashmod flash-size-register-address -- free flash )
57    @ $FFFF and 1024 * * dup
58    compiletoram? >r
59    compiletoflash
60    here -
61       r> if compiletoram
62       then
63  ;
64 
65  : ramfree ( ramsize-kb -- free ram )
66    compiletoram? not
67    flashvar-here
68    4 -
69    compiletoram
70    here -
71    swap
72       if compiletoflash
73       then
74  ;
75 
76  : memstats ( ramsize-kb flashmod flash-size-register-address -- memory stats) cr
77    ." Memory stats in bytes: " cr
78    flashfree swap 2dup ." Total Flash:". ."  Free:" . swap - ."  Used:" . cr
79    1024 * ramfree  2dup  swap ." Total Ram:". ."  Free:" . - ."  Used:" . cr
80  ;
81 
82  : free ( -- ) 32 1 $1FFFF7E0 memstats ;  \ GD32VF103 
83  \ : free ( -- ) 20 2 $1FFFF7E0 memstats ;  \ STM32F103C8  
84 
85  \ free
86 
87  compiletoram

Warning

Ram and Flash values reported by “free” are totally seperate from values the Mecrisp-Stellaris Kernel uses. These values are preset and used when the Kernel is compiled. To configure the Kernel memory values for your MCU see Changing Kernel Flash and Ram values. Using these preset Kernel memory values, Mecrisp-Stellaris will print warnings when Flash or Ram reserves are exhausted.