+ one example for STM32F401 "black pill" added.

This commit is contained in:
Vovanium 2024-03-20 17:22:53 +03:00
parent 0700017033
commit b465184160
8 changed files with 251 additions and 0 deletions

View File

@ -34,6 +34,12 @@ stm32f429disco (stm32f429disc1) -- board available from STM.
STM32F407Z-based board from PiSwords. Widely available from chinese suppliers.
407z_piswords in examples.
STM32F401/411-based "black pill" boards from WeAct.
Also widely available from chinese suppliers.
401c_blackpill in examples
(Note: currently there's no suitable runtime for STM32F401/STM32F411.
See GNAT section of this README for details).
### Default values
Default values are given to register and their field according to following rules:
@ -96,3 +102,13 @@ what those accesses actually do.
Currently GPR cannot manage aggregate projects for different targets.
GNU Make script is used to build whole set of libraries instead.
There are no GNAT runtime for some widely used boards.
For STM32F401 "black bill" there's a patch that makes suitable runtime from STM32F4 one
in directory `gnat_runtime`.
To build and run "black pill" examples please add required runtime to GNAT
by doing following steps:
- Go to Gnat runtime directory {gnat's prefix}/arm-eabi/lib/gnat
- Copy runtime: `cp -r light-stm32f4 light-stm32f401`
- Apply patch: `patch light-stm32f401 < {patch dir}/light-stm32f401.patch

View File

@ -0,0 +1,17 @@
with STM32.USARTs;
package Board.UART is
Port : GPIO_Registers renames GPIOA;
TX_Bit : constant Port_Bit_Number := 9;
RX_Bit : constant Port_Bit_Number := 10;
Port_RCC_EN : Boolean renames RCC.AHB1ENR (Index.GPIOA);
Port_RCC_RST : Boolean renames RCC.AHB1RSTR (Index.GPIOA);
AF : Alternate_Function renames Alternate_Functions.USART1;
Module : STM32.USARTs.USART_Registers renames STM32.USARTs.USART1;
RCC_EN : Boolean renames RCC.APB2ENR (Index.USART1);
RCC_RST : Boolean renames RCC.APB2RSTR (Index.USART1);
end Board.UART;

View File

@ -0,0 +1,13 @@
with STM32.GPIO, STM32.Reset_and_Clock;
use STM32.GPIO, STM32.Reset_and_Clock;
package Board is
LED_Port : GPIO_Registers renames GPIOC;
LED_Bit : constant Port_Bit_Number := 13;
LED_On : constant Boolean := False;
LED_RCC_EN : Boolean renames RCC.AHB1ENR (Index.GPIOC);
APB2_Frequency : constant := 84_000_000; -- Set by board support
end Board;

View File

@ -0,0 +1,3 @@
with STM32.F407;
package Chip renames STM32.F407;

View File

@ -0,0 +1,30 @@
# Here's a example project name
X = led_flasher
# Supported board list
BOARDS = 401c_blackpill
O = objects
help :
@echo "Usable targets"
@echo "flash example: $(BOARDS:%=flash_$X_%)"
@echo "build example: $(BOARDS:%=$O/%/$X)"
@echo "build all: all"
all : $(BOARDS:%=$O/%/$X)
.PHONY : help all
$(BOARDS:%=flash_$X_%) : flash_$X_% : $O/%/$X.bin
st-flash --reset write $< 0x8000000
$(BOARDS:%=$O/%/$X) : $O/%/$X : $X_%.gpr .FORCE
gprbuild $<
$(BOARDS:%=$O/%/$X.bin) : $O/%/$X.bin : $O/%/$X
arm-eabi-objcopy -O binary $< $@
.PHONY : $(BOARDS:%=flash_$X_%)
.PHONY : .FORCE

View File

@ -0,0 +1,31 @@
with Board; use Board;
with STM32.Reset_and_Clock; use STM32.Reset_and_Clock;
with STM32.GPIO.Ports;
use STM32.GPIO.Ports, STM32.GPIO;
procedure LED_Flasher is
package LED is new GPIO_Port_Boolean(LED_Port, LED_Bit);
procedure Dly (X : Positive) is
begin
for J in 1 .. X loop
LED_RCC_EN := True;
end loop;
end;
begin
LED_RCC_EN := True;
LED.Set_MODER (Output_Mode);
LED.Set_OTYPER (Push_Pull_Type);
LED.Set_OSPEEDR (Very_High_Speed);
LED.Set_PUPDR (No_Pull);
loop
LED.Set (LED_On);
Dly (1000000);
LED.Set (not LED_On);
Dly (3000000);
end loop;
end Led_Flasher;

View File

@ -0,0 +1,25 @@
with "../../library/gpr/light_stm32f4_library.gpr";
project LED_Flasher_401c_Blackpill is
for Languages use("Ada");
for Main use("led_flasher.adb");
for Object_Dir use "objects/401c_blackpill";
for Target use "arm-eabi";
for Runtime("Ada") use "light-stm32f401";
for Source_Dirs use(".", "../common/401c_blackpill");
package Compiler is
for Default_Switches("Ada") use ("-gnatwa.X", "-gnatQ", "-gnatn", "-O2");
end Compiler;
package Builder is
for Default_Switches("Ada") use ("-ggdb");
end Builder;
package IDE is
for Program_Host use "localhost:4242";
for Communication_Protocol use "remote";
for Connection_Tool use "st-util";
end IDE;
end LED_Flasher_401c_Blackpill;

View File

@ -0,0 +1,116 @@
diff -u -r light-stm32f4/gnat/s-bbbopa.ads light-stm32f401/gnat/s-bbbopa.ads
--- light-stm32f4/gnat/s-bbbopa.ads 2022-09-29 14:17:39.819434400 +0300
+++ light-stm32f401/gnat/s-bbbopa.ads 2024-03-12 17:11:52.584980267 +0300
@@ -42,16 +42,14 @@
-- Hardware clock --
--------------------
- Main_Clock_Frequency : constant := 168_000_000;
- -- Optimal frequency of the system clock. Note that the STM32F411 can go
- -- up to 200 MHz, but all other STM32F40x and STM32F41x MCUs can only do
- -- 168 MHz.
+ Main_Clock_Frequency : constant := 84_000_000;
+ -- The STM32F401 unlike others can go up to 84 MHz only.
- HSE_Clock_Frequency : constant := 8_000_000;
- -- Frequency of High Speed External clock.
+ HSE_Clock_Frequency : constant := 25_000_000;
+ -- Frequency of High Speed External clock (As in "black pill").
FLASH_Latency : constant := 5;
- PLLP_Value : constant := 2;
+ PLLP_Value : constant := 4;
PLLQ_Value : constant := 7;
end System.BB.Board_Parameters;
diff -u -r light-stm32f4/gnat/start-rom.S light-stm32f401/gnat/start-rom.S
--- light-stm32f4/gnat/start-rom.S 2022-09-29 14:17:39.819434400 +0300
+++ light-stm32f401/gnat/start-rom.S 2024-03-12 18:21:55.981719375 +0300
@@ -61,18 +61,6 @@
subs r1,r1,#1
bne 0b
1:
- /* Copy .ccmdata */
- movw r0,#:lower16:__ccmdata_start
- movt r0,#:upper16:__ccmdata_start
- movw r1,#:lower16:__ccmdata_words
- movw r2,#:lower16:__ccmdata_load
- movt r2,#:upper16:__ccmdata_load
- cbz r1,1f
-0: ldr r4,[r2],#4
- str r4,[r0],#4
- subs r1,r1,#1
- bne 0b
-1:
/* Clear .bss */
movw r0,#:lower16:__bss_start
movt r0,#:upper16:__bss_start
diff -u -r light-stm32f4/ld/common-RAM.ld light-stm32f401/ld/common-RAM.ld
--- light-stm32f4/ld/common-RAM.ld 2022-09-29 14:17:39.819434400 +0300
+++ light-stm32f401/ld/common-RAM.ld 2024-03-12 18:20:57.248385024 +0300
@@ -87,20 +87,6 @@
__data_end = .;
} > sram_da
- .ccmdata :
- {
- __ccmdata_start = .;
- *(.ccmdata .ccmdata.*)
-
- /* Ensure that the end of the data section is always word aligned.
- Initial values are stored in 4-bytes blocks so we must guarantee
- that these blocks do not fall out the section (otherwise they are
- truncated and the initial data for the last block are lost). */
-
- . = ALIGN(0x4);
- __ccmdata_end = .;
- } > ccm_da
-
.bss (NOLOAD): {
. = ALIGN(0x8);
__bss_start = .;
diff -u -r light-stm32f4/ld/common-ROM.ld light-stm32f401/ld/common-ROM.ld
--- light-stm32f4/ld/common-ROM.ld 2022-09-29 14:17:39.819434400 +0300
+++ light-stm32f401/ld/common-ROM.ld 2024-03-12 18:20:07.011717499 +0300
@@ -90,22 +90,6 @@
} > sram_da
__data_words = (__data_end - __data_start) >> 2;
- __ccmdata_load = __rom_end + (__data_words << 2);
- .ccmdata : AT (__ccmdata_load)
- {
- __ccmdata_start = .;
- *(.ccmdata .ccmdata.*)
-
- /* Ensure that the end of the data section is always word aligned.
- Initial values are stored in 4-bytes blocks so we must guarantee
- that these blocks do not fall out the section (otherwise they are
- truncated and the initial data for the last block are lost). */
-
- . = ALIGN(0x4);
- __ccmdata_end = .;
- } > ccm_da
- __ccmdata_words = (__ccmdata_end - __ccmdata_start) >> 2;
-
.bss (NOLOAD): {
. = ALIGN(0x8);
__bss_start = .;
diff -u -r light-stm32f4/ld/memory-map.ld light-stm32f401/ld/memory-map.ld
--- light-stm32f4/ld/memory-map.ld 2022-09-29 14:17:39.823434400 +0300
+++ light-stm32f401/ld/memory-map.ld 2024-03-12 18:28:51.885059907 +0300
@@ -36,13 +36,11 @@
MEMORY
{
- flash (rx) : ORIGIN = 0x08000000, LENGTH = 1024K
- sram12 (rwx) : ORIGIN = 0x20000000, LENGTH = 128K
- ccm (rw) : ORIGIN = 0x10000000, LENGTH = 64K
+ flash (rx) : ORIGIN = 0x08000000, LENGTH = 256K
+ sram12 (rwx) : ORIGIN = 0x20000000, LENGTH = 64K
}
REGION_ALIAS("sram_tx", sram12)
REGION_ALIAS("sram_ro", sram12)
REGION_ALIAS("sram_bs", sram12)
REGION_ALIAS("sram_da", sram12)
-REGION_ALIAS("ccm_da", ccm)