Initialize dmuart repository template based on dmgpio and dmclk#3
Conversation
- Add CMakeLists.txt with DMOD build system integration - Add manifest.dmm and dmuart.dmr resource files - Add include/ with dmuart.h (public API) and dmuart_port.h (port layer) - Add include/port/ with STM32 register definitions - Add src/dmuart.c core DMDRVI implementation - Add src/port/ with STM32F7 UART port implementation - Add configs/ with board and MCU configuration files - Add docs/ with module, API, configuration, and port guides - Add tests/dmuart-test/ with loopback test application - Add examples/config.ini - Add .vscode/ settings and tasks - Update .gitignore and README.md
JohnAmadis
left a comment
There was a problem hiding this comment.
@copilot popraw to proszę
| @@ -0,0 +1,9 @@ | |||
| ; STM32F746G-DISCO board UART configuration | |||
There was a problem hiding this comment.
Dodaj więcej konfiguracji płytek, przynajmniej tyle samo co w dmgpio
There was a problem hiding this comment.
Added board configurations for: nucleo-f401re, nucleo-f411re, nucleo-f446re, nucleo-f767zi, stm32f4-discovery, stm32f429i-discovery, stm32f746g-disco, stm32f769i-discovery — matching the same set as dmgpio.
| ; STM32F746G-DISCO board UART configuration | ||
| ; Uses USART1 (connected to ST-Link virtual COM port) | ||
| [dmuart] | ||
| baudrate=115200 |
There was a problem hiding this comment.
daj jakąś wyższą prędkość, ta jest za niska
There was a problem hiding this comment.
Changed default baud rate to 921600 across all board and MCU configs.
| @@ -0,0 +1,8 @@ | |||
| { | |||
There was a problem hiding this comment.
brakuje też konfiguracji CI dla githuba
There was a problem hiding this comment.
Added .github/workflows/ci.yml with the same pattern as dmgpio — auto-discovers CPU families from src/port/*/port.c and builds each in a matrix using the chocotechnologies/dmod:1.0.4 container.
| @@ -0,0 +1,325 @@ | |||
| #define DMOD_ENABLE_REGISTRATION ON | |||
There was a problem hiding this comment.
wsparcie dla innych rodzin (przynajmniej f4) też powinno być
There was a problem hiding this comment.
Added full STM32F4 port at src/port/stm32f4/port.c with register definitions in include/port/stm32f4_regs.h. Supports USART1-6 with the same API as STM32F7. CI will now build both families.
| * | ||
| * @return int 0 on success, non-zero on failure | ||
| */ | ||
| dmod_dmuart_port_api_declaration(1.0, int, _init, ( uint32_t instance, dmuart_baudrate_t baudrate, dmuart_databits_t databits, uint8_t parity, uint8_t stopbits, uint8_t flowcontrol) ) |
There was a problem hiding this comment.
w dmgpio dla każdego parametru konfiguracyjnego były enumy - sprawdź sobie header dmgpio_types.h - tutaj też tak powinno być. Nie chcemy zgadywać co tam się przekazuje
There was a problem hiding this comment.
Created include/dmuart_types.h with typed enums for all parameters: dmuart_word_length_t, dmuart_parity_t, dmuart_stop_bit_t, dmuart_flow_control_t, dmuart_bit_order_t, dmuart_invert_t, dmuart_loopback_t, dmuart_int_trigger_t. The port layer now uses these types in all setters/getters instead of raw uint8_t.
| return -1; | ||
| } | ||
|
|
||
| volatile USART_TypeDef *USART = (USART_TypeDef *)uart_base_addresses[instance - 1]; |
There was a problem hiding this comment.
a co z obsługą przerwań? Nie widzę żadnej
There was a problem hiding this comment.
Added full interrupt support — DMOD_IRQ_HANDLER entries for all UART instances (both F4 and F7), set_interrupt_trigger to enable/disable specific interrupt sources (RXNE, TXE, TC, IDLE, Error), and add/remove_interrupt_handler for callback registration. ISR dispatches to registered handler with trigger type and received data.
| @@ -0,0 +1,9 @@ | |||
| ; STM32F746G-DISCO board UART configuration | |||
| ; Uses USART1 (connected to ST-Link virtual COM port) | |||
| [dmuart] | |||
There was a problem hiding this comment.
pliki konfiguracyjne dla uarta powinny również zawierać konfigurację dla niezbędnych pinów w gpio - tak, aby jak ktoś zdecyduje, że chce używać uarta, to automatycznie mu się skonfiguruje też gpio odpowiednio. dmdevfs wspiera takie coś - wystarczy dodać osobną sekcję i dodać w niej klucz driver_name (sprawdz sobie dokumentację dmdevfs).
Ponadto, jako że jest tam kilka uartów różnych na płytce, to moglibyśmy zrobić tak, że stworzymy folder configs/board/stm32f746g-disco/ a wewnątrz dodamy osobne pliki z konfiguracjami na każdego dostępnego uarta na płytce
Jako nazwę sekcji użyj też jakieś human friendly nazwy tego uarta, bo dzięki temu dmdevfs stworzy odpowiedni plik o tej nazwie.
There was a problem hiding this comment.
Restructured configs: each board is now a folder (e.g. configs/board/stm32f746g-disco/) with per-UART .ini files. Each file uses human-friendly section names (e.g. [stlink_vcp], [arduino_uart]) and includes GPIO pin configuration sections with driver_name=dmgpio for TX/RX pins, so dmdevfs will auto-configure both drivers.
| */ | ||
| dmod_dmdrvi_dif_api_declaration(1.0, dmuart, int, _flush, ( dmdrvi_context_t context, void* handle )) | ||
| { | ||
| return 0; |
There was a problem hiding this comment.
czemu flusha nie implementujesz? Też jest potrzebny
There was a problem hiding this comment.
Flush is now properly implemented — calls dmuart_port_flush() which waits for TX complete and drains RX FIFO.
| Dmod_Printf("Baud rate : %u\n\n", baudrate); | ||
|
|
||
| /* Initialize UART: 8N1, no flow control */ | ||
| int ret = dmuart_port_init(instance, baudrate, 8, 0, 0, 0); |
There was a problem hiding this comment.
nie powinieneś sam inicjalizować uarta do testów - lepiej jak Ci użytkownik przekażę ścieżkę do pliku z gotowym uartem
There was a problem hiding this comment.
Redesigned the test — it now takes a config file path as argument and creates the UART via dmuart_dmdrvi_create() using dmini_load(). No more direct port initialization.
| dmdrvi_context_t context = Dmod_Malloc(sizeof(struct dmdrvi_context)); | ||
| if (context != NULL) | ||
| { | ||
| memset(context, 0, sizeof(*context)); |
There was a problem hiding this comment.
z tego co widzę, to też nie obsługujesz kompletnie przerwań i dmhaman - powinieneś dać możliwość podania interrupt_trigger tak jak dmgpio - czyli żeby się dało triggerować handlery jak się otrzyma dane z uarta
There was a problem hiding this comment.
Added dmhaman integration: the driver reads interrupt_trigger and interrupt_handler from the INI config. When configured, it registers a port interrupt handler that calls dmhaman_call_handler() with dmuart_interrupt_params_t (instance, trigger type, received data). Also available via dmuart_ioctl_cmd_set_interrupt_handler ioctl.
…CI, board configs - Add dmuart_types.h with enums for all parameters (word_length, parity, stop_bit, flow_control, bit_order, invert, loopback, interrupt_trigger) - Redesign port layer with individual setters/getters per parameter - Add interrupt support with dmhaman integration (interrupt_trigger config) - Implement flush properly via port layer - Add STM32F4 port implementation - Add GitHub CI workflow (matching dmgpio pattern) - Restructure board configs as folders with per-UART files + GPIO pin config - Increase default baud rate to 921600 - Redesign test to accept config file path via dmdrvi
Done — addressed all review feedback in commits |
JohnAmadis
left a comment
There was a problem hiding this comment.
@copilot kolejne poprawki są niezbędne
| @@ -0,0 +1,70 @@ | |||
| name: CI | |||
There was a problem hiding this comment.
a release? Czemu tylko jedno skopiowałeś? Nie przyszło Ci do głowy, że drugie też jest potrzebne?
| flowcontrol=none | ||
| instance=6 | ||
|
|
||
| [arduino_uart_tx] |
There was a problem hiding this comment.
wydaje mi się, że gpio piny powinny być konfigurowane jako pierwsze, bo inaczej nie będziesz mógł użyć uarta
|
|
||
| on: | ||
| push: | ||
| branches: [ master, develop ] |
There was a problem hiding this comment.
tutaj w repo jest branch main
| } | ||
|
|
||
| const char *config_path = argv[1]; | ||
| Dmod_Printf("Config file: %s\n\n", config_path); |
There was a problem hiding this comment.
nie rozumiesz - nie potrzebujesz czytać config file'a,bo już powinien być skonfigurowany przez dmdevfs - użytkownik ma ci tylko podac sciezke do pliku
| dmuart_config_t *c = &context->config; | ||
| int ret; | ||
|
|
||
| ret = dmuart_port_init(c->instance); |
There was a problem hiding this comment.
dodaj jeszcze kontrolę zajętości kanału - tak, żeby przed skonfigurowaniem najpierw driver spróbował oznaczyć go sobie jako "zajęty" - tak aby następnym razem jak ktoś próbuje jeszcze raz użyć tego samego kanału i skonfigurować go do czegoś innego, żeby dostał błąd "channel is already used"
| { | ||
| if (validate_instance(instance) != 0 || data == NULL || received == NULL) return -1; | ||
|
|
||
| volatile USART_TypeDef *USART = get_usart(instance); |
There was a problem hiding this comment.
te Twoje nazwy typów USART_TypeDef aż biją po oczach biblioteką stm32 cube - dopasuj nazewnictwo do lokalnego standardu kodowania - snake_case, z suffixem _t dla typów
| return -1; | ||
| } | ||
|
|
||
| data[i] = (uint8_t)(USART->RDR & 0xFF); |
There was a problem hiding this comment.
a gdzie jakiś lokalny bufor? Z przerwania, jak tylko przyjdą dane, powinieneś je wrzucać do lokalnego bufora, np cycle ring. I jak ktoś zawoła receive to z niego to odczytywać... Nie powinniśmy tracić żadnych danych - a tymczasem w twoim rozwiazaniu jak nie zdazymy czegos odebrac to to przepada.
Możesz sobie zobaczyć jak ja to zaimplementowałem w innym systemie:
https://bitbucket.org/chocos/chocos/src/develop/Source/system/portable/src/st/stm32f7/lld/uart/oc_uart_lld.c
| return received; | ||
| } | ||
|
|
||
| dmod_dmdrvi_dif_api_declaration(1.0, dmuart, size_t, _write, ( dmdrvi_context_t context, void* handle, const void* buffer, size_t size, uint32_t offset )) |
There was a problem hiding this comment.
dodaj jakieś komentarze doxygen do tych wszystkich funkcji bo pusto jest jakoś tak.
I najlepiej też jakiś komentarz separacyjny w stylu:
// ==========================================================================
/**
* @brief moja znakomita funkcja
*
...
*/
// ==========================================================================|
@copilot nie buduje Ci sie projekt: [ 68%] Building C object src/port/CMakeFiles/dmuart_port.dir/stm32f4/port.c.o |
… STM32F4 and STM32F7 port implementations
Bootstraps the dmuart repository with the same DMOD module structure used in dmgpio and dmclk, adapted for UART.
Structure
CMakeLists.txtwithDMUART_MCU_SERIESparameter, DMOD FetchContent integration,dmod_add_libraryusagemanifest.dmm,dmuart.dmrresource fileinclude/dmuart_types.h): Typed enums for all configuration parameters — word length, parity, stop bit, flow control, bit order, invert, loopback, interrupt trigger; interrupt handler types and params structinclude/dmuart.h):dmuart_config_tstructure with typed fields; ioctl command set for runtime configurationinclude/dmuart_port.h): Individual setters/getters for each parameter (baudrate, word_length, parity, stop_bit, bit_order, invert, loopback), interrupt trigger/handler registration, flush, transmit/receivesrc/dmuart.c): Full DMDRVI implementation — create/free/open/close/read/write/ioctl/flush/stat withdmhamaninterrupt dispatch supportsrc/port/stm32f7/port.c): Register-level USART1-8 support with ISR handlers, all setters/getters, polled TX/RXsrc/port/stm32f4/port.c): Register-level USART1-6 support with ISR handlers for the F4 familydmdevfsauto-setup (8 boards: nucleo-f401re, nucleo-f411re, nucleo-f446re, nucleo-f767zi, stm32f4-discovery, stm32f429i-discovery, stm32f746g-disco, stm32f769i-discovery)tests/dmuart-test/)Usage
cmake -DDMUART_MCU_SERIES=stm32f7 -B build cmake --build build # or for STM32F4: cmake -DDMUART_MCU_SERIES=stm32f4 -B build cmake --build build