STM32G4 DAC output HAL+LL naming
Hi,
HAL and LL DAC configuration structure and its parameters naming can be confusing. Reference manual claims that DAC "mode" (register ADC->MCR, bits 0..2 or 16..17) can be in one of following four combinations when not used sample and hold mode:
0 -> DAC channel2 is connected to external pin with Buffer enabled
1 -> DAC channel2 is connected to external pin and to on chip peripherals with buffer enabled
2 -> DAC channel2 is connected to external pin with buffer disabled
3 -> DAC channel2 is connected to on chip peripherals with Buffer disabled
These combinations coherent but HAL DAC init struct offers up to six conbinations (Enable/Disable buffer times Internal/External/both connections). Some of them are not accesible. I've listed following configurations:
a) - OK
DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE;
DAC_ConnectOnChipPeripheral = DAC_CHIPCONNECT_EXTERNAL;
Resulting configuration: 0 -> DAC channel2 is connected to external pin with Buffer enabled
b) - Misleading
DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE;
DAC_ConnectOnChipPeripheral = DAC_CHIPCONNECT_INTERNAL;
Resulting configuration: 1 -> DAC channel2 is connected to external pin and to on chip peripherals with buffer enabled
c) - OK
DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE;
DAC_ConnectOnChipPeripheral = DAC_CHIPCONNECT_BOTH;
Resulting configuration: 1 -> DAC channel2 is connected to external pin and to on chip peripherals with buffer enabled
d) - OK
DAC_OutputBuffer = DAC_OUTPUTBUFFER_DISABLE;
DAC_ConnectOnChipPeripheral = DAC_CHIPCONNECT_EXTERNAL;
Resulting configuration: 2 -> DAC channel2 is connected to external pin with buffer disabled
e) - OK
DAC_OutputBuffer = DAC_OUTPUTBUFFER_DISABLE;
DAC_ConnectOnChipPeripheral = DAC_CHIPCONNECT_INTERNAL;
Resulting configuration: 3 -> DAC channel2 is connected to on chip peripherals with Buffer disabled
f) - Misleading
DAC_OutputBuffer = DAC_OUTPUTBUFFER_DISABLE;
DAC_ConnectOnChipPeripheral = DAC_CHIPCONNECT_BOTH;
Resulting configuration: 2 -> DAC channel2 is connected to external pin with buffer disabled
Also LL API have misleading parameter naming:
a) - OK
OutputBuffer = LL_DAC_OUTPUT_BUFFER_ENABLE;
OutputConnection = LL_DAC_OUTPUT_CONNECT_GPIO;
Resulting configuration: 0 -> DAC channel2 is connected to external pin with Buffer enabled
b) - Misleading
OutputBuffer = LL_DAC_OUTPUT_BUFFER_ENABLE;
OutputConnection = LL_DAC_OUTPUT_CONNECT_INTERNAL;
Resulting configuration: 1 -> DAC channel2 is connected to external pin and to on chip peripherals with buffer enabled
c) - OK
OutputBuffer = LL_DAC_OUTPUT_BUFFER_DISABLE;
OutputConnection = LL_DAC_OUTPUT_CONNECT_GPIO;
Resulting configuration: 2 -> DAC channel2 is connected to external pin with buffer disabled
d) - OK
OutputBuffer = LL_DAC_OUTPUT_BUFFER_DISABLE;
OutputConnection = LL_DAC_OUTPUT_CONNECT_INTERNAL;
Resulting configuration: 3 -> DAC channel2 is connected to on chip peripherals with Buffer disabled
You probably should enhance comment of structs
LL_DAC_InitTypeDef
DAC_ChannelConfTypeDef
to cover this confusions. Or/And change macros names. Or better change struct structure to correspond reference manual with four legal combinations.
