AnsweredAssumed Answered

Migration support from Standard Peripheral Libraries to STM32CubeMX

Question asked by gabriel on Dec 12, 2014
Latest reply on Dec 15, 2014 by gabriel
Hi,

I'm trying to migrate an existing project from the Standard Peripheral Libraries to the new ones and can't fine any guides. Do any exist?

As an example I'm currently trying to convert this function.

void I2C3_Configuration(void)
{
// I2C3, PA8, PC9
 
    GPIO_InitTypeDef  GPIO_InitStructure;
    I2C_InitTypeDef I2C_InitStructure;
 
    /* Enable the AHB1 peripheral clocks */
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
 
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
 
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C3, ENABLE);
 
    /* Reset I2C IP */
    RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C3, ENABLE);
 
    /* Release reset signal of I2C IP */
    RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C3, DISABLE);
 
    /* GPIO configuration */
    /* Configure GPIO pin alternate function */
    GPIO_PinAFConfig(GPIOA, GPIO_PinSource8, GPIO_AF_I2C3);
    GPIO_PinAFConfig(GPIOC, GPIO_PinSource9, GPIO_AF_I2C3);
 
    GPIO_StructInit(&GPIO_InitStructure);
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOA, &GPIO_InitStructure);
 
    GPIO_StructInit(&GPIO_InitStructure);
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOC, &GPIO_InitStructure);
 
    /*!< I2C DMA TX and RX channels configuration */
    /* Clear any pending flag on Rx Stream  */
    DMA_ClearFlag(DMA1_Stream4, DMA_FLAG_FEIF4 | DMA_FLAG_DMEIF4 | DMA_FLAG_TEIF4 | \
                                       DMA_FLAG_HTIF4 | DMA_FLAG_TCIF4);
    /* Disable the I2C Tx DMA stream */
    DMA_Cmd(DMA1_Stream4, DISABLE);
    /* Configure the DMA stream for the I2C peripheral TX direction */
    DMA_DeInit(DMA1_Stream4);
    I2C3_DMA_InitStructure.DMA_Channel = DMA_Channel_3;
    I2C3_DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)I2C3_DR_Address;
    I2C3_DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)0;    /* This parameter will be configured during communication */;
    I2C3_DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral; /* This parameter will be configured during communication */
    I2C3_DMA_InitStructure.DMA_BufferSize = 0xFFFF;              /* This parameter will be configured during communication */
    I2C3_DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
    I2C3_DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
    I2C3_DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
    I2C3_DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
    I2C3_DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
    I2C3_DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;
    I2C3_DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Enable;
    I2C3_DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_Full;
    I2C3_DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
    I2C3_DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
    DMA_Init(DMA1_Stream4, &I2C3_DMA_InitStructure);
 
    /* Clear any pending flag on Rx Stream */
    DMA_ClearFlag(DMA1_Stream2, DMA_FLAG_FEIF2 | DMA_FLAG_DMEIF2 | DMA_FLAG_TEIF2 | \
                                       DMA_FLAG_HTIF2 | DMA_FLAG_TCIF2);
    /* Disable the I2C DMA Rx stream */
    DMA_Cmd(DMA1_Stream2, DISABLE);
    /* Configure the DMA stream for the I2C peripheral RX direction */
    DMA_DeInit(DMA1_Stream2);
    DMA_Init(DMA1_Stream2, &I2C3_DMA_InitStructure);
 
    /* Enable the DMA Channels Interrupts */
    DMA_ITConfig(DMA1_Stream4, DMA_IT_TC, ENABLE);
    DMA_ITConfig(DMA1_Stream2, DMA_IT_TC, ENABLE);
 
    /* I2C configuration */
    I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
    I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
    I2C_InitStructure.I2C_OwnAddress1 = 0x00;
    I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
    I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
    I2C_InitStructure.I2C_ClockSpeed = 400000;
 
 
    /* Enable the I2C peripheral */
    I2C_Cmd(I2C3, ENABLE);
 
    /* Initialize the I2C peripheral after enabling it */
    I2C_Init(I2C3, &I2C_InitStructure);
}


Thanks,

Gabriel

Outcomes