2025-11-14 5:04 AM
Hi,
I'm going to use four different OpAmps in the STM32G474, namely OPAMP3, OPAMP4, OPAMP5, and OPAMP6.
At this moment I try to initialize all four OpAmps. The first three work perfectly well, the initialization of OPAMP6 results in a problem. The State of OPAMP6 is HAL_OPAMP_STATE_CALIBBUSY. And, therefore result in an error.
For the first three the State is '28', and initialize perfectly well.
How can I fix this? What is causing this behavior?
With kind regards,
ErX
Solved! Go to Solution.
2025-11-14 5:26 AM - edited 2025-11-14 5:27 AM
At this stage better to test without RTOS. Create a new project from scratch then do the test. It could be something related to your implementation.
2025-11-14 5:16 AM
Hello,
You need to show your code.
How to write your question to maximize your chances to find a solution
2025-11-14 5:24 AM
Hi,
I'm using FreeRTOS to run a few tasks. Handling analog outputs via the OpAmps is done in my AnaControl-class.
I have one method to initialize all four OpAmps. The last one fails.
Here is the code of the initialize-method:
bool AnaControl::InitOpAmpModules()
{
m_hOpAmp3.Instance = OPAMP3;
m_hOpAmp3.Init.PowerMode = OPAMP_POWERMODE_NORMALSPEED;
m_hOpAmp3.Init.Mode = OPAMP_FOLLOWER_MODE;
m_hOpAmp3.Init.NonInvertingInput = OPAMP_NONINVERTINGINPUT_DAC;
m_hOpAmp3.Init.InternalOutput = DISABLE;
m_hOpAmp3.Init.TimerControlledMuxmode = OPAMP_TIMERCONTROLLEDMUXMODE_DISABLE;
m_hOpAmp3.Init.UserTrimming = OPAMP_TRIMMING_FACTORY;
if (HAL_OPAMP_Init(&m_hOpAmp3) != HAL_OK)
return false;
m_hOpAmp4.Instance = OPAMP4;
m_hOpAmp4.Init.PowerMode = OPAMP_POWERMODE_NORMALSPEED;
m_hOpAmp4.Init.Mode = OPAMP_FOLLOWER_MODE;
m_hOpAmp4.Init.NonInvertingInput = OPAMP_NONINVERTINGINPUT_DAC;
m_hOpAmp4.Init.InternalOutput = DISABLE;
m_hOpAmp4.Init.TimerControlledMuxmode = OPAMP_TIMERCONTROLLEDMUXMODE_DISABLE;
m_hOpAmp4.Init.UserTrimming = OPAMP_TRIMMING_FACTORY;
if (HAL_OPAMP_Init(&m_hOpAmp4) != HAL_OK)
return false;
m_hOpAmp5.Instance = OPAMP5;
m_hOpAmp5.Init.PowerMode = OPAMP_POWERMODE_NORMALSPEED;
m_hOpAmp5.Init.Mode = OPAMP_FOLLOWER_MODE;
m_hOpAmp5.Init.NonInvertingInput = OPAMP_NONINVERTINGINPUT_DAC;
m_hOpAmp5.Init.InternalOutput = DISABLE;
m_hOpAmp5.Init.TimerControlledMuxmode = OPAMP_TIMERCONTROLLEDMUXMODE_DISABLE;
m_hOpAmp5.Init.UserTrimming = OPAMP_TRIMMING_FACTORY;
if (HAL_OPAMP_Init(&m_hOpAmp5) != HAL_OK)
return false;
m_hOpAmp6.Instance = OPAMP6;
m_hOpAmp6.Init.PowerMode = OPAMP_POWERMODE_NORMALSPEED;
m_hOpAmp6.Init.Mode = OPAMP_FOLLOWER_MODE;
m_hOpAmp6.Init.NonInvertingInput = OPAMP_NONINVERTINGINPUT_DAC;
m_hOpAmp6.Init.InternalOutput = DISABLE;
m_hOpAmp6.Init.TimerControlledMuxmode = OPAMP_TIMERCONTROLLEDMUXMODE_DISABLE;
m_hOpAmp6.Init.UserTrimming = OPAMP_TRIMMING_FACTORY;
if (HAL_OPAMP_Init(&m_hOpAmp6) != HAL_OK)
return false;
return true;
}
2025-11-14 5:26 AM - edited 2025-11-14 5:27 AM
At this stage better to test without RTOS. Create a new project from scratch then do the test. It could be something related to your implementation.
2025-11-14 5:41 AM
Hi,
It worked great without RTOS. I thought of why. I think the m_hOpAmp<n> objects were created on the stack. When the RTOS switches tasks (and therefore the contents of the stack), they could be gone.
I went back to my RTOS project and moved the object from the stack into the memory. Now it works perfectly.
Greetings,
ErX