[HAL][USART] Remove __HAL_LOCK() and __HAL_UNLOCK() invocation from both HAL_xxx_RegisterCallback() and HAL_xxx_UnRegisterCallback() Rationale: HAL_xxx_RegisterCallback() must be called before HAL_xxx_Init(), which creates the semaphore used when invoking __HAL_LOCK() and __HAL_UNLOCK(). Invoking __HAL_LOCK() and __HAL_UNLOCK() in HAL_xxx_RegisterCallback() means using the semaphore before its creation.
diff --git a/Src/stm32f7xx_hal_usart.c b/Src/stm32f7xx_hal_usart.c index 99c43b0..a327647 100644 --- a/Src/stm32f7xx_hal_usart.c +++ b/Src/stm32f7xx_hal_usart.c
@@ -394,6 +394,8 @@ /** * @brief Register a User USART Callback * To be used instead of the weak predefined callback + * @note The HAL_USART_RegisterCallback() may be called before HAL_USART_Init() in HAL_USART_STATE_RESET + * to register callbacks for HAL_USART_MSPINIT_CB_ID and HAL_USART_MSPDEINIT_CB_ID * @param husart usart handle * @param CallbackID ID of the callback to be registered * This parameter can be one of the following values: @@ -421,8 +423,6 @@ return HAL_ERROR; } - /* Process locked */ - __HAL_LOCK(husart); if (husart->State == HAL_USART_STATE_READY) { @@ -504,15 +504,14 @@ status = HAL_ERROR; } - /* Release Lock */ - __HAL_UNLOCK(husart); - return status; } /** * @brief Unregister an USART Callback * USART callaback is redirected to the weak predefined callback + * @note The HAL_USART_UnRegisterCallback() may be called before HAL_USART_Init() in HAL_USART_STATE_RESET + * to un-register callbacks for HAL_USART_MSPINIT_CB_ID and HAL_USART_MSPDEINIT_CB_ID * @param husart usart handle * @param CallbackID ID of the callback to be unregistered * This parameter can be one of the following values: @@ -531,9 +530,6 @@ { HAL_StatusTypeDef status = HAL_OK; - /* Process locked */ - __HAL_LOCK(husart); - if (HAL_USART_STATE_READY == husart->State) { switch (CallbackID) @@ -614,9 +610,6 @@ status = HAL_ERROR; } - /* Release Lock */ - __HAL_UNLOCK(husart); - return status; } #endif /* USE_HAL_USART_REGISTER_CALLBACKS */