Skip to content

fix(LPBAM): initialize Request in LPBAM_LPTIM_FillStructInfo#74

Open
94xhn wants to merge 1 commit into
STMicroelectronics:mainfrom
94xhn:fix-lpbam-lptim-uninitialized-request
Open

fix(LPBAM): initialize Request in LPBAM_LPTIM_FillStructInfo#74
94xhn wants to merge 1 commit into
STMicroelectronics:mainfrom
94xhn:fix-lpbam-lptim-uninitialized-request

Conversation

@94xhn

@94xhn 94xhn commented Jul 9, 2026

Copy link
Copy Markdown

Resubmission of #73, closed because the CLA wasn't signed yet at the time — signed now.

Fixes #65.

Root cause

For the LPBAM_LPTIM_CONFIG_ID node, LPBAM_LPTIM_FillStructInfo() (Utilities/lpbam/STM32U5/stm32_ll_lpbam.c) only sets pDescInfo->Request in two cases:

  • Config.State == ENABLEDMA_REQUEST_SW
  • Config.State != ENABLE and Config.Mode == LPBAM_LPTIM_UE_MODELPDMA1_REQUEST_LPTIM1_UE / LPDMA1_REQUEST_LPTIM3_UE

The remaining combination — Config.State != ENABLE and Config.Mode == LPBAM_LPTIM_NO_UE_MODE — falls through without ever assigning pDescInfo->Request.

The caller, LPBAM_LPTIM_FillNodeConfig() (Utilities/lpbam/stm32_lpbam_lptim.c), declares its LPBAM_InfoDesc_t desc_info; on the stack without initializing it, so in this case pDMANodeConfig->Init.Request ends up with whatever garbage happened to be on the stack. That value also decides pDMANodeConfig->Init.Direction (set to DMA_MEMORY_TO_PERIPH whenever Request != DMA_REQUEST_SW), so two otherwise-identical LPTIM "stop" nodes built the same way can end up with different DMA node configurations purely depending on unrelated stack contents at the time — this is exactly what @elektrojupp's report shows: two stop nodes built with the same code, one working and one not, traced down to differing Request bits in the resulting descriptors.

Fix

Set Request = DMA_REQUEST_SW for the missing case, matching the same choice already made in the Config.State == ENABLE branch just above it — both are cases where there's no specific hardware DMA request line tied to the transfer, so software-triggered is the consistent choice.

Testing

I don't have the affected hardware or STM32CubeMX/IDE set up to build the full LPBAM example project, so I can't provide a board-level test. What I did instead: extracted the exact branch structure of LPBAM_LPTIM_FillStructInfo()'s LPBAM_LPTIM_CONFIG_ID case into a standalone host-C reproduction (stand-in enums for the STM32U5-specific constants), compiled and ran with plain gcc:

  • Before fix: State=DISABLE, Mode=NO_UE_MODE leaves Request as an uninitialized sentinel value.
  • After fix: same input produces Request = DMA_REQUEST_SW (0), consistently.

This matches @elektrojupp's own account that "the suggested fix at least worked in my case. Both stop nodes working and no difference in descriptors."

Generative AI

I used generative AI tools when creating this PR, but a human has checked the code and is responsible for the code and the description above.

For the LPBAM_LPTIM_CONFIG_ID node, LPBAM_LPTIM_FillStructInfo()
only sets pDescInfo->Request when Config.State == ENABLE, or when
Config.State != ENABLE and Config.Mode == LPBAM_LPTIM_UE_MODE. The
remaining case (State != ENABLE, Mode != LPBAM_LPTIM_UE_MODE, i.e.
LPBAM_LPTIM_NO_UE_MODE) leaves pDescInfo->Request untouched.

The caller, LPBAM_LPTIM_FillNodeConfig() in stm32_lpbam_lptim.c,
declares its LPBAM_InfoDesc_t on the stack without initializing it,
so in this case pDMANodeConfig->Init.Request ends up with whatever
garbage was already on the stack. That value also decides
pDMANodeConfig->Init.Direction (set to DMA_MEMORY_TO_PERIPH whenever
Request != DMA_REQUEST_SW), so two otherwise-identical LPTIM stop
nodes can end up with different DMA node configurations depending
on unrelated stack contents - reported independently by two users,
one of whom confirmed setting Request explicitly fixed their queue.

Set Request to DMA_REQUEST_SW for this case, matching the same
choice already made in the State == ENABLE branch above (also a
case with no specific hardware DMA request tied to it).

Fixes STMicroelectronics#65

Signed-off-by: yi chen <94xhn1@gmail.com>
@ALABSTM ALABSTM added bug Something isn't working lpbam Low-Power Background Autonomous Mode labels Jul 10, 2026
@ALABSTM ALABSTM added the utils Utilities label Jul 10, 2026
@MKISTM MKISTM moved this from To do to Analyzed in stm32cube-mcu-fw-dashboard Jul 13, 2026
@MKISTM

MKISTM commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Hello @94xhn,

Thank you for this report. This point is already being tracked internally. I will keep you informed about our decision.

Best Regards,
KIWA Mohamed Chaker.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working lpbam Low-Power Background Autonomous Mode utils Utilities

Projects

Development

Successfully merging this pull request may close these issues.

possible error in stm32_ll_lpbam.c

3 participants