Coding style in STM32 HAL code
A do { something; } while (0) is a typical pattern in macros, where you want to make sure that all instructions get executed.

Example why this is important:

#define MY_MACRO() do_something1(); do_something2()


This will work:

MY_MACRO();


but this will not work as intended:

if (some_condition) MY_MACRO();


because it will be preprocessed into:

if (some_condition) do_something1(); do_something2();


The second statement will be executed no matter what the condition said.

A do { ... } while(0) is just a convenient way to make a block of code. It will be optimized out by the compiler anyway, so there is actually no looping involved and no runtime overhead.