Skip to main content
Associate II
November 14, 2025
Solved

Initialization of OpAmps in STM32G474

  • November 14, 2025
  • 2 replies
  • 230 views

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

Best answer by mƎALLEm

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.

2 replies

mƎALLEm
Technical Moderator
November 14, 2025
"To give better visibility on the answered topics, please click on ""Accept as Solution"" on the reply which solved your issue or answered your question."
ErXAuthor
Associate II
November 14, 2025

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;
}
mƎALLEm
mƎALLEmBest answer
Technical Moderator
November 14, 2025

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.

"To give better visibility on the answered topics, please click on ""Accept as Solution"" on the reply which solved your issue or answered your question."
ErXAuthor
Associate II
November 14, 2025

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