Skip to content

possible error in stm32_ll_lpbam.c #65

Description

@TUBUSER1GFBPROJ
LPBAM_Status_t LPBAM_LPTIM_FillNodeConfig(LPBAM_LPTIM_ConfNode_t const *const  pConfNode,
                                          DMA_NodeConfTypeDef    *const pDMANodeConfig)
{
  LPBAM_Status_t   status;
  LPBAM_InfoDesc_t desc_info;
  ...

in stm32_lpbam_lptim.c leaves desc_info uninitialized and calls

LPBAM_Status_t LPBAM_LPTIM_FillStructInfo(LPBAM_LPTIM_ConfNode_t const *const pConfNode,
                                          LPBAM_InfoDesc_t       *const pDescInfo)

in stm32_ll_lpbam.c with reference to desc_info.

While LPBAM_LPTIM_FillStructInfo does not set pDescInfo->Request in case of LPBAM_LPTIM_CONFIG_ID with pConfNode->Config.State != ENABLE and pConfNode->Config.Mode != LPBAM_LPTIM_UE_MODE as it can be seen in the following code snippet.

  ...
  /* Check node ID */
  switch (pConfNode->NodeDesc.NodeInfo.NodeID)
  {
    /* LPBAM LPTIM Update Period node ID */
    case LPBAM_LPTIM_CONFIG_ID:
    {
      /* Get control register value */
      dummy = pConfNode->pInstance->CR;

      /* Check LPTIM state */
      if (pConfNode->Config.State == ENABLE)
      {
        /* Set LPTIM update event request */
        pDescInfo->Request = DMA_REQUEST_SW;

        /* Set LPTIM state */
        dummy |= LPTIM_CR_ENABLE;

        /* Check LPTIM start mode update */
        if (pConfNode->Config.UpdateStartMode == ENABLE)
        {
          if (pConfNode->Config.StartMode == LPBAM_LPTIM_START_SINGLE)
          {
            /* Configure LPTIM to start in single mode */
            dummy |= LPTIM_CR_SNGSTRT;
          }
          else
          {
            /* Configure LPTIM to start in continuous mode */
            dummy |= LPTIM_CR_CNTSTRT;
          }
        }
      }
      else
      {
        /* Set LPTIM state */
        dummy &= ~(LPTIM_CR_ENABLE);
    	
        /* Check LPTIM mode */
        if (pConfNode->Config.Mode == LPBAM_LPTIM_UE_MODE)
        {
          /* Check LPTIM instance */
          if (pConfNode->pInstance == LPTIM1)
          {
            /* Set LPTIM1 update event request */
            pDescInfo->Request = LPDMA1_REQUEST_LPTIM1_UE;
          }
          else
          {
            /* Set LPTIM3 update event request */
            pDescInfo->Request = LPDMA1_REQUEST_LPTIM3_UE;
          }
        }
      }

      /* Set value to be written */
      *pConfNode->NodeDesc.pSrcVarReg = dummy;

      /* Set DMA source address */
      pDescInfo->SrcAddr  = (uint32_t)pConfNode->NodeDesc.pSrcVarReg;
      /* Set DMA destination address */
      pDescInfo->DstAddr  = lptim_descitem_tbl[pConfNode->NodeDesc.NodeInfo.NodeID].RegOffset +
                            (uint32_t)pConfNode->pInstance;
      /* Set DMA data size */
      pDescInfo->DataSize = lptim_descitem_tbl[pConfNode->NodeDesc.NodeInfo.NodeID].RegDataSize;

      break;
    }
    ....

Later code uses Request leading to undefined behavior. The fix that worked for me was adding

      ...
      else
      {
        
        pDescInfo->Request = DMA_REQUEST_SW;

        /* Set LPTIM state */
        dummy &= ~(LPTIM_CR_ENABLE);
      ...

essentially this problem occurred when adding a lptim stop node with "not from update event detection" in cubemx lpbam scenario.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinginternal bug trackerIssue confirmed and logged into the internal bug tracking systemlpbamLow-Power Background Autonomous ModeutilsUtilities

Type

Fields

No fields configured for Bug.

Projects

Status
Analyzed

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions