Skip to content

Commit 530c346

Browse files
authored
Add support for Arm Cortex-M3 (NUCLEO-F207ZG) (#39)
* add support for stm32f207 Signed-off-by: Thing-han, Lim <15379156+potsrevennil@users.noreply.github.com> * renmae stm32f207zg -> nucleo_f207zg Signed-off-by: Thing-han, Lim <15379156+potsrevennil@users.noreply.github.com> * build nucleo-f207zg in ci Signed-off-by: Thing-han, Lim <15379156+potsrevennil@users.noreply.github.com> --------- Signed-off-by: Thing-han, Lim <15379156+potsrevennil@users.noreply.github.com>
1 parent ff19445 commit 530c346

File tree

6 files changed

+82
-5
lines changed

6 files changed

+82
-5
lines changed

.github/workflows/build.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ jobs:
3737
3838
make_platform stm32f4discovery
3939
make_platform nucleo-f767zi
40+
make_platform nucleo-f207zg
4041
4142
- name: Build for emulation on QEMU
4243
shell: nix develop .#ci -c bash -e {0}

flake.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
perSystem = { pkgs, ... }:
2020
let
2121
libopencm3 = pkgs.callPackage ./libopencm3.nix {
22-
targets = [ "stm32/f4" "stm32/f7" ];
22+
targets = [ "stm32/f2" "stm32/f4" "stm32/f7" ];
2323
};
2424
core = builtins.attrValues {
2525
libopencm3 = libopencm3;
@@ -56,7 +56,7 @@
5656
shellHook = ''
5757
export OPENCM3_DIR=${libopencm3}
5858
export PATH=$PWD/scripts:$PWD/scripts/ci:$PATH
59-
eval "$(_TESTS_COMPLETE=source tests)"
59+
eval "$(_TESTS_COMPLETE=bash_source tests)"
6060
'';
6161
};
6262

hal/hal-opencm3.c

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,15 @@
1212
#include <libopencm3/stm32/usart.h>
1313
#include <libopencm3/stm32/flash.h>
1414

15-
#if defined(STM32F407VG)
15+
#if defined(STM32F207ZG)
16+
#include <libopencm3/stm32/rng.h>
17+
18+
#define SERIAL_GPIO GPIOD
19+
#define SERIAL_USART USART3
20+
#define SERIAL_PINS (GPIO8 | GPIO9)
21+
#define STM32
22+
#define NUCLEO_BOARD
23+
#elif defined(STM32F407VG)
1624
#include <libopencm3/stm32/rng.h>
1725
#define SERIAL_GPIO GPIOA
1826
#define SERIAL_USART USART2
@@ -91,13 +99,70 @@ static void clock_setup(enum clock_mode clock) {
9199
rcc_periph_clock_enable(RCC_RNG);
92100
flash_art_enable();
93101
flash_prefetch_enable();
102+
#elif defined(STM32F2)
103+
/* Some STM32 Platform */
104+
rcc_periph_clock_enable(RCC_RNG);
105+
rcc_periph_clock_enable(RCC_GPIOH);
106+
/* All of them use an external oscillator with bypass. */
107+
rcc_osc_off(RCC_HSE);
108+
rcc_osc_bypass_enable(RCC_HSE);
109+
rcc_osc_on(RCC_HSE);
110+
rcc_wait_for_osc_ready(RCC_HSE);
111+
# if defined(NUCLEO_BOARD)
112+
/* NUCLEO-STM32F2 Board */
113+
switch (clock) {
114+
case CLOCK_BENCHMARK:
115+
rcc_ahb_frequency = 30000000;
116+
rcc_apb1_frequency = 30000000;
117+
rcc_apb2_frequency = 30000000;
118+
_clock_freq = 30000000;
119+
rcc_set_hpre(RCC_CFGR_HPRE_DIV_4);
120+
rcc_set_ppre1(RCC_CFGR_PPRE_DIV_NONE);
121+
rcc_set_ppre2(RCC_CFGR_PPRE_DIV_NONE);
122+
rcc_osc_off(RCC_PLL);
123+
/* Configure the PLL oscillator (use CUBEMX tool). */
124+
rcc_set_main_pll_hse(8, 240, 2, 5);
125+
/* Enable PLL oscillator and wait for it to stabilize. */
126+
rcc_osc_on(RCC_PLL);
127+
rcc_wait_for_osc_ready(RCC_PLL);
128+
flash_dcache_enable();
129+
flash_icache_enable();
130+
flash_set_ws(FLASH_ACR_LATENCY_0WS);
131+
flash_prefetch_enable();
132+
break;
133+
case CLOCK_FAST:
134+
default:
135+
rcc_ahb_frequency = 120000000;
136+
rcc_apb1_frequency = 30000000;
137+
rcc_apb2_frequency = 60000000;
138+
_clock_freq = 120000000;
139+
rcc_set_hpre(RCC_CFGR_HPRE_DIV_NONE);
140+
rcc_set_ppre1(RCC_CFGR_PPRE_DIV_4);
141+
rcc_set_ppre2(RCC_CFGR_PPRE_DIV_2);
142+
rcc_osc_off(RCC_PLL);
143+
/* Configure the PLL oscillator (use CUBEMX tool). */
144+
rcc_set_main_pll_hse(8, 240, 2, 5);
145+
/* Enable PLL oscillator and wait for it to stabilize. */
146+
rcc_osc_on(RCC_PLL);
147+
rcc_wait_for_osc_ready(RCC_PLL);
148+
flash_dcache_enable();
149+
flash_icache_enable();
150+
flash_set_ws(FLASH_ACR_LATENCY_3WS);
151+
flash_prefetch_enable();
152+
break;
153+
}
154+
rcc_set_sysclk_source(RCC_CFGR_SW_PLL);
155+
rcc_wait_for_sysclk_status(RCC_PLL);
156+
# else
157+
# error Unsupported STM32F2 Board
158+
# endif
94159
#else
95160
#error Unsupported platform
96161
#endif
97162
}
98163

99164
void usart_setup() {
100-
#if defined(STM32F7)
165+
#if defined(STM32F207ZG) || defined(STM32F7)
101166
rcc_periph_clock_enable(RCC_GPIOD);
102167
rcc_periph_clock_enable(RCC_USART3);
103168
#elif defined(DISCOVERY_BOARD)

hal/stm32f4discovery.cfg renamed to hal/nucleo_f207zg.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ source [find interface/stlink-dap.cfg]
33

44
transport select dapdirect_swd
55

6-
source [find target/stm32f4x.cfg]
6+
source [find target/stm32f2x.cfg]
77

88
reset_config trst_only

mk/nucleo-f207zg.mk

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
DEVICE=stm32f207zg
3+
OPENCM3_TARGET=lib/stm32/f2
4+
5+
include mk/opencm3.mk

scripts/tests

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import click
1111
import logging
1212
import sys
1313
import re
14+
import os.path
1415
from enum import Enum
1516
from types import SimpleNamespace
1617
from functools import reduce
@@ -110,6 +111,7 @@ class PLATFORM(Enum):
110111
STM32F4DISCOVERY = 1
111112
MPS2_AN386 = 2
112113
NUCLEO_F767ZI = 3
114+
NUCLEO_F207ZG = 4
113115

114116
def __str__(self):
115117
return self.name.lower().replace("_", "-")
@@ -133,8 +135,12 @@ class RecursiveNamespace(SimpleNamespace):
133135
setattr(self, key, list(map(self.map_entry, val)))
134136

135137

138+
ROOT = os.path.dirname(os.path.dirname(__file__))
136139
platform_map = RecursiveNamespace(
137140
**{
141+
f"{PLATFORM.NUCLEO_F207ZG}": {
142+
"openocd_cfg": f"{ROOT}/hal/nucleo_f207zg.cfg",
143+
},
138144
f"{PLATFORM.STM32F4DISCOVERY}": {
139145
"openocd_cfg": "board/stm32f4discovery.cfg",
140146
},

0 commit comments

Comments
 (0)