Skip to content
Open
4 changes: 2 additions & 2 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ extends = stm32g473

[at32]
extends = common
debug_tool = stlink
debug_tool = atlink
upload_protocol = dfu
platform = https://github.com/ArteryTek/platform-arterytekat32.git#5729d36
platform = https://github.com/ArteryTek/platform-arterytekat32.git#c8da386
platform_packages = toolchain-gccarmnoneeabi@~1.120301.0
framework = at32firmlib
board_build.at32firmlib.custom_system_setup = yes
Expand Down
207 changes: 112 additions & 95 deletions script/device_gen.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import glob
import hashlib
import yaml
import os
import re

import modm_devices

Expand Down Expand Up @@ -106,6 +105,66 @@ def __getitem__(self, item) -> modm_devices.device.Device:
return value


def map_signal(s):
if s is None:
return None

if s["driver"] == "tim" and s["name"].startswith("ch"):
return {
"func": "timer",
"af": int(s.get("af", "-1")),
"instance": int(s["instance"]),
"name": s["name"],
}
elif s["driver"] == "spi" and (
s["name"] == "sck"
or s["name"] == "mosi"
or s["name"] == "miso"
or s["name"] == "tx"
or s["name"] == "rx"
):
return {
"func": "spi",
"af": int(s.get("af", "-1")),
"instance": int(s["instance"]),
"name": {"tx": "mosi", "rx": "miso"}.get(s["name"], s["name"]),
}
elif (s["driver"] == "uart" or s["driver"] == "usart") and (
s["name"] == "rx" or s["name"] == "tx"
):
return {
"func": "serial",
"af": int(s.get("af", "-1")),
"instance": int(s["instance"]),
"name": s["name"],
}
elif s["driver"] == "adc" and re.match(r"in\d+", s.get("name", "in0")):
return {
"func": "adc",
"af": -1,
"instance": int(s["instance"]),
"name": s.get("name", "in0xff")[2:],
}
else:
return None


def map_tag(f):
if f is None:
return None

if f["func"] == "timer":
return f"TIMER_TAG(TIMER{f['instance']}, TIMER_{f['name']})".upper()
elif f["func"] == "spi":
return f"SPI_TAG(SPI_PORT{f['instance']}, RES_SPI_{f['name']})".upper()
elif f["func"] == "serial":
return f"SERIAL_TAG(SERIAL_PORT{f['instance']}, RES_SERIAL_{f['name']})".upper()
elif f["func"] == "adc":
return f"ADC_TAG(ADC_DEVICE{f['instance']}, {f['name']})".upper()
else:
return None


devices = [
"stm32f405rg",
"stm32f411re",
Expand All @@ -123,100 +182,58 @@ def __getitem__(self, item) -> modm_devices.device.Device:
pins = {}
key = next((x for x in caches.keys() if x.startswith(device)), None)

for driver in caches[key].get_all_drivers("gpio"):
for pin in driver["gpio"]:
funcs = []
with open(f"src/system/{device[:9]}/gpio_pins.in", "w") as file:
for driver in caches[key].get_all_drivers("gpio"):
for pin in driver["gpio"]:
file.write(f"GPIO_PIN({pin['port']}, {pin['pin']})\n".upper())
if "signal" not in pin:
continue

if "signal" in pin:
for s in pin["signal"]:
if s["driver"] == "tim" and s["name"].startswith("ch"):
funcs.append(
{
"func": "timer",
"af": int(s["af"]),
"instance": int(s["instance"]),
"name": s["name"],
}
)

if s["driver"] == "spi" and (
s["name"] == "sck" or s["name"] == "mosi" or s["name"] == "miso"
):
funcs.append(
{
"func": "spi",
"af": int(s["af"]),
"instance": int(s["instance"]),
"name": s["name"],
}
)

if (s["driver"] == "uart" or s["driver"] == "usart") and (
s["name"] == "rx" or s["name"] == "tx"
):
funcs.append(
{
"func": "serial",
"af": int(s["af"]),
"instance": int(s["instance"]),
"name": s["name"],
}
)

if s["driver"] == "adc" and not (
s["name"].startswith("inp") or s["name"].startswith("inn")
):
funcs.append(
{
"func": "adc",
"af": -1,
"instance": int(s["instance"]),
"name": s["name"][2:],
}
)

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

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"):
dir = os.path.dirname(filename)

with open(filename, "r") as f:
pins = yaml.load(f, Loader=yaml.Loader)

with open(f"{dir}/gpio_pins.in", "w") as file:
for k, funcs in pins.items():
port = k[1]
pin = k[2:]
file.write(f"GPIO_PIN({port}, {pin})\n")

for f in funcs:
line = f"GPIO_AF(PIN_{port}{pin}, {f['af']}, "

if f["func"] == "timer":
line = (
line
+ f"TIMER_TAG(TIMER{f['instance']}, TIMER_{f['name'].upper()}))\n"
)

if f["func"] == "spi":
line = (
line
+ f"SPI_TAG(SPI_PORT{f['instance']}, RES_SPI_{f['name'].upper()}))\n"
)

if f["func"] == "serial":
line = (
line
+ f"SERIAL_TAG(SERIAL_PORT{f['instance']}, RES_SERIAL_{f['name'].upper()}))\n"
)

if f["func"] == "adc":
line = (
line
+ f"ADC_TAG(ADC_DEVICE{f['instance']}, {f['name'].upper()}))\n"
f = map_signal(s)
s = map_tag(f)
if s is None:
continue
file.write(
f"GPIO_AF(PIN_{pin['port']}{pin['pin']}, {f['af']}, {s})\n".upper()
)

file.write(line)
with open(f"src/system/{device[:9]}/dma.in", "w") as file:
for driver in caches[key].get_all_drivers("dma"):
if "streams" in driver:
for dma in driver["streams"]:
for stream in dma["stream"]:
for channel in stream["channel"]:
funcs = [
r
for s in channel["signal"]
if (r := map_tag(map_signal(s))) is not None
]
for func in funcs:
entry = ", ".join(
[
f".tag = {func}",
f".port_index = {dma['instance']}",
f".stream_index = {stream['position']}",
f".channel = LL_DMA_CHANNEL_{channel['position']}",
]
)
file.write("{ " + entry + " },\n")
if "requests" in driver:
for dma in driver["requests"]:
for request in dma["request"]:
funcs = [
r
for s in request["signal"]
if (r := map_tag(map_signal(s))) is not None
]
for func in funcs:
entry = ", ".join(
[
f".tag = {func}",
f".port_index = -1",
f".stream_index = -1",
f".request = {request['position']}",
]
)
file.write("{ " + entry + " },\n")
3 changes: 1 addition & 2 deletions src/config/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,7 @@
// at eliminating propwash. Motor noise related to rpm is known to have a quadratic relationship with increasing throttle. While a quadratic curve
// could have been selected for this feature, a faster moving parabolic one was selected in its place as the goal is not to follow motor noise, but
// to get the filter out of the way as fast as possible in the interest of better performance and handling through reduced D filter latency when you need it most.
#define DTERM_DYNAMIC_LPF
#define DTERM_DYNAMIC_EXPO 1.0f
#define DTERM_DYNAMIC_TYPE FILTER_LP_PT1
#define DTERM_DYNAMIC_FREQ_MIN 70
#define DTERM_DYNAMIC_FREQ_MAX 260

Expand Down
1 change: 1 addition & 0 deletions src/config/feature.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#define USE_VTX
#define USE_DIGITAL_VTX
#define USE_MAX7456
#define USE_RGB_LED

#define USE_MOTOR_DSHOT
#define USE_MOTOR_PWM
Expand Down
4 changes: 2 additions & 2 deletions src/core/failloop.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ typedef enum {
FAILLOOP_GYRO = 4, // gyro not found
FAILLOOP_FAULT = 5, // clock, intterrupts, systick, gcc bad code, bad memory access (code issues like bad pointers) - this should not come up
FAILLOOP_LOOPTIME = 6, // loop time issue - if loop time exceeds 20mS
FAILLOOP_DMA = 7, // dma error - triggered by dma pool
FAILLOOP_SPI = 8, // spi error - triggered by hardware spi driver only
FAILLOOP_DMA = 7, // dma error
FAILLOOP_SPI = 8, // spi error
} __attribute__((__packed__)) failloop_t;

void failloop(failloop_t val);
9 changes: 3 additions & 6 deletions src/core/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ __attribute__((__used__)) int main() {
motor_set_all(MOTOR_OFF);

// wait for devices to wake up
time_delay_ms(300);
time_delay_ms(100);
osd_init();
rx_spektrum_bind();

Expand All @@ -113,20 +113,17 @@ __attribute__((__used__)) int main() {
sixaxis_init();

// give the gyro some time to settle
time_delay_ms(100);
time_delay_ms(50);

// display bootlogo while calibrating
sixaxis_gyro_cal();

// wait for adc and vtx to wake up
time_delay_ms(100);

adc_init();
vbat_init();

rx_init();
vtx_init();
rgb_init();
rgb_led_init();

blackbox_init();
imu_init();
Expand Down
11 changes: 2 additions & 9 deletions src/core/profile.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,17 +203,10 @@ const profile_t default_profile = {
},
},

#ifdef DTERM_DYNAMIC_LPF
.dterm_dynamic_enable = 1,
#else
.dterm_dynamic_enable = 0,
#endif
#ifdef DTERM_DYNAMIC_FREQ_MIN
.dterm_dynamic_type = DTERM_DYNAMIC_TYPE,
.dterm_dynamic_min = DTERM_DYNAMIC_FREQ_MIN,
#endif
#ifdef DTERM_DYNAMIC_FREQ_MAX
.dterm_dynamic_max = DTERM_DYNAMIC_FREQ_MAX,
#endif

#ifdef GYRO_DYNAMIC_NOTCH
.gyro_dynamic_notch_enable = 1,
#else
Expand Down
6 changes: 3 additions & 3 deletions src/core/profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#define OSD_NUMBER_ELEMENTS 32

#define PROFILE_VERSION MAKE_SEMVER(0, 2, 5)
#define PROFILE_VERSION MAKE_SEMVER(0, 2, 6)

// Rates
typedef enum {
Expand Down Expand Up @@ -327,7 +327,7 @@ typedef struct {
typedef struct {
profile_filter_parameter_t gyro[FILTER_MAX_SLOTS];
profile_filter_parameter_t dterm[FILTER_MAX_SLOTS];
uint8_t dterm_dynamic_enable;
filter_type_t dterm_dynamic_type;
float dterm_dynamic_min;
float dterm_dynamic_max;
uint8_t gyro_dynamic_notch_enable;
Expand All @@ -337,7 +337,7 @@ typedef struct {
START_STRUCT(profile_filter_t) \
ARRAY_MEMBER(gyro, FILTER_MAX_SLOTS, profile_filter_parameter_t) \
ARRAY_MEMBER(dterm, FILTER_MAX_SLOTS, profile_filter_parameter_t) \
MEMBER(dterm_dynamic_enable, uint8_t) \
MEMBER(dterm_dynamic_type, uint8_t) \
MEMBER(dterm_dynamic_min, float) \
MEMBER(dterm_dynamic_max, float) \
MEMBER(gyro_dynamic_notch_enable, uint8_t) \
Expand Down
2 changes: 2 additions & 0 deletions src/core/target.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ target_info_t target_info = {
#define INDEX_ARRAY_MEMBER CBOR_ENCODE_INDEX_ARRAY_MEMBER
#define STR_ARRAY_MEMBER CBOR_ENCODE_STR_ARRAY_MEMBER

TARGET_DMA_MEMBERS
TARGET_LED_MEMBERS
TARGET_BUZZER_MEMBERS
TARGET_SERIAL_MEMBERS
Expand Down Expand Up @@ -69,6 +70,7 @@ TARGET_INFO_MEMBERS
#define INDEX_ARRAY_MEMBER CBOR_DECODE_INDEX_ARRAY_MEMBER
#define STR_ARRAY_MEMBER CBOR_DECODE_STR_ARRAY_MEMBER

TARGET_DMA_MEMBERS
TARGET_LED_MEMBERS
TARGET_BUZZER_MEMBERS
TARGET_SERIAL_MEMBERS
Expand Down
Loading