cancel
Showing results for 
Search instead for 
Did you mean: 

Migration support from Standard Peripheral Libraries to STM32CubeMX

gabrielharrison
Associate II
Posted on December 12, 2014 at 11:46

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 #throw-away-rewrite-debug
2 REPLIES 2
Posted on December 12, 2014 at 14:23

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?

Yeah, well you see the problem here is that Cube/HAL uses a completely different paradigm, you're going to have to rewrite everything. So the trick would be to learn how to use Cube/HAL, and then ponder how you can do what you had previously done with this new model.

[DEAD LINK /public/STe2ecommunities/mcu/Lists/STM32Java/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/STM32Java/Any%20app%20note%20%20guide%20on%20migrating%20from%20STM32F2%20std.%20periph.%20lib.%20to%20HAL&FolderCTID=0x01200200770978C69A1141439FE559EB459D758000F9A0E3A95BA69146A17C2E80209ADC21&currentviews=279]https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Java/Flat.aspx?RootFolder=%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2FSTM32Java%2FAny%20app%20note%20%20guide%20on%20migrating%20from%20STM32F2%20std.%20periph.%20lib.%20to%20HAL&FolderCTID=0x01200200770978C69A1141439FE559EB459D758000F9A0E3A95BA69146A17C2E80209ADC21¤tviews=279
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
gabrielharrison
Associate II
Posted on December 15, 2014 at 11:56

Thanks,

In that case is there any documentation that describes the old and new library structures in detail?

For example it took be a while to work out

__HAL_FREEZE_IWDG_DBGMCU() has replaced  DBGMCU_APB1PeriphConfig(DBGMCU_IWDG_STOP, ENABLE)

Thanks,

Gabriel