cancel
Showing results for 
Search instead for 
Did you mean: 

Is it me, or does I2C Fast Mode Plus kill the ADC on the STM32F030R8?

DOsbo
Senior

Hi All,

My STM32F0 happily makes multiple channel ADC conversions and transfers them using DMA. However, when I flick the I2C into Fast Mode Plus mode (1Mb/s), there's no ADC conversions or transfers. It actually generates a DMA overrun, but there are no ADC transfers to begin with. The I2C Fast Mode plays nice, but not Fast Mode Plus. The strange thing is the I2C isn't even running - its just configured but not started.

So is it me, or the chip, or the hal?

Cheers

David

1 REPLY 1
DOsbo
Senior

And the answer is: The HAL.

In the header stm32f0xx_hal_i2c_ex.h it contains this code:

#define I2C_FMP_NOT_SUPPORTED      0xAAAA0000U                    /*!< Fast Mode Plus not supported       */
 
#if defined(SYSCFG_CFGR1_I2C_FMP_I2C1)
#define I2C_FASTMODEPLUS_I2C1      SYSCFG_CFGR1_I2C_FMP_I2C1      /*!< Enable Fast Mode Plus on I2C1 pins */
#else
#define I2C_FASTMODEPLUS_I2C1      (uint32_t)(0x00000100U | I2C_FMP_NOT_SUPPORTED) /*!< Fast Mode Plus I2C1 not supported  */
#endif
#if defined(SYSCFG_CFGR1_I2C_FMP_I2C2)
#define I2C_FASTMODEPLUS_I2C2      SYSCFG_CFGR1_I2C_FMP_I2C2      /*!< Enable Fast Mode Plus on I2C2 pins */
#else
#define I2C_FASTMODEPLUS_I2C2      (uint32_t)(0x00000200U | I2C_FMP_NOT_SUPPORTED) /*!< Fast Mode Plus I2C2 not supported  */
#endif

In main.c

static void MX_I2C1_Init(void)
{
 .
.
   /** I2C Fast mode Plus enable 
  */
  __HAL_SYSCFG_FASTMODEPLUS_ENABLE(I2C_FASTMODEPLUS_I2C1);
 }

When FM+ is enabled in STM32CubeMX, it generates code that writes (uint32_t)(0x00000100U | I2C_FMP_NOT_SUPPORTED) into SYSCFG_CFGR1. What's wrong with that?

  1. FM+ is supported on STM32F030R8 (I2C1 port b pins).
  2. The 0x00000100U part is also incorrect. That bit position remaps ADC_DMA to channel 2 which effectively kills ADC_DMA if you were unaware of the remapping (like me).

In my opinion randomly writing 0xAAAA0000 into a register is not a good way of showing something is not supported (even though it is supported). Try something like:

#error "FM+ is not supported on this micro". Also remapping DMA channels without telling people isn't a good idea.

One last thing. Thank you to the person who added the tags to my initial post. In my tiredness I neglected to add them myself. Thank you mystery tag adding person 😉

Cheers

David