mirror of
https://github.com/rfivet/stm32bringup.git
synced 2025-10-18 00:44:22 -04:00
Code check against documentation.
This commit is contained in:
19
Makefile
19
Makefile
@@ -120,9 +120,11 @@ CRC32SIGN := 1
|
|||||||
#SRCS = startup.txeie.c gpioa.c dht11main.c dht11.c
|
#SRCS = startup.txeie.c gpioa.c dht11main.c dht11.c
|
||||||
#SRCS = startup.txeie.c gpioa.c ds18b20main.c ds18b20.c
|
#SRCS = startup.txeie.c gpioa.c ds18b20main.c ds18b20.c
|
||||||
#SRCS = startup.txeie.c adc.c adcmain.c
|
#SRCS = startup.txeie.c adc.c adcmain.c
|
||||||
#SRCS = startup.txeie.c adc.c adccalib.c ds18b20.c
|
##SRCS = startup.txeie.c adc.c adccalib.c ds18b20.c
|
||||||
#SRCS = startup.ram.c txeie.c uptime.1.c
|
#SRCS = startup.ram.c txeie.c uptime.1.c
|
||||||
SRCS = startup.crc.c txeie.c uptime.1.c
|
#SRCS = startup.crc.c txeie.c uptime.c
|
||||||
|
SRCS = startup.crc.c adc.c adcmain.c
|
||||||
|
|
||||||
LIBSRCS = printf.c putchar.c puts.c # memset.c memcpy.c
|
LIBSRCS = printf.c putchar.c puts.c # memset.c memcpy.c
|
||||||
ALLSRCS = $(SRCS) $(LIBSRCS)
|
ALLSRCS = $(SRCS) $(LIBSRCS)
|
||||||
|
|
||||||
@@ -134,7 +136,7 @@ ifdef CRC32SIGN
|
|||||||
CDEFINES += -DCRC32SIGN=$(CRC32SIGN)
|
CDEFINES += -DCRC32SIGN=$(CRC32SIGN)
|
||||||
endif
|
endif
|
||||||
WARNINGS=-pedantic -Wall -Wextra -Wstrict-prototypes
|
WARNINGS=-pedantic -Wall -Wextra -Wstrict-prototypes
|
||||||
CFLAGS = $(CPU) -g $(WARNINGS) -Os $(CDEFINES)
|
CFLAGS = -std=c2x $(CPU) -g $(WARNINGS) -Os $(CDEFINES)
|
||||||
|
|
||||||
LD_SCRIPT = generic.ld
|
LD_SCRIPT = generic.ld
|
||||||
ifdef FLASHSTART
|
ifdef FLASHSTART
|
||||||
@@ -150,7 +152,7 @@ LDFLAGS =-Wl,$(subst $(space),$(comma),$(LDOPTS))
|
|||||||
|
|
||||||
.PHONY: clean all version
|
.PHONY: clean all version
|
||||||
|
|
||||||
all: $(PROJECT).$(BINLOC).bin $(PROJECT).hex
|
all: $(PROJECT).hex $(PROJECT).$(BINLOC).bin
|
||||||
|
|
||||||
version:
|
version:
|
||||||
@echo make $(MAKE_VERSION) $(MAKE_HOST)
|
@echo make $(MAKE_VERSION) $(MAKE_HOST)
|
||||||
@@ -169,7 +171,7 @@ ledtick.elf: ledtick.o
|
|||||||
cstartup.elf: cstartup.o
|
cstartup.elf: cstartup.o
|
||||||
|
|
||||||
%.elf:
|
%.elf:
|
||||||
@echo $@
|
@echo $@ from $+
|
||||||
$(CC) $(CPU) -T$(LD_SCRIPT) $(LDFLAGS) -nostartfiles -o $@ $+
|
$(CC) $(CPU) -T$(LD_SCRIPT) $(LDFLAGS) -nostartfiles -o $@ $+
|
||||||
$(SIZE) $@
|
$(SIZE) $@
|
||||||
$(OBJDUMP) -hS $@ > $(subst .elf,.lst,$@)
|
$(OBJDUMP) -hS $@ > $(subst .elf,.lst,$@)
|
||||||
@@ -186,13 +188,14 @@ ifdef CRC32SIGN
|
|||||||
mv signed.bin $@
|
mv signed.bin $@
|
||||||
|
|
||||||
%.hex: %.$(BINLOC).bin
|
%.hex: %.$(BINLOC).bin
|
||||||
@echo $@
|
@echo $@ from $<
|
||||||
$(OBJCOPY) --change-address=$(BINLOC) -I binary -O ihex $< $@
|
$(OBJCOPY) --change-address=$(BINLOC) -I binary -O ihex $< $@
|
||||||
endif
|
else
|
||||||
|
|
||||||
%.hex: %.elf
|
%.hex: %.elf
|
||||||
@echo $@
|
@echo $@ from $<
|
||||||
$(OBJCOPY) -O ihex $< $@
|
$(OBJCOPY) -O ihex $< $@
|
||||||
|
endif
|
||||||
|
|
||||||
libstm32.a: $(LIBSRCS:.c=.o)
|
libstm32.a: $(LIBSRCS:.c=.o)
|
||||||
$(AR) rc $@ $?
|
$(AR) rc $@ $?
|
||||||
|
@@ -196,59 +196,66 @@ ifdef CRC32SIGN
|
|||||||
mv signed.bin $@
|
mv signed.bin $@
|
||||||
|
|
||||||
%.hex: %.$(BINLOC).bin
|
%.hex: %.$(BINLOC).bin
|
||||||
@echo $@
|
@echo $@ from $<
|
||||||
$(OBJCOPY) --change-address=$(BINLOC) -I binary -O ihex $< $@
|
$(OBJCOPY) --change-address=$(BINLOC) -I binary -O ihex $< $@
|
||||||
|
else
|
||||||
|
|
||||||
|
%.hex: %.elf
|
||||||
|
@echo $@ from $<
|
||||||
|
$(OBJCOPY) -O ihex $< $@
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
<h2>Building and testing</h2>
|
<h2>Building and testing</h2>
|
||||||
|
|
||||||
If I build an executable, I can see that the binary file is CRC-32
|
If I build an executable, I can see that the binary file is CRC-32
|
||||||
signed. In the example below, the CRC-32 signature is 0xBC689506 and the
|
signed. In the example below, the CRC-32 signature is 0xDEAD68BE and the
|
||||||
total binary image is 2680 bytes long.
|
total binary image is 1728 bytes long.
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
$ make
|
$ make
|
||||||
f030f4.elf
|
f030f4.elf from startup.crc.o txeie.o uptime.o libstm32.a
|
||||||
Memory region Used Size Region Size %age Used
|
Memory region Used Size Region Size %age Used
|
||||||
FLASH: 2680 B 16 KB 16.36%
|
FLASH: 1728 B 16 KB 10.55%
|
||||||
RAM: 24 B 4 KB 0.59%
|
RAM: 16 B 4 KB 0.39%
|
||||||
text data bss dec hex filename
|
text data bss dec hex filename
|
||||||
2673 4 20 2697 a89 f030f4.elf
|
1725 0 16 1741 6cd f030f4.elf
|
||||||
f030f4.0x08000000.bin
|
f030f4.0x08000000.bin
|
||||||
crc32/sign32 f030f4.0x08000000.bin
|
crc32/sign32 f030f4.0x08000000.bin
|
||||||
BC689506 f030f4.0x08000000.bin: 2676, signed.bin: 2680
|
DEAD68BE f030f4.0x08000000.bin: 1724, signed.bin: 1728
|
||||||
mv signed.bin f030f4.0x08000000.bin
|
mv signed.bin f030f4.0x08000000.bin
|
||||||
f030f4.hex
|
f030f4.hex from f030f4.0x08000000.bin
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
I can double check that the value at the end of the binary file matches.
|
I can double check that the value at the end of the binary file matches.
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
$ hexdump -C f030f4.0x08000000.bin | tail
|
$ hexdump -C f030f4.0x08000000.bin | tail
|
||||||
000009f0 01 46 63 46 52 41 5b 10 10 46 01 d3 40 42 00 2b |.FcFRA[..F..@B.+|
|
00000630 8b 42 01 d3 cb 00 c0 1a 52 41 83 08 8b 42 01 d3 |.B......RA...B..|
|
||||||
00000a00 00 d5 49 42 70 47 63 46 5b 10 00 d3 40 42 01 b5 |..IBpGcF[...@B..|
|
00000640 8b 00 c0 1a 52 41 43 08 8b 42 01 d3 4b 00 c0 1a |....RAC..B..K...|
|
||||||
00000a10 00 20 00 f0 05 f8 02 bd 00 29 f8 d0 16 e7 70 47 |. .......)....pG|
|
00000650 52 41 41 1a 00 d2 01 46 52 41 10 46 70 47 ff e7 |RAA....FRA.FpG..|
|
||||||
00000a20 70 47 c0 46 50 4c 4c 48 53 49 0a 00 20 25 64 20 |pG.FPLLHSI.. %d |
|
00000660 01 b5 00 20 00 f0 06 f8 02 bd c0 46 00 29 f7 d0 |... .......F.)..|
|
||||||
00000a30 25 73 25 73 00 75 70 00 77 65 65 6b 00 64 61 79 |%s%s.up.week.day|
|
00000670 76 e7 70 47 70 47 c0 46 50 4c 4c 48 53 45 0a 00 |v.pGpG.FPLLHSE..|
|
||||||
00000a40 00 68 6f 75 72 00 6d 69 6e 75 74 65 00 73 65 63 |.hour.minute.sec|
|
00000680 20 25 64 20 25 73 25 73 00 75 70 00 77 65 65 6b | %d %s%s.up.week|
|
||||||
00000a50 6f 6e 64 00 30 31 32 33 34 35 36 37 38 39 41 42 |ond.0123456789AB|
|
00000690 00 64 61 79 00 68 6f 75 72 00 6d 69 6e 75 74 65 |.day.hour.minute|
|
||||||
00000a60 43 44 45 46 00 00 20 2b 2b 10 0a 02 08 00 00 00 |CDEF.. ++.......|
|
000006a0 00 73 65 63 6f 6e 64 00 30 31 32 33 34 35 36 37 |.second.01234567|
|
||||||
00000a70 ef 00 00 00 06 95 68 bc |......h.|
|
000006b0 38 39 41 42 43 44 45 46 00 00 00 00 be 68 ad de |89ABCDEF.....h..|
|
||||||
00000a78
|
000006c0
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
I can flash the resulting intel hex file and see that it executes.
|
I can flash the resulting intel hex file and see that it executes.
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
$ stm32flash -x f030f4.hex COM3
|
$ stm32flash -x f030f4.hex COM6
|
||||||
stm32flash 0.6-patch-hex
|
stm32flash 0.7-patch-exe
|
||||||
|
|
||||||
http://stm32flash.sourceforge.net/
|
http://stm32flash.sourceforge.net/
|
||||||
|
|
||||||
Using Parser : Intel HEX
|
Using Parser : Intel HEX
|
||||||
Location : 0x8000000
|
Location : 0x8000000
|
||||||
Size : 2680
|
Size : 1728
|
||||||
Interface serial_w32: 57600 8E1
|
Interface serial_w32: 57600 8E1
|
||||||
Version : 0x31
|
Version : 0x31
|
||||||
Option 1 : 0x00
|
Option 1 : 0x00
|
||||||
@@ -260,18 +267,18 @@ Device ID : 0x0444 (STM32F03xx4/6)
|
|||||||
- System RAM : 3KiB
|
- System RAM : 3KiB
|
||||||
Write to memory
|
Write to memory
|
||||||
Erasing memory
|
Erasing memory
|
||||||
Wrote address 0x08000a78 (100.00%) Done.
|
Wrote address 0x080006c0 (100.00%) Done.
|
||||||
|
|
||||||
Starting execution at address 0x08000000... done.
|
Starting execution at address 0x08000000... done.
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
I can use stm32flash to compute the CRC-32 checksum on the first 2680
|
I can use <b><i>stm32flash</i></b> to compute the CRC-32 checksum on the first
|
||||||
bytes of FLASH, the result is 0 as this covers both the payload AND
|
1728 bytes of FLASH, the result is 0 as this covers both the payload AND
|
||||||
the CRC-32 checksum value.
|
the CRC-32 checksum value.
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
$ stm32flash -C -S 0x08000000:2680 COM3
|
$ stm32flash -C -S 0x08000000:1728 COM6
|
||||||
stm32flash 0.6-patch-hex
|
stm32flash 0.7-patch-exe
|
||||||
|
|
||||||
http://stm32flash.sourceforge.net/
|
http://stm32flash.sourceforge.net/
|
||||||
|
|
||||||
@@ -285,17 +292,17 @@ Device ID : 0x0444 (STM32F03xx4/6)
|
|||||||
- Option RAM : 16b
|
- Option RAM : 16b
|
||||||
- System RAM : 3KiB
|
- System RAM : 3KiB
|
||||||
CRC computation
|
CRC computation
|
||||||
CRC address 0x08000a78 (100.00%) Done.
|
CRC address 0x080006c0 (100.00%) Done.
|
||||||
CRC(0x08000000-0x08000a78) = 0x00000000
|
CRC(0x08000000-0x080006c0) = 0x00000000
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
If I ask stm32flash to compute the CRC-32 checksum on the first 2676
|
If I ask <b><i>stm32flash</i></b> to compute the CRC-32 checksum on the first
|
||||||
bytes (payload excluding CRC-32 checksum value), it returns 0xbc689506,
|
1724 bytes (payload excluding CRC-32 checksum value), it returns 0xdead68be,
|
||||||
which is the value computed at build time.
|
which is the value computed at build time.
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
$ stm32flash -C -S 0x08000000:2676 COM3
|
$ stm32flash -C -S 0x08000000:1724 COM6
|
||||||
stm32flash 0.6-patch-hex
|
stm32flash 0.7-patch-exe
|
||||||
|
|
||||||
http://stm32flash.sourceforge.net/
|
http://stm32flash.sourceforge.net/
|
||||||
|
|
||||||
@@ -309,25 +316,27 @@ Device ID : 0x0444 (STM32F03xx4/6)
|
|||||||
- Option RAM : 16b
|
- Option RAM : 16b
|
||||||
- System RAM : 3KiB
|
- System RAM : 3KiB
|
||||||
CRC computation
|
CRC computation
|
||||||
CRC address 0x08000a74 (100.00%) Done.
|
CRC address 0x080006bc (100.00%) Done.
|
||||||
CRC(0x08000000-0x08000a74) = 0xbc689506
|
CRC(0x08000000-0x080006bc) = 0xdead68be
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
Because STM32F030 USART bootloader is v3.1, it doesn't implement the CRC
|
Because STM32F030 USART bootloader is v3.1, it doesn't implement the CRC
|
||||||
checksum command included in v3.3. This means that in this case
|
checksum command included in v3.3. This means that in this case
|
||||||
stm32flash computes the CRC checksum value on its own. You can check the
|
<b><i>stm32flash</i></b> computes the CRC checksum value on its own. You can
|
||||||
sources of stm32flash for its implementation of the CRC-32 calculation.
|
check the sources of <b><i>stm32flash</i></b> for its implementation of the
|
||||||
|
CRC-32 calculation.
|
||||||
|
|
||||||
<h2>Checkpoint</h2>
|
<h2>Checkpoint</h2>
|
||||||
|
|
||||||
There is variation in the functionality of the CRC calculation unit
|
There is variations in the functionality of the CRC calculation unit
|
||||||
among different STM32 chipset family. The <code>check_flash()</code>
|
among different STM32 chipset family. The <code>check_flash()</code>
|
||||||
implementation I just made relying on the default settings for polynomial,
|
implementation I just made relies on the default settings for polynomial,
|
||||||
initial value, polynomial length and shift direction should be common.
|
initial value, polynomial length and shift direction. This should be common to
|
||||||
|
most chipset.
|
||||||
<p>
|
<p>
|
||||||
<a href="39_resistor.html">Next</a>, I will use the ADC to read a resistor
|
<a href="39_resistor.html">Next</a>, I will use the ADC to read a resistor
|
||||||
value.
|
value.
|
||||||
|
|
||||||
<hr>© 2020-2024 Renaud Fivet
|
<hr>© 2020-2025 Renaud Fivet
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
4
uptime.c
4
uptime.c
@@ -1,5 +1,5 @@
|
|||||||
/* uptime.c -- tells how long the system has been running */
|
/* uptime.c -- tells how long the system has been running */
|
||||||
/* Copyright (c) 2020-2023 Renaud Fivet */
|
/* Copyright (c) 2020-2025 Renaud Fivet */
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "system.h" /* uptime, yield() */
|
#include "system.h" /* uptime, yield() */
|
||||||
@@ -10,7 +10,7 @@ static void display( unsigned u, const char *s) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int main( void) {
|
int main( void) {
|
||||||
static unsigned last ;
|
unsigned last = 0 ;
|
||||||
|
|
||||||
for( ;;)
|
for( ;;)
|
||||||
if( last != uptime) {
|
if( last != uptime) {
|
||||||
|
Reference in New Issue
Block a user