Skip to main content
Visitor II
September 25, 2026
Question

Bug Report: Wrong conditional flag used for AC Feed-Forward in DPC_Loopctrl.c (Vienna Rectifier / Digital Power)

  • September 25, 2026
  • 0 replies
  • 5 views

Hello Community,

I would like to report another significant logic bug in the generated firmware libraries for the Vienna Rectifier project (specifically located in the Digital Power Control stack file BSP/DPC_FW_PACK/src/DPC_Loopctrl.c).

The Issue:

Inside the function DPC_LCT_FeedForwardCtrl(..), the firmware is supposed to evaluate whether the AC Voltage Feed-Forward task is enabled before adding the d-axis and q-axis AC feed-forward grid terms (fVd_feed_sub and fVq_feed_sub) to the current loop outputs.

However, the original ST framework code erroneously checks the DC voltage feed-forward enable flag instead of the AC one.

The Code Snippet:

c

void DPC_LCT_FeedForwardCtrl(DPC_LCT_CDC_t *pCDC_sub, float *pVd_ctrl_FF_sub, float *pVq_ctrl_FF_sub)
{
float fVd_feed_sub = pCDC_sub->fVdFeed;
float fVq_feed_sub = pCDC_sub->fVqFeed;
float fVd_ctrl_sub = pCDC_sub->fVdCurrentCtrl;
float fVq_ctrl_sub = pCDC_sub->fVqCurrentCtrl;

/* AC feedforward task */
// BUG: Checks bVDC_FF_Enable instead of bFF_Enable
if(pCDC_sub->bVDC_FF_Enable == SET) /*!< DC voltage FeedForward Enabling */
{
pCDC_sub->fVdFF_ctrl = fVd_ctrl_sub + fVd_feed_sub; // d-axis - Vac Feed_Forward
pCDC_sub->fVqFF_Ctrl = fVq_ctrl_sub + fVq_feed_sub; // q-axis - Vac Feed_Forward
}
else
{
pCDC_sub->fVdFF_ctrl = fVd_ctrl_sub; // d-axis - Vac Feed_Forward bypassed
pCDC_sub->fVqFF_Ctrl = fVq_ctrl_sub; // q-axis - Vac Feed_Forward bypassed
}

/* DQ control voltage obtained */
*pVd_ctrl_FF_sub = pCDC_sub->fVdFF_ctrl;
*pVq_ctrl_FF_sub = pCDC_sub->fVqFF_Ctrl;
}

 

The Impact:

Because of this typo/copy-paste error in the library logic, if a user enables or disables AC Feed-Forward independently in their control topology parameters, the conditional branch evaluates the wrong boolean state (bVDC_FF_Enable). This compromises the decoupled current control loop (CDC) matrix, causing severe tracking errors in the DQ frame, poor THD performance, and potential instability under fast load variations.

The Elegant Non-Intrusive Fix (Linker Wrap Method):

Since modifying the library file directly inside BSP/DPC_FW_PACK/src/DPC_Loopctrl.c will cause the fix to be overwritten every time you click "Generate Code" in CubeMX, you can use the GCC linker function wrapping mechanism to fix it safely:

  1. Copy the function into a safe user code section (e.g., inside app_vienna.c between USER CODE BEGIN / USER CODE END tags) and implement the corrected flag check using the __wrap_ prefix:

c

void __wrap_DPC_LCT_FeedForwardCtrl(DPC_LCT_CDC_t *pCDC_sub, float *pVd_ctrl_FF_sub, float *pVq_ctrl_FF_sub)
{
float fVd_feed_sub = pCDC_sub->fVdFeed;
float fVq_feed_sub = pCDC_sub->fVqFeed;
float fVd_ctrl_sub = pCDC_sub->fVdCurrentCtrl;
float fVq_ctrl_sub = pCDC_sub->fVqCurrentCtrl;

/* AC feedforward task - FIXED FLAG CHECK */
if(pCDC_sub->bFF_Enable == SET) /*!< AC voltage FeedForward Enabling properly checked */
{
pCDC_sub->fVdFF_ctrl = fVd_ctrl_sub + fVd_feed_sub;
pCDC_sub->fVqFF_Ctrl = fVq_ctrl_sub + fVq_feed_sub;
}
else
{
pCDC_sub->fVdFF_ctrl = fVd_ctrl_sub;
pCDC_sub->fVqFF_Ctrl = fVq_ctrl_sub;
}

*pVd_ctrl_FF_sub = pCDC_sub->fVdFF_ctrl;
*pVq_ctrl_FF_sub = pCDC_sub->fVqFF_Ctrl;
}

 

  1. Instruct the linker to redirect all calls from the original function to your fixed version. Go to:
    Project Properties > C/C++ Build > Settings > Tool Settings > MCU/MPU GCC Linker > Miscellaneous > Other flags and add:

text

-Wl,--wrap=DPC_LCT_FeedForwardCtrl

 

Best regards,

k_nedelchev