2019-08-28 03:39 AM
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
2019-08-28 08:54 PM
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?
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