Skip to content

Commit a42316d

Browse files
committed
stm32h7_m4: create a generic variant
This allows having all the generic code in a single place, including the needed clock configuration override
1 parent fee275d commit a42316d

25 files changed

+1627
-330
lines changed

boards.txt

+8-8
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ envie_m7.menu.target_core.cm7.build.fpu=-mfpu=fpv5-d16
7474
envie_m7.menu.target_core.cm7.build.architecture=cortex-m7
7575
envie_m7.menu.target_core.cm7.compiler.mbed.arch.define=
7676

77-
envie_m7.menu.target_core.cm4.build.variant=PORTENTA_H7_M4
77+
envie_m7.menu.target_core.cm4.build.variant=GENERIC_STM32H747_M4
7878
envie_m7.menu.target_core.cm4.build.mcu=cortex-m4
7979
envie_m7.menu.target_core.cm4.build.fpu=-mfpu=fpv4-sp-d16
8080
envie_m7.menu.target_core.cm4.build.architecture=cortex-m4
@@ -99,7 +99,7 @@ envie_m7.compiler.mbed.defines={build.variant.path}/defines.txt
9999
envie_m7.compiler.mbed.ldflags={build.variant.path}/ldflags.txt
100100
envie_m7.compiler.mbed.cflags={build.variant.path}/cflags.txt
101101
envie_m7.compiler.mbed.cxxflags={build.variant.path}/cxxflags.txt
102-
envie_m7.compiler.mbed.includes={build.variant.path}/includes.txt
102+
envie_m7.compiler.mbed.includes={build.variant.path}/../PORTENTA_H7_M7/includes.txt
103103
envie_m7.compiler.mbed.extra_ldflags=-lstdc++ -lsupc++ -lm -lc -lgcc -lnosys
104104
envie_m7.compiler.mbed="{build.variant.path}/libs/libmbed.a"
105105
envie_m7.vid.0=0x2341
@@ -492,7 +492,7 @@ nicla_vision.menu.target_core.cm7.build.fpu=-mfpu=fpv5-d16
492492
nicla_vision.menu.target_core.cm7.build.architecture=cortex-m7
493493
nicla_vision.menu.target_core.cm7.compiler.mbed.arch.define=
494494

495-
nicla_vision.menu.target_core.cm4.build.variant=PORTENTA_H7_M4
495+
nicla_vision.menu.target_core.cm4.build.variant=GENERIC_STM32H747_M4
496496
nicla_vision.menu.target_core.cm4.build.mcu=cortex-m4
497497
nicla_vision.menu.target_core.cm4.build.fpu=-mfpu=fpv4-sp-d16
498498
nicla_vision.menu.target_core.cm4.build.architecture=cortex-m4
@@ -510,7 +510,7 @@ nicla_vision.compiler.mbed.defines={build.variant.path}/defines.txt
510510
nicla_vision.compiler.mbed.ldflags={build.variant.path}/ldflags.txt
511511
nicla_vision.compiler.mbed.cflags={build.variant.path}/cflags.txt
512512
nicla_vision.compiler.mbed.cxxflags={build.variant.path}/cxxflags.txt
513-
nicla_vision.compiler.mbed.includes={build.variant.path}/includes.txt
513+
nicla_vision.compiler.mbed.includes={build.variant.path}/../NICLA_VISION/includes.txt
514514
nicla_vision.compiler.mbed.extra_ldflags=-lstdc++ -lsupc++ -lm -lc -lgcc -lnosys
515515
nicla_vision.compiler.mbed="{build.variant.path}/libs/libmbed.a"
516516
nicla_vision.vid.0=0x2341
@@ -590,7 +590,7 @@ opta.menu.target_core.cm7.build.fpu=-mfpu=fpv5-d16
590590
opta.menu.target_core.cm7.build.architecture=cortex-m7
591591
opta.menu.target_core.cm7.compiler.mbed.arch.define=
592592

593-
opta.menu.target_core.cm4.build.variant=PORTENTA_H7_M4
593+
opta.menu.target_core.cm4.build.variant=GENERIC_STM32H747_M4
594594
opta.menu.target_core.cm4.build.mcu=cortex-m4
595595
opta.menu.target_core.cm4.build.fpu=-mfpu=fpv4-sp-d16
596596
opta.menu.target_core.cm4.build.architecture=cortex-m4
@@ -617,7 +617,7 @@ opta.compiler.mbed.defines={build.variant.path}/defines.txt
617617
opta.compiler.mbed.ldflags={build.variant.path}/ldflags.txt
618618
opta.compiler.mbed.cflags={build.variant.path}/cflags.txt
619619
opta.compiler.mbed.cxxflags={build.variant.path}/cxxflags.txt
620-
opta.compiler.mbed.includes={build.variant.path}/includes.txt
620+
opta.compiler.mbed.includes={build.variant.path}/../OPTA/includes.txt
621621
opta.compiler.mbed.extra_ldflags=-lstdc++ -lsupc++ -lm -lc -lgcc -lnosys
622622
opta.compiler.mbed="{build.variant.path}/libs/libmbed.a"
623623
opta.vid.0=0x2341
@@ -716,7 +716,7 @@ giga.menu.target_core.cm7.build.fpu=-mfpu=fpv5-d16
716716
giga.menu.target_core.cm7.build.architecture=cortex-m7
717717
giga.menu.target_core.cm7.compiler.mbed.arch.define=
718718

719-
giga.menu.target_core.cm4.build.variant=PORTENTA_H7_M4
719+
giga.menu.target_core.cm4.build.variant=GENERIC_STM32H747_M4
720720
giga.menu.target_core.cm4.build.mcu=cortex-m4
721721
giga.menu.target_core.cm4.build.fpu=-mfpu=fpv4-sp-d16
722722
giga.menu.target_core.cm4.build.architecture=cortex-m4
@@ -739,7 +739,7 @@ giga.compiler.mbed.defines={build.variant.path}/defines.txt
739739
giga.compiler.mbed.ldflags={build.variant.path}/ldflags.txt
740740
giga.compiler.mbed.cflags={build.variant.path}/cflags.txt
741741
giga.compiler.mbed.cxxflags={build.variant.path}/cxxflags.txt
742-
giga.compiler.mbed.includes={build.variant.path}/includes.txt
742+
giga.compiler.mbed.includes={build.variant.path}/../GIGA/includes.txt
743743
giga.compiler.mbed.extra_ldflags=-lstdc++ -lsupc++ -lm -lc -lgcc -lnosys
744744
giga.compiler.mbed="{build.variant.path}/libs/libmbed.a"
745745
giga.vid.0=0x2341

giga.variables

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export FLAVOUR="giga"
2-
export VARIANTS=("GIGA PORTENTA_H7_M4")
2+
export VARIANTS=("GIGA GENERIC_STM32H747_M4")
33
export FQBNS=("giga")
44
export LIBRARIES=("MRI Portenta_SDRAM SPI WiFi ea_malloc openamp_arduino STM32H747_System ThreadDebug Himax_HM01B0 PDM Arduino_H7_Video USBAudio KernelDebug Portenta_Audio RPC USBHID Wire Portenta_lvgl Camera rpclib OV7670 mbed-memory-status Scheduler USBMSD USBMIDI SocketWrapper MCUboot Arduino_CAN")
55
export BOOTLOADERS=("GIGA")

libraries/Arduino_CAN/src/Arduino_CAN.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* COMPILE TIME CHECKS
2525
**************************************************************************************/
2626

27-
#if !(defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_GIGA))
27+
#if !(defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_GIGA))
2828
# error "CAN only available on Arduino Portenta H7 and Arduino Giga (of all ArduinoCore-mbed enabled boards)."
2929
#endif
3030

libraries/Camera/src/camera.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#define ALIGN_PTR(p,a) ((p & (a-1)) ?(((uintptr_t)p + a) & ~(uintptr_t)(a-1)) : p)
2929

3030
// Include all image sensor drivers here.
31-
#if defined (ARDUINO_PORTENTA_H7_M7) || defined (ARDUINO_PORTENTA_H7_M4)
31+
#if defined (ARDUINO_PORTENTA_H7_M7)
3232

3333
#define DCMI_TIM (TIM1)
3434
#define DCMI_TIM_PIN (GPIO_PIN_1)
@@ -80,7 +80,7 @@ arduino::MbedI2C CameraWire(I2C_SDA1, I2C_SCL1);
8080

8181
// DCMI GPIO pins struct
8282
static const struct { GPIO_TypeDef *port; uint16_t pin; } dcmi_pins[] = {
83-
#if defined (ARDUINO_PORTENTA_H7_M7) || defined (ARDUINO_PORTENTA_H7_M4)
83+
#if defined (ARDUINO_PORTENTA_H7_M7)
8484
{GPIOA, GPIO_PIN_4 },
8585
{GPIOA, GPIO_PIN_6 },
8686
{GPIOI, GPIO_PIN_4 },
@@ -175,7 +175,7 @@ void HAL_DCMI_MspInit(DCMI_HandleTypeDef *hdcmi)
175175
hgpio.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
176176
hgpio.Alternate = GPIO_AF13_DCMI;
177177

178-
#if defined (ARDUINO_PORTENTA_H7_M7) || defined (ARDUINO_PORTENTA_H7_M4)
178+
#if defined (ARDUINO_PORTENTA_H7_M7)
179179
/* Enable GPIO clocks */
180180
__HAL_RCC_GPIOA_CLK_ENABLE();
181181
__HAL_RCC_GPIOH_CLK_ENABLE();

libraries/SocketWrapper/src/utility/wl_definitions.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ enum wl_enc_type { /* Values map to 802.11 encryption suites... */
7070
ENC_TYPE_AUTO = 8
7171
};
7272

73-
#if defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4)
73+
#if defined(ARDUINO_PORTENTA_H7_M7)
7474
#include "whd_version.h"
7575
#define WIFI_FIRMWARE_LATEST_VERSION WHD_VERSION
7676
#endif
7777

78-
#endif /* WL_DEFINITIONS_H_ */
78+
#endif /* WL_DEFINITIONS_H_ */

libraries/WiFi/src/utility/wl_definitions.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ enum wl_enc_type { /* Values map to 802.11 encryption suites... */
7070
ENC_TYPE_AUTO = 8
7171
};
7272

73-
#if defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4)
73+
#if defined(ARDUINO_PORTENTA_H7_M7)
7474
#include "whd_version.h"
7575
#define WIFI_FIRMWARE_LATEST_VERSION WHD_VERSION
7676
#endif
7777

78-
#endif /* WL_DEFINITIONS_H_ */
78+
#endif /* WL_DEFINITIONS_H_ */

mbed-os-to-arduino

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ generate_flags () {
183183
for fl in c cxx ld; do
184184
jq -r '.flags | .[] | select(. != "-MMD")' ./BUILD/"$BOARDNAME"/GCC_ARM${PROFILE}/.profile-${fl} \
185185
> "$ARDUINOVARIANT"/${fl}flags.txt
186-
if [[ $ARDUINOVARIANT == *PORTENTA* || $ARDUINOVARIANT == *GIGA* || $ARDUINOVARIANT == *NICLA_VISION* || $ARDUINOVARIANT == *OPTA* ]]; then
186+
if [[ $ARDUINOVARIANT == *PORTENTA* || $ARDUINOVARIANT == *GIGA* || $ARDUINOVARIANT == *NICLA_VISION* || $ARDUINOVARIANT == *OPTA* || $ARDUINOVARIANT == *GENERIC*M4 ]]; then
187187
echo "Patching '-fno-exceptions' flag for $ARDUINOVARIANT/${fl}flags.txt"
188188
sed -i '/-fno-exceptions/d' "$ARDUINOVARIANT"/${fl}flags.txt
189189
set +e

nicla.variables

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export FLAVOUR="nicla"
2-
export VARIANTS=("NICLA NICLA_VISION PORTENTA_H7_M4")
2+
export VARIANTS=("NICLA NICLA_VISION GENERIC_STM32H747_M4")
33
export FQBNS=("nicla_sense nicla_voice nicla_vision")
44
export LIBRARIES=("SPI Wire Scheduler Nicla_System WiFi ea_malloc openamp_arduino STM32H747_System ThreadDebug GC2145 Himax_HM01B0 PDM KernelDebug RPC USBHID Camera rpclib USBHOST mbed-memory-status USBMSD SocketWrapper MRI SE05X MLC NDP syntiant_ilib")
55
export BOOTLOADERS=("NICLA NICLA_VISION NICLA_VOICE")

opta.variables

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export FLAVOUR="opta"
2-
export VARIANTS=("OPTA PORTENTA_H7_M4")
2+
export VARIANTS=("OPTA GENERIC_STM32H747_M4")
33
export FQBNS=("opta")
44
export LIBRARIES=("Ethernet SPI WiFi openamp_arduino ThreadDebug KernelDebug RPC USBHID Wire rpclib USBHOST mbed-memory-status Scheduler USBMSD SocketWrapper STM32H747_System MRI")
55
export BOOTLOADERS=("OPTA")

portenta.variables

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export FLAVOUR="portenta"
2-
export VARIANTS=("PORTENTA_H7_M7 PORTENTA_H7_M4 PORTENTA_X8")
2+
export VARIANTS=("PORTENTA_H7_M7 GENERIC_STM32H747_M4 PORTENTA_X8")
33
export FQBNS=("envie_m7 portenta_x8")
44
export LIBRARIES=("doom Ethernet MRI Portenta_SDRAM SPI WiFi ea_malloc openamp_arduino STM32H747_System ThreadDebug Himax_HM01B0 Himax_HM0360 PDM Arduino_H7_Video USBAudio KernelDebug Portenta_Audio RPC USBHID Wire Portenta_lvgl Camera rpclib USBHOST mbed-memory-status Portenta_SDCARD Scheduler USBMSD USBMIDI SocketWrapper GSM GPS MCUboot Arduino_CAN")
55
export BOOTLOADERS=("PORTENTA_H7")

variants/PORTENTA_H7_M4/cflags.txt renamed to variants/GENERIC_STM32H747_M4/cflags.txt

-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
-c
22
-std=gnu11
33
-DAPPLICATION_ADDR=0x8100000
4-
-DAPPLICATION_RAM_ADDR=0x10000000
5-
-DAPPLICATION_RAM_SIZE=0x48000
64
-DAPPLICATION_SIZE=0x100000
7-
-DMBED_RAM1_SIZE=0x80000
8-
-DMBED_RAM1_START=0x24000000
95
-DMBED_RAM_SIZE=0x48000
106
-DMBED_RAM_START=0x10000000
117
-DMBED_ROM_SIZE=0x100000
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#include "Arduino.h"
2+
3+
#if defined(ARDUINO_GIGA)
4+
#undef HSE_VALUE
5+
#define HSE_VALUE 16000000
6+
#endif
7+
8+
extern "C" uint32_t HAL_RCC_GetSysClockFreq(void)
9+
{
10+
uint32_t pllp, pllsource, pllm, pllfracen, hsivalue;
11+
float_t fracn1, pllvco;
12+
uint32_t sysclockfreq;
13+
14+
/* Get SYSCLK source -------------------------------------------------------*/
15+
16+
switch (RCC->CFGR & RCC_CFGR_SWS)
17+
{
18+
case RCC_CFGR_SWS_HSI: /* HSI used as system clock source */
19+
20+
if (__HAL_RCC_GET_FLAG(RCC_FLAG_HSIDIV) != 0U)
21+
{
22+
sysclockfreq = (uint32_t) (HSI_VALUE >> (__HAL_RCC_GET_HSI_DIVIDER()>> 3));
23+
}
24+
else
25+
{
26+
sysclockfreq = (uint32_t) HSI_VALUE;
27+
}
28+
29+
break;
30+
31+
case RCC_CFGR_SWS_CSI: /* CSI used as system clock source */
32+
sysclockfreq = CSI_VALUE;
33+
break;
34+
35+
case RCC_CFGR_SWS_HSE: /* HSE used as system clock source */
36+
sysclockfreq = HSE_VALUE;
37+
break;
38+
39+
case RCC_CFGR_SWS_PLL1: /* PLL1 used as system clock source */
40+
41+
/* PLL_VCO = (HSE_VALUE or HSI_VALUE or CSI_VALUE/ PLLM) * PLLN
42+
SYSCLK = PLL_VCO / PLLR
43+
*/
44+
pllsource = (RCC->PLLCKSELR & RCC_PLLCKSELR_PLLSRC);
45+
pllm = ((RCC->PLLCKSELR & RCC_PLLCKSELR_DIVM1)>> 4) ;
46+
pllfracen = ((RCC-> PLLCFGR & RCC_PLLCFGR_PLL1FRACEN)>>RCC_PLLCFGR_PLL1FRACEN_Pos);
47+
fracn1 = (float_t)(uint32_t)(pllfracen* ((RCC->PLL1FRACR & RCC_PLL1FRACR_FRACN1)>> 3));
48+
49+
if (pllm != 0U)
50+
{
51+
switch (pllsource)
52+
{
53+
case RCC_PLLSOURCE_HSI: /* HSI used as PLL clock source */
54+
55+
if (__HAL_RCC_GET_FLAG(RCC_FLAG_HSIDIV) != 0U)
56+
{
57+
hsivalue= (HSI_VALUE >> (__HAL_RCC_GET_HSI_DIVIDER()>> 3));
58+
pllvco = ( (float_t)hsivalue / (float_t)pllm) * ((float_t)(uint32_t)(RCC->PLL1DIVR & RCC_PLL1DIVR_N1) + (fracn1/(float_t)0x2000) +(float_t)1 );
59+
}
60+
else
61+
{
62+
pllvco = ((float_t)HSI_VALUE / (float_t)pllm) * ((float_t)(uint32_t)(RCC->PLL1DIVR & RCC_PLL1DIVR_N1) + (fracn1/(float_t)0x2000) +(float_t)1 );
63+
}
64+
break;
65+
66+
case RCC_PLLSOURCE_CSI: /* CSI used as PLL clock source */
67+
pllvco = ((float_t)CSI_VALUE / (float_t)pllm) * ((float_t)(uint32_t)(RCC->PLL1DIVR & RCC_PLL1DIVR_N1) + (fracn1/(float_t)0x2000) +(float_t)1 );
68+
break;
69+
70+
case RCC_PLLSOURCE_HSE: /* HSE used as PLL clock source */
71+
pllvco = ((float_t)HSE_VALUE / (float_t)pllm) * ((float_t)(uint32_t)(RCC->PLL1DIVR & RCC_PLL1DIVR_N1) + (fracn1/(float_t)0x2000) +(float_t)1 );
72+
break;
73+
74+
default:
75+
pllvco = ((float_t)CSI_VALUE / (float_t)pllm) * ((float_t)(uint32_t)(RCC->PLL1DIVR & RCC_PLL1DIVR_N1) + (fracn1/(float_t)0x2000) +(float_t)1 );
76+
break;
77+
}
78+
pllp = (((RCC->PLL1DIVR & RCC_PLL1DIVR_P1) >>9) + 1U ) ;
79+
sysclockfreq = (uint32_t)(float_t)(pllvco/(float_t)pllp);
80+
}
81+
else
82+
{
83+
sysclockfreq = 0U;
84+
}
85+
break;
86+
87+
default:
88+
sysclockfreq = CSI_VALUE;
89+
break;
90+
}
91+
92+
return sysclockfreq;
93+
}

variants/PORTENTA_H7_M4/cxxflags.txt renamed to variants/GENERIC_STM32H747_M4/cxxflags.txt

-4
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@
33
-fno-rtti
44
-std=gnu++14
55
-DAPPLICATION_ADDR=0x8100000
6-
-DAPPLICATION_RAM_ADDR=0x10000000
7-
-DAPPLICATION_RAM_SIZE=0x48000
86
-DAPPLICATION_SIZE=0x100000
9-
-DMBED_RAM1_SIZE=0x80000
10-
-DMBED_RAM1_START=0x24000000
117
-DMBED_RAM_SIZE=0x48000
128
-DMBED_RAM_START=0x10000000
139
-DMBED_ROM_SIZE=0x100000

variants/PORTENTA_H7_M4/defines.txt renamed to variants/GENERIC_STM32H747_M4/defines.txt

+4-5
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
-DFEATURE_BLE=1
4343
-D__FPU_PRESENT=1
4444
-D__MBED__=1
45-
-DMBED_BUILD_TIMESTAMP=1690447099.1347957
45+
-DMBED_BUILD_TIMESTAMP=1698330953.225854
4646
-D__MBED_CMSIS_RTOS_CM
4747
-DMBED_MPU_CUSTOM
4848
-DMBED_TICKLESS
@@ -52,21 +52,20 @@
5252
-DMETAL_MAX_DEVICE_REGIONS=2
5353
-DNO_ATOMIC_64_SUPPORT
5454
-DNO_VTOR_RELOCATE
55-
-DQSPI_NO_SAMPLE_SHIFT
5655
-DRPMSG_BUFFER_SIZE=2048
5756
-DSTM32H747xx
5857
-DTARGET_CORDIO
5958
-DTARGET_CORTEX
6059
-DTARGET_CORTEX_M
60+
-DTARGET_GENERIC_STM32H747_M4
6161
-DTARGET_LIKE_CORTEX_M4
6262
-DTARGET_LIKE_MBED
6363
-DTARGET_M4
6464
-DTARGET_MCU_STM32
6565
-DTARGET_MCU_STM32H7
6666
-DTARGET_MCU_STM32H747xI
67-
-DTARGET_NAME=PORTENTA_H7_M4
68-
-DTARGET_PORTENTA_H7
69-
-DTARGET_PORTENTA_H7_M4
67+
-DTARGET_MCU_STM32H747xI_CM4
68+
-DTARGET_NAME=GENERIC_STM32H747_M4
7069
-DTARGET_RELEASE
7170
-DTARGET_RTOS_M4_M7
7271
-DTARGET_STM

0 commit comments

Comments
 (0)