Skip to content

Commit

Permalink
make firmware compile for stm32g4
Browse files Browse the repository at this point in the history
  • Loading branch information
bkleiner committed Jul 4, 2024
1 parent 8b7f065 commit 0af38d4
Show file tree
Hide file tree
Showing 39 changed files with 1,835 additions and 224 deletions.
2 changes: 1 addition & 1 deletion boards/STM32F405RG.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@
]
},
"url": "https://www.st.com/en/microcontrollers-microprocessors/stm32f405rg.html",
"vendor": "Generic"
"vendor": "ST"
}
2 changes: 1 addition & 1 deletion boards/STM32F411RE.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@
]
},
"url": "https://www.st.com/en/microcontrollers-microprocessors/stm32f411re.html",
"vendor": "Generic"
"vendor": "ST"
}
2 changes: 1 addition & 1 deletion boards/STM32F722RE.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@
]
},
"url": "https://www.st.com/en/microcontrollers-microprocessors/stm32f722re.html",
"vendor": "Generic"
"vendor": "ST"
}
2 changes: 1 addition & 1 deletion boards/STM32F745XG.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@
]
},
"url": "https://www.st.com/en/microcontrollers-microprocessors/stm32f745xg.html",
"vendor": "Generic"
"vendor": "ST"
}
2 changes: 1 addition & 1 deletion boards/STM32F765VI.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@
]
},
"url": "https://www.st.com/en/microcontrollers-microprocessors/stm32f765vi.html",
"vendor": "Generic"
"vendor": "ST"
}
37 changes: 37 additions & 0 deletions boards/STM32G473CE.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"build": {
"core": "stm32",
"cpu": "cortex-m4",
"extra_flags": "-DSTM32G473xx -DSTM32G473 -DSTM32G4xx -DSTM32G4 -DSTM32 -DMCU_NAME=stm32g473 -DHSE_VALUE=8000000U -DUSE_FAST_RAM -DUSB_PMASIZE=0x400",
"f_cpu": "170000000L",
"mcu": "stm32g473",
"product_line": "STM32G473xx",
"variant": "Generic_G473"
},
"debug": {
"jlink_device": "STM32G473CB",
"openocd_target": "stm32g4x",
"svd_path": "STM32G473xx.svd"
},
"frameworks": [
"arduino",
"cmsis",
"libopencm3",
"stm32cube"
],
"name": "STM32G473CE (128k RAM. 512k Flash)",
"upload": {
"maximum_ram_size": 131072,
"maximum_size": 524288,
"protocol": "stlink",
"protocols": [
"stlink",
"jlink",
"cmsis-dap",
"blackmagic",
"mbed"
]
},
"url": "https://www.st.com/en/microcontrollers-microprocessors/stm32g473ce.html",
"vendor": "ST"
}
2 changes: 1 addition & 1 deletion boards/STM32H743VI.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@
]
},
"url": "https://www.st.com/en/microcontrollers-microprocessors/stm32h743vi.html",
"vendor": "Generic"
"vendor": "ST"
}
20 changes: 19 additions & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ build_flags =

[stm32]
extends = common
platform = ststm32@~17.0.0
platform = ststm32@~17.3.0
build_src_filter = ${common.build_src_filter} +<driver/stm32>
framework = stm32cube
board_build.stm32cube.custom_system_setup = yes
Expand Down Expand Up @@ -133,6 +133,24 @@ build_flags =
[env:stm32h743]
extends = stm32h743

[stm32g4]
extends = stm32
system_flags =
-mfloat-abi=hard
-mfpu=fpv4-sp-d16

[stm32g473]
extends = stm32g4
board = STM32G473CE
build_src_filter = ${stm32.build_src_filter} +<system/stm32g473>
board_build.ldscript = $PROJECT_DIR/src/system/stm32g473/flash_layout.ld
build_flags =
${stm32g4.build_flags}
-Isrc/system/stm32g473

[env:stm32g473]
extends = stm32g473

[at32]
extends = common
platform = https://github.com/ArteryTek/platform-arterytekat32.git#5729d36
Expand Down
5 changes: 3 additions & 2 deletions script/device_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def parse_all(self):
)

# roughly filter to supported devices
supported = ["stm32f4", "stm32f7", "stm32h7"]
supported = ["stm32f4", "stm32g4", "stm32f7", "stm32h7"]
device_file_names = [
dfn for dfn in device_file_names if any(s in dfn for s in supported)
]
Expand Down Expand Up @@ -109,6 +109,7 @@ def __getitem__(self, item) -> modm_devices.device.Device:
devices = [
"stm32f405rg",
"stm32f411re",
"stm32g473ceu6",
"stm32f722re",
"stm32f745vg",
"stm32f765vi",
Expand Down Expand Up @@ -176,7 +177,7 @@ def __getitem__(self, item) -> modm_devices.device.Device:

pins[f"P{pin['port']}{pin['pin']}".upper()] = funcs

with open(f"src/system/{device[:-2]}/gpio_pins.yaml", "w") as file:
with open(f"src/system/{device[:9]}/gpio_pins.yaml", "w") as file:
documents = yaml.dump(pins, file, sort_keys=False)

for filename in glob.glob("src/system/*/gpio_pins.yaml"):
Expand Down
2 changes: 2 additions & 0 deletions src/core/target.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ typedef enum {
SERIAL_PORT4,
SERIAL_PORT5,
#endif
#ifndef STM32G4
SERIAL_PORT6,
#endif
#if defined(STM32F7) || defined(STM32H7) || defined(AT32F4)
SERIAL_PORT7,
SERIAL_PORT8,
Expand Down
2 changes: 1 addition & 1 deletion src/driver/adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ uint16_t adc_array[ADC_CHAN_MAX];
adc_channel_t adc_pins[ADC_CHAN_MAX];

extern uint16_t adc_read_raw(adc_chan_t index);
extern float adc_convert_to_temp(float val);
extern float adc_convert_to_temp(uint16_t val);

static float adc_convert_to_mv(float value) {
const float vref = (float)(VREFINT_CAL * VREFINT_CAL_VREF) / (float)adc_read_raw(ADC_CHAN_VREF);
Expand Down
6 changes: 5 additions & 1 deletion src/driver/adc.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ typedef enum {
ADC_DEVICE2,
ADC_DEVICE3,
#endif
ADC_DEVICEMAX,
#ifdef STM32G473
ADC_DEVICE4,
ADC_DEVICE5,
#endif
ADC_DEVICE_MAX,
} adc_devices_t;

typedef enum {
Expand Down
10 changes: 5 additions & 5 deletions src/driver/at32/adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
extern uint16_t adc_array[ADC_CHAN_MAX];
extern adc_channel_t adc_pins[ADC_CHAN_MAX];

static adc_type *adc_devs[ADC_DEVICEMAX] = {
static adc_type *adc_devs[ADC_DEVICE_MAX] = {
ADC1,
ADC2,
ADC3,
Expand All @@ -23,7 +23,7 @@ static adc_type *adc_devs[ADC_DEVICEMAX] = {
static void adc_init_pin(adc_chan_t chan, gpio_pins_t pin) {
adc_array[chan] = 1;
adc_pins[chan].pin = PIN_NONE;
adc_pins[chan].dev = ADC_DEVICEMAX;
adc_pins[chan].dev = ADC_DEVICE_MAX;

switch (chan) {
case ADC_CHAN_VREF:
Expand Down Expand Up @@ -70,7 +70,7 @@ static void adc_init_dev() {
common_init.vbat_state = FALSE;
adc_common_config(&common_init);

for (uint32_t i = 0; i < ADC_DEVICEMAX; i++) {
for (uint32_t i = 0; i < ADC_DEVICE_MAX; i++) {
adc_base_config_type base_init;
base_init.sequence_mode = FALSE;
base_init.repeat_mode = FALSE;
Expand Down Expand Up @@ -141,14 +141,14 @@ uint16_t adc_read_raw(adc_chan_t index) {
do {
last_adc_chan = (last_adc_chan + 1) % ADC_CHAN_MAX;
// skip through all channels without a dev
} while (adc_pins[last_adc_chan].dev == ADC_DEVICEMAX);
} while (adc_pins[last_adc_chan].dev == ADC_DEVICE_MAX);

adc_start_conversion(last_adc_chan);
}

return adc_array[index];
}

float adc_convert_to_temp(float val) {
float adc_convert_to_temp(uint16_t val) {
return (ADC_TEMP_BASE - val * ADC_VREF / 4096) / ADC_TEMP_SLOPE + 25;
}
5 changes: 4 additions & 1 deletion src/driver/fmc.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

#include "util/util.h"

#if defined(STM32H7)
#if defined(STM32G4)
#define FLASH_WORD_SIZE 8
typedef uint64_t flash_word_t;
#elif defined(STM32H7)
#define FLASH_WORD_SIZE 32
typedef uint64_t flash_word_t;
#else
Expand Down
Loading

0 comments on commit 0af38d4

Please sign in to comment.