Repository navigation
Conversation
…n step USB code generation follows the LibXR OTG register runtime: - The OTG device takes a hardware configuration (PHY, DMA, VBUS sensing, high speed, EP0 OUT DMA buffer) derived from the .ioc mode and parameters instead of the PCD handle. - Endpoint buffers are 32-byte aligned, data endpoints are two slots (512-byte slots at high speed), and a raised OTG buffer size is written back to libxr_config.yaml with a notice. - CubeMX keeps its default settings; only a disabled OTG interrupt in NVIC is an error. When the generated sources define no OTG interrupt handler, app_main.cpp gets the vector function. libxr stm32 sync parses the project, generates app_main.cpp, turns off the CubeMX initialization call and interrupt handler of the OTG instances LibXR takes over, and updates the CMake integration. setup registers cmake/libxr_after_cubemx.cmd, a script that runs under cmd on Windows and under sh elsewhere, as the CubeMX post-generation script, so every code generation in CubeMX runs sync. Its output also goes to .libxr/after_cubemx.log; app_main.cpp records the digest of the .ioc file, and LibXR.CMake fails the configuration with that log and the command to run when the .ioc file changed without the code being generated again.
Emit the RX/TX list device constructor without any hpcd, generate the FSDEV/DRD vector function when CubeMX provides no IRQ handler, and number the data OUT endpoints EP(i+1) on both OTG and FSDEV.
[Medium impact] The changes affect STM32 USB projects using LibXR and their CubeMX build workflow. Fix the setup digest order, FSDEV interrupt settings, and shell interpreter selection before merging.
|
| generate(yaml_output, cpp_output, xrobot_enable) | ||
|
|
||
| integrate(project_dir) | ||
| install_hook(project_dir, ioc_file) |
There was a problem hiding this comment.
On first setup, install_hook() changes ProjectManager.UAScriptAfterPath after the final generate() call. The digest in app_main.cpp therefore describes the old .ioc file. The next CMake configure fails with a stale-code error even though setup reported success. Install the hook before parsing, or regenerate after registering it.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/libxr/config_cubemx_project.py
Line: 784
Comment:
**First setup blocks the build**
On first setup, `install_hook()` changes `ProjectManager.UAScriptAfterPath` after the final `generate()` call. The digest in `app_main.cpp` therefore describes the old `.ioc` file. The next CMake configure fails with a stale-code error even though setup reported success. Install the hook before parsing, or regenerate after registering it.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| if usb_name.startswith("USB_OTG_"): | ||
| self._record_otg_code_generation(usb_name, cfg) |
There was a problem hiding this comment.
FSDEV interrupt handlers stay missing
The parser records Vectors only for USB_OTG_*, but the new _fsdev_vector() needs that field to choose an interrupt handler. For USB and USB_DRD_FS, it always returns before checking the generated sources. With the USB interrupt enabled but CubeMX's Generate IRQ handler turned off, no replacement handler is emitted, so USB interrupts never reach STM32USBDeviceDevFs::Dispatch(). Record the FSDEV interrupt settings too.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/libxr/peripheral_analyzer_stm32.py
Line: 1257-1258
Comment:
**FSDEV interrupt handlers stay missing**
The parser records `Vectors` only for `USB_OTG_*`, but the new `_fsdev_vector()` needs that field to choose an interrupt handler. For `USB` and `USB_DRD_FS`, it always returns before checking the generated sources. With the USB interrupt enabled but CubeMX's Generate IRQ handler turned off, no replacement handler is emitted, so USB interrupts never reach `STM32USBDeviceDevFs::Dispatch()`. Record the FSDEV interrupt settings too.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| for py in ${LIBXR_PYTHON:-} python3 python; do | ||
| if command -v "$py" >/dev/null 2>&1 && "$py" -c "import libxr.stm32_cubemx_sync" >/dev/null 2>&1; then |
There was a problem hiding this comment.
If LIBXR_PYTHON names an interpreter whose path contains spaces, the shell hook splits it into separate words because the expansion in the for list is unquoted. A path such as /home/user/My Project/.venv/bin/python is never tried as one interpreter. If the fallback interpreters lack libxr, automatic sync fails despite a valid explicit interpreter. Probe the quoted LIBXR_PYTHON value separately before trying python3 and python.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/libxr/stm32_cubemx_sync.py
Line: 91-92
Comment:
**Hook skips the chosen Python**
If `LIBXR_PYTHON` names an interpreter whose path contains spaces, the shell hook splits it into separate words because the expansion in the `for` list is unquoted. A path such as `/home/user/My Project/.venv/bin/python` is never tried as one interpreter. If the fallback interpreters lack libxr, automatic sync fails despite a valid explicit interpreter. Probe the quoted `LIBXR_PYTHON` value separately before trying `python3` and `python`.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.setup wrote the script name into the .ioc file after app_main.cpp had recorded the digest of the .ioc file, so a project failed to configure right after setup until STM32CubeMX generated the code again.
STM32 USB code generation for the register runtimes of LibXR. It pairs with xrobot-org/libxr#362: after that change the STM32 USB backends no longer use the HAL PCD handle, so projects generated by the current CodeGenerator do not build against it.
What changes:
app_mainconstructsSTM32USBDeviceOtgFSorSTM32USBDeviceOtgHSwith the PHY, DMA, VBUS sensing and speed taken from the CubeMX configuration, and the endpoint buffers in the slot layout.OTG_x_IRQnhas to be enabled in NVIC; when CubeMX does not generate the handler, the generator writes one that callsSTM32USBOtgDevice::Dispatch().STM32USBDeviceDevFs.HAL_PCD_InitandHAL_PCD_IRQHandlerat link time.libxr stm32 syncand a CubeMX post-generation step:libxr stm32 setupinstallscmake/libxr_after_cubemx.cmdas the project's "after code generation" user action, so generating from CubeMX also regenerates the LibXR code. Errors go to.libxr/after_cubemx.logand fail the CMake configure step.Tests: analyzer, generator, CMake generator and the sync command have unit tests (
tests/test_stm32_cubemx_sync.pyis new).ruff format --checkandruff checkpass.Merge together with xrobot-org/libxr#362.