Skip to main content
Paul Andreev
Associate
November 15, 2018
Question

Strange conversion in adc low-layer for STM32F4.

  • November 15, 2018
  • 3 replies
  • 1774 views

0690X000006CNWrQAO.jpg

Output type of LL_ADC_REG_ReadConversiomData32() is uint32_t. Convertion in function is uint16_t.

I think convertion need be to type uint32_t. Like in function LL_ADC_REG_ReadMultiConversionData32().

0690X000006CNXBQA4.jpg

Also in LL_ADC_REG_ReadConversionData6 and LL_ADC_REG_ReadConversionData8 convertion need to be (uint8_t).

0690X000006CNXaQAO.jpg

This topic has been closed for replies.

3 replies

AvaTar
Senior III
November 15, 2018

I have my reasons to stay with the SPL for this MCU.

The last function is even more strange:

return (uint16_t) (READ_BIT) (ADCx->DR ...));

How can one convert a single bit to a 6 bit value ?

Or does the function/macro not do what it's name suggests ?

Guess this discloses something about the amount of code reviews and tests done for the Cube/LL ...

Paul Andreev
Associate
November 15, 2018
__STATIC_INLINE uint8_t LL_ADC_REG_ReadConversionData6(ADC_TypeDef *ADCx)
{
 return (uint16_t)(READ_BIT(ADCx->DR, ADC_DR_DATA));
}

READ_BIT - macro.

#define READ_BIT(REG, BIT) ((REG) & (BIT))

Bitwise AND with mask. I think in func LL_ADC_REG_ReadConversion_Data6 mask shoud be 0x3F.

#define ADC_DR_DATA_Pos (0U) 
#define ADC_DR_DATA_Msk (0xFFFFU << ADC_DR_DATA_Pos) /*!< 0x0000FFFF */
#define ADC_DR_DATA ADC_DR_DATA_Msk 

Value for ADC_DR_DATA is 0xFFFF. In last func you recieve 8 bit of data from ADC. Seems LL_ADC_REG_ReadConversion_Data6 not works correctly.

AvaTar
Senior III
November 15, 2018

I don't need to see the code behind that macro - the name is already appalling enough.

As said, I have my reasons to stick with the SPL for this MCU.