Skip to main content
Md Mubdiul Hasan
Associate III
December 26, 2016
Question

What to do with HAL MSP initialization process?

  • December 26, 2016
  • 3 replies
  • 3973 views
Posted on December 26, 2016 at 02:08

Dear Sir,

According to user manual,UM1785, (Description of STM32F0xx HAL and Low-layer drivers)

stm32f0xx_hal_msp.c filecontains the MSP initialization and de-initialization (main routine and callbacks) of the peripheral used in the user application.

Its written that, ' It can be generated automatically by STM32CubeMX tool and further modified.'

I have generated my

stm32f0xx_hal_msp.c usingSTM32CubeMX as,

* Includes ------------------------------------------------------------------*/
#include 'stm32f0xx_hal.h'
extern void Error_Handler(void);
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/**
 * Initializes the Global MSP.
 */
void HAL_MspInit(void)
{
 /* USER CODE BEGIN MspInit 0 */
/* USER CODE END MspInit 0 */
__HAL_RCC_SYSCFG_CLK_ENABLE();
/* System interrupt init*/
 /* SVC_IRQn interrupt configuration */
 HAL_NVIC_SetPriority(SVC_IRQn, 0, 0);
 /* PendSV_IRQn interrupt configuration */
 HAL_NVIC_SetPriority(PendSV_IRQn, 0, 0);
 /* SysTick_IRQn interrupt configuration */
 HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
/* USER CODE BEGIN MspInit 1 */
/* USER CODE END MspInit 1 */
}
 but, the project I am going to work its stm32f0xx_hal_msp.c is different, 
#include 'stm32f0xx_hal.h'
extern void Error_Handler(void);
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/**
 * Initializes the Global MSP.
 */
void HAL_MspInit(void)
{
 /* USER CODE BEGIN MspInit 0 */
/* USER CODE END MspInit 0 */
__HAL_RCC_SYSCFG_CLK_ENABLE();
/* System interrupt init*/
 /* SVC_IRQn interrupt configuration */
 HAL_NVIC_SetPriority(SVC_IRQn, 0, 0);
 /* PendSV_IRQn interrupt configuration */
 HAL_NVIC_SetPriority(PendSV_IRQn, 0, 0);
 /* SysTick_IRQn interrupt configuration */
 HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
/* USER CODE BEGIN MspInit 1 */
/* USER CODE END MspInit 1 */
}
void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
{
GPIO_InitTypeDef GPIO_InitStruct;
 if(hspi->Instance==SPI1)
 {
 /* USER CODE BEGIN SPI1_MspInit 0 */
/* USER CODE END SPI1_MspInit 0 */
 /* Peripheral clock enable */
 __HAL_RCC_SPI1_CLK_ENABLE();
 
 /**SPI1 GPIO Configuration 
 PA7 ------> SPI1_MOSI
 PB3 ------> SPI1_SCK
 PB4 ------> SPI1_MISO 
 */
 GPIO_InitStruct.Pin = GPIO_PIN_7;
 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
 GPIO_InitStruct.Pull = GPIO_NOPULL;
 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
 GPIO_InitStruct.Alternate = GPIO_AF0_SPI1;
 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_3|GPIO_PIN_4;
 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
 GPIO_InitStruct.Pull = GPIO_NOPULL;
 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
 GPIO_InitStruct.Alternate = GPIO_AF0_SPI1;
 HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/* USER CODE BEGIN SPI1_MspInit 1 */
/* USER CODE END SPI1_MspInit 1 */
 }
}
void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi)
{
if(hspi->Instance==SPI1)
 {
 /* USER CODE BEGIN SPI1_MspDeInit 0 */
/* USER CODE END SPI1_MspDeInit 0 */
 /* Peripheral clock disable */
 __HAL_RCC_SPI1_CLK_DISABLE();
 
 /**SPI1 GPIO Configuration 
 PA7 ------> SPI1_MOSI
 PB3 ------> SPI1_SCK
 PB4 ------> SPI1_MISO 
 */
 HAL_GPIO_DeInit(GPIOA, GPIO_PIN_7);
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_3|GPIO_PIN_4);
}
�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

I have number of question?

1. What difference you find comparing each other?

2. Second example is done forperipheral needs to be de-initialized during the program execution?

3. Let me know whyHal_MspInit() and MSP De-Initialization is done for SPI1 ?

4. Can not we add those things main.c for SPI1 and keep the first code example as it is?

Help me please.

#hal-drivers
This topic has been closed for replies.

3 replies

Nesrine M_O
Associate
December 26, 2016
Posted on December 26, 2016 at 09:48

Hi

Hasan.Md_Mubdiul

‌,

The peripheral initialization is done through HAL_PPP_Init() while the hardware resources initialization used by a peripheral (PPP) is performed during this initialization by calling MSP callback function HAL_PPP_MspInit(). The MspInit callback performs the low level initialization related to the different additional hardware resources: RCC, GPIO, NVIC and DMA.

Please refer toHAL MSP initialization process section in the

http://www.st.com/content/ccc/resource/technical/document/user_manual/2f/77/25/0f/5c/38/48/80/DM00122pdf/files/DM00122pdf/jcr:content/translations/en.DM00122pdf

To format source code, click on ''More >> Syntax Highlighter'':

0690X00000605yFQAQ.png

-Nesrine-

Md Mubdiul Hasan
Associate III
December 27, 2016
Posted on December 27, 2016 at 01:13

Hi Nesrine,

Thank you for your response here.

The MspInit callback performs the low level initialization related to the different additional hardware resources: RCC, GPIO, NVIC and DMA.

I understand while reading the manual. Did you read my question below number 3 and 4?

Kindly take a look carefully.