Problem with AnalogOut(DAC) and wait_ms()/thread_sleep_for

I’m trying to generate a sawtooth wave on my Nucleo-L432KC board. The code is pasted below:

int main()
{
    AnalogOut wave(A3);
    for(float i = 0; i < 1; i += 0.01)
    {
        wave = i;
        thread_sleep_for(50);
        // wait_ms(50); This cannot work too
        // osDelay(50); This cannot work too
        // wait_us(50000); This can work
    }
}

However, the A3 pin cannot perform what I expect. It will output a voltage for every 50ms, but during the 50ms wait time, it will output 0V.
I’ve tried wait_ms(50) and it has the same behaviour. If the code is changed to wait_us(50000), it perfectly works.

The RTOS is enabled in my project, so both wait_ms(50) and thread_sleep_for(50) will finally call the function osDelay(50);

I don’t know why osDelay(50) will disable the DAC output during the wait time. Is this a bug or I have some wrong understanding?

Thank you.

Hello,

The function wait_us is a delay without sleeping.
You probably need to find an information in datasheet about DAC behavior during sleep. STM32L families are low power consumption families, so there will be some rules. I think.

BR, Jan