Skip to content

Commit b23c767

Browse files
oganigljorgesg82Cantonplasvictor-Lopez25Copilot
authored
DFSDM (#614)
* add all enums needed, I hope * CLK finished, half way from finishing DFSDM.HPP * First total draft of dfsdm finished * fix some errors from the merge, mia culpa * eliminate right bit shift in execution time * added some changes to compile clk * change a bit of AF in PB0 for dfsdm_clk_out * clock works for every possible pin * added a config, you're welcome Boris * compiles let's see if it works * add buffer and callbacks in compile time * some more changes in the dfsdm * fix some minor errors * add again max_instances * Add dma safety, not implemented yet * Masinstances updated to max_instances * now the callbacks works * some more more changes * the trigger works gg * okay this might work * okay dma works, something to look is how to allow to use the 16 entries of the DMA without removing double entries with the dfsdm. * dma tested, don't ask how, don't ask why but it works fine. Or at least in my test has worked fine. * Robust TCP/IP Hardening (#582) * Fixed copy pointers leading with possible missalignment * fix(tcp): handle fragmented order streams and queue backpressure * fix(server): own and recycle ServerSocket instances safely * fix(udp): harden DatagramSocket lifecycle and pbuf parsing * fix(lwip): align ICMP checksum settings with hw offload * fix(net): harden socket teardown and unify TCP order parsing * Applied formatter * perf(net): benchmark-driven TCP TX fast path * feat(error): decouple transport from legacy update * Modified warning to decouple from protections * Better timestamp in error and warning * Protection manager more robust * Always enqueuing msgs even when there are no sockets * sorry, I forgot one file * SNTP set * minor fix on protections * Being able to compile without ehternet * formatter * Prescaler was not initialized in init (#584) * Prescaler was not initialized in init * formatting: Remove spaces * formatting * hardened a lot the encoder, being sure that instances are properly set * minor fix, not setting properly the encoder start * added tests for the encoder * reverted nullptr checks, and made builder private * applied formatter * Make constructors private in Encoder, PWM, DualPWM * applied formatter * fixed merge mess --------- Co-authored-by: Víctor López <120128034+victor-Lopez25@users.noreply.github.com> Co-authored-by: Jorge Sáez <jorgeesg82@gmail.com> * Fix/scheduler timerdomain (#585) * Scheduler now "reserves" a timer from timerdomain * Also remove possibility of getting scheduler timer from bits32_timers * stupid change to get precommit to work (?) * fix formatting (?) * more format fix * fix segfault in tests (?) * fix formatting * move Scheduler_global_timer in scheduler_test.cpp * Fixed issues with MSVC on windows in tests (#583) * Fixed issues with MSVC on windows * Move implementation into cpp * Return to inlining clz and ctz * fix formatting (hopefully) * more formatting fixes * fix formatting final please * Fix: rcc_enable_timer for scheduler timer (#586) * Fix: rcc_enable_timer for scheduler timer * formatting nº1 * Feat/no virtual on State Machine (#581) * No more fixed_vector(idk why I did that) * First version implementing std::tupple * No more copy constructor bullshit * Equal operator fixed, now it compiles * Compiling version, tests to be done * Okay now we check for duplicates * Some formating changes * Clanker made me do this so the start and exit functions stop when the condition is true * Made nesting consteval * Fix short circuit no use on return warning * Added state machine tests * Formating errors fixed * Ok now format errors are fixed * More tests need to be addes * Compile testing added, as well as reduced task array to only allow 16 task * Formating errores fixed * Delete tests for the tests * Now you cant use state machine without start * Fixed logic for nested machine start * Formating error fix * clanker commit Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Now we use a concept for a correct tuple in state machine helper function * Formating fix --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix(MDMA): Fix, MDMA AHBS is 32-bit only (#588) * Fix Scheduler race conditions (#591) * Max out ARR for encoder (#587) * Max ARR * fix encoder test * actually fix tests now * fix formatting * Hotfix/sched register b4 start (#593) * Change the frequency if this can be called frequency of the leds (#580) * Releases are back bitches (#596) * chore(release): add semver foundation and tooling * ci(release): require changesets on pull requests * ci(release): automate release preparation and publishing * chore(release): add bootstrap changeset for release infra * fix(release): address Copilot review feedback * merge development to main * compiles, but not tested * OKay tested this works fine with dma and without. * readme version * indentation done * change start() to static functions * add more safety * change changeset * Remove duplicity * add indentation for 14 time * add defines for the simulator * modify stm32.cmake so everyone can use it and not only people with an apple computer ejem * done again changes do to indentation * change for clarity * change for clarity * more changes done * fuck code was right * eliminate an array that is not used * test dfdsm creo que no se puede llamar ni vibe coding, se debería de llamar: IA vibe codeando con permisos sudos * feat(DFSDM): Re-add DFSDM_CLK_DOMAIN tests (13 tests) - Added clock domain pin validation tests - Added clock domain alternate function mapping tests - Added clock domain constructor validation - All 22 DFSDM tests now passing - Both simulator and nucleo-debug presets compile with 0 errors * add fucking iindent --------- Co-authored-by: Jorge Sáez <125664643+jorgesg82@users.noreply.github.com> Co-authored-by: Daniel Cantó Catalán <144663567+Cantonplas@users.noreply.github.com> Co-authored-by: Víctor López <120128034+victor-Lopez25@users.noreply.github.com> Co-authored-by: Jorge Sáez <jorgeesg82@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Boris Mladenov Beslimov <borisbeslimov@gmail.com>
1 parent f1b51c9 commit b23c767

13 files changed

Lines changed: 2135 additions & 30 deletions

File tree

.changesets/dfsdm-module-minor.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
release: minor
2+
summary: Added module dfsdm tested

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ set(HALAL_CPP_NO_ETH
298298
${CMAKE_CURRENT_LIST_DIR}/Src/HALAL/Services/Time/RTC.cpp
299299
${CMAKE_CURRENT_LIST_DIR}/Src/HALAL/Services/Time/Scheduler.cpp
300300
${CMAKE_CURRENT_LIST_DIR}/Src/HALAL/Services/Watchdog/Watchdog.cpp
301+
${CMAKE_CURRENT_LIST_DIR}/Src/HALAL/Services/DFSDM/DFSDM.cpp
301302
)
302303

303304

Inc/HALAL/HALAL.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
#include "HALAL/Models/Packets/MdmaPacket.hpp"
5151

5252
#include "HALAL/Benchmarking_toolkit/DataWatchpointTrace/DataWatchpointTrace.hpp"
53+
54+
#include "HALAL/Services/DFSDM/DFSDM.hpp"
5355
#include "HALAL/HardFault/HardfaultTrace.h"
5456
#include "HALAL/Services/Communication/Ethernet/NewEthernet.hpp"
5557
#ifdef STLIB_ETH

Inc/HALAL/Models/DMA/DMA2.hpp

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ struct DMADomain {
3535
spi4,
3636
spi5,
3737
spi6,
38-
fmac
38+
fmac,
39+
dfsdm_filter0,
40+
dfsdm_filter1,
41+
dfsdm_filter2,
42+
dfsdm_filter3
3943
};
4044

4145
enum class Stream : uint8_t {
@@ -98,7 +102,7 @@ struct DMADomain {
98102
}
99103
return nullptr;
100104
}
101-
105+
static inline consteval bool shares_dma(Peripheral p) { return is_dfsdm(p); }
102106
struct Entry {
103107
Peripheral instance;
104108
Stream stream;
@@ -217,6 +221,16 @@ struct DMADomain {
217221

218222
static consteval bool is_none(Peripheral instance) { return instance == Peripheral::none; }
219223

224+
static consteval bool is_dfsdm(Peripheral instance) {
225+
return is_one_of(
226+
instance,
227+
Peripheral::dfsdm_filter0,
228+
Peripheral::dfsdm_filter1,
229+
Peripheral::dfsdm_filter2,
230+
Peripheral::dfsdm_filter3
231+
);
232+
}
233+
220234
static consteval uint32_t get_Request(Peripheral instance, uint8_t i) {
221235
if (instance == Peripheral::none)
222236
return DMA_REQUEST_MEM2MEM;
@@ -272,8 +286,20 @@ struct DMADomain {
272286
return DMA_REQUEST_FMAC_WRITE;
273287
if (instance == Peripheral::fmac && i == 2)
274288
return DMA_REQUEST_FMAC_READ;
275-
289+
if (instance == Peripheral::dfsdm_filter0) {
290+
return DMA_REQUEST_DFSDM1_FLT0;
291+
}
292+
if (instance == Peripheral::dfsdm_filter1) {
293+
return DMA_REQUEST_DFSDM1_FLT1;
294+
}
295+
if (instance == Peripheral::dfsdm_filter2) {
296+
return DMA_REQUEST_DFSDM1_FLT2;
297+
}
298+
if (instance == Peripheral::dfsdm_filter3) {
299+
return DMA_REQUEST_DFSDM1_FLT3;
300+
}
276301
compile_error("Invalid DMA request configuration");
302+
277303
return 0;
278304
}
279305

@@ -303,7 +329,7 @@ struct DMADomain {
303329
static consteval uint32_t get_PeriphDataAlignment(Peripheral instance, uint8_t i) {
304330
if (is_spi(instance) || is_i2c(instance)) {
305331
return DMA_PDATAALIGN_BYTE;
306-
} else if (is_none(instance)) {
332+
} else if (is_none(instance) || (is_dfsdm(instance))) {
307333
return DMA_PDATAALIGN_WORD;
308334
}
309335
return DMA_PDATAALIGN_HALFWORD;

Inc/HALAL/Models/TimerDomain/TimerDomain.hpp

Lines changed: 59 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,32 @@ enum TimerRequest : uint8_t {
149149
Basic_6 = 6,
150150
Basic_7 = 7,
151151
};
152+
enum class SelectionTrigger1 : uint32_t {
153+
Reset = TIM_TRGO_RESET,
154+
Enable = TIM_TRGO_ENABLE,
155+
Update = TIM_TRGO_UPDATE,
156+
General_Compare = TIM_TRGO_OC1,
157+
Compare_channel1 = TIM_TRGO_OC1REF,
158+
Compare_channel2 = TIM_TRGO_OC2REF,
159+
Compare_channel3 = TIM_TRGO_OC3REF,
160+
Compare_channel4 = TIM_TRGO_OC4REF
161+
};
162+
enum class SelectionTrigger2 : uint32_t {
163+
Reset = TIM_TRGO2_RESET,
164+
Enable = TIM_TRGO2_ENABLE,
165+
Update = TIM_TRGO2_UPDATE,
166+
General_Compare = TIM_TRGO2_OC1,
167+
Compare_channel1 = TIM_TRGO2_OC1REF,
168+
Compare_channel2 = TIM_TRGO2_OC2REF,
169+
Compare_channel3 = TIM_TRGO2_OC3REF,
170+
Compare_channel4 = TIM_TRGO2_OC4REF,
171+
Compare_channel5 = TIM_TRGO2_OC5REF,
172+
Compare_channel6 = TIM_TRGO2_OC6REF,
173+
Compare_channel4_R_channel6_F = TIM_TRGO2_OC4REF_RISING_OC6REF_FALLING,
174+
Compare_channel4_R_channel6_R = TIM_TRGO2_OC4REF_RISING_OC6REF_RISING,
175+
Compare_channel5_R_channel6_F = TIM_TRGO2_OC5REF_RISING_OC6REF_FALLING,
176+
Compare_channel5_R_channel6_R = TIM_TRGO2_OC5REF_RISING_OC6REF_RISING
177+
};
152178

153179
// Alternate functions for timers
154180
enum class TimerAF {
@@ -261,10 +287,14 @@ struct TimerDomain {
261287
TimerRequest request;
262288
uint8_t pin_count;
263289
std::array<TimerPin, 7> pins; /* this won't be read in Timer constructor */
290+
SelectionTrigger1 trgo1{SelectionTrigger1::Reset};
291+
SelectionTrigger2 trgo2{SelectionTrigger2::Reset};
264292
};
265293

266294
struct Config {
267295
uint8_t timer_idx;
296+
SelectionTrigger1 trgo1;
297+
SelectionTrigger2 trgo2;
268298
};
269299

270300
static constexpr TIM_HandleTypeDef* hal_handles[16] = { // general purpose timers
@@ -498,15 +528,17 @@ struct TimerDomain {
498528
: e(ent.name,
499529
ent.request,
500530
sizeof...(pinargs),
501-
std::array<TimerPin, 7>(
502-
{GetPinFromIdx(pinargs, 0),
503-
GetPinFromIdx(pinargs, 1),
504-
GetPinFromIdx(pinargs, 2),
505-
GetPinFromIdx(pinargs, 3),
506-
GetPinFromIdx(pinargs, 4),
507-
GetPinFromIdx(pinargs, 5),
508-
GetPinFromIdx(pinargs, 6)}
509-
)),
531+
std::array<TimerPin, 7>({
532+
GetPinFromIdx(pinargs, 0),
533+
GetPinFromIdx(pinargs, 1),
534+
GetPinFromIdx(pinargs, 2),
535+
GetPinFromIdx(pinargs, 3),
536+
GetPinFromIdx(pinargs, 4),
537+
GetPinFromIdx(pinargs, 5),
538+
GetPinFromIdx(pinargs, 6),
539+
}),
540+
ent.trgo1,
541+
ent.trgo2),
510542
gpio0(GetGPIOFromIdx(pinargs, ent.request, 0)),
511543
gpio1(GetGPIOFromIdx(pinargs, ent.request, 1)),
512544
gpio2(GetGPIOFromIdx(pinargs, ent.request, 2)),
@@ -551,6 +583,8 @@ struct TimerDomain {
551583
.request = e.request,
552584
.pin_count = e.pin_count,
553585
.pins = e.pins,
586+
.trgo1 = e.trgo1,
587+
.trgo2 = e.trgo2
554588
};
555589
ctx.template add<TimerDomain>(local_entry, this);
556590
}
@@ -605,6 +639,8 @@ struct TimerDomain {
605639

606640
Config cfg = {
607641
.timer_idx = timer_idxmap[reqint],
642+
.trgo1 = requests[i].trgo1,
643+
.trgo2 = requests[i].trgo2
608644
};
609645
cfgs[cfg_idx++] = cfg;
610646

@@ -635,9 +671,8 @@ struct TimerDomain {
635671
}
636672

637673
uint8_t reqint = remaining_32bit_timers[count_32bit_requests];
638-
Config cfg = {
639-
.timer_idx = timer_idxmap[reqint],
640-
};
674+
Config cfg =
675+
{.timer_idx = timer_idxmap[reqint], .trgo1 = e.trgo1, .trgo2 = e.trgo2};
641676
cfgs[cfg_idx++] = cfg;
642677

643678
// unordered remove
@@ -684,9 +719,7 @@ struct TimerDomain {
684719
ST_LIB::compile_error("This only processes TimerRequest::AnyGeneralPurpose");
685720
}
686721
uint8_t reqint = remaining_timers[i];
687-
Config cfg = {
688-
.timer_idx = timer_idxmap[reqint],
689-
};
722+
Config cfg = {.timer_idx = timer_idxmap[reqint], .trgo1 = e.trgo1, .trgo2 = e.trgo2};
690723
cfgs[cfg_idx++] = cfg;
691724
}
692725

@@ -697,6 +730,7 @@ struct TimerDomain {
697730
struct Instance {
698731
TIM_TypeDef* tim;
699732
TIM_HandleTypeDef* hal_tim;
733+
TIM_MasterConfigTypeDef master{};
700734
uint8_t timer_idx;
701735
};
702736

@@ -738,6 +772,7 @@ struct TimerDomain {
738772

739773
TIM_HandleTypeDef* handle = hal_handles[e.timer_idx];
740774
TIM_TypeDef* tim = cmsis_timers[e.timer_idx];
775+
741776
handle->Instance = tim;
742777
handle->Init.Period = 0;
743778
handle->Init.Prescaler = 0;
@@ -767,6 +802,15 @@ struct TimerDomain {
767802
inst->tim = tim;
768803
inst->hal_tim = handle;
769804
inst->timer_idx = e.timer_idx;
805+
TIM_MasterConfigTypeDef sMasterConfig = {};
806+
sMasterConfig.MasterOutputTrigger = static_cast<uint32_t>(e.trgo1);
807+
sMasterConfig.MasterOutputTrigger2 = static_cast<uint32_t>(e.trgo2);
808+
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
809+
inst->master = sMasterConfig;
810+
if (HAL_TIMEx_MasterConfigSynchronization(inst->hal_tim, &sMasterConfig) !=
811+
HAL_OK) {
812+
ErrorHandler("Unable to configure master synch");
813+
}
770814
}
771815
}
772816
};

0 commit comments

Comments
 (0)