2022-05-24 09:41 PM
Hello,
I'm trying to do the memory position jump using this code:
JumpAddress = *(__IO uint32_t*) (APPLICATION_ADDRESS + 4);
Jump_To_Application = (pFunction) JumpAddress;
__set_MSP(*(__IO uint32_t*) (APPLICATION_ADDRESS ));
Jump_To_Application();
I managed to make it work with only one GPIO, but when I add peripherals in the bootloader, it no longer works.
I'm trying to de-initialize the peripheral, a UART has this reference (stm32f4xx_hal_uart.c):
/**
* @brief DeInitializes the UART peripheral.
* @param huart Pointer to a UART_HandleTypeDef structure that contains
* the configuration information for the specified UART module.
* @retval HAL status
*/
HAL_StatusTypeDef HAL_UART_DeInit(UART_HandleTypeDef *huart)
{
/* Check the UART handle allocation */
if (huart == NULL)
{
return HAL_ERROR;
}
/* Check the parameters */
assert_param(IS_UART_INSTANCE(huart->Instance));
huart->gState = HAL_UART_STATE_BUSY;
/* Disable the Peripheral */
__HAL_UART_DISABLE(huart);
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
if (huart->MspDeInitCallback == NULL)
{
huart->MspDeInitCallback = HAL_UART_MspDeInit;
}
/* DeInit the low level hardware */
huart->MspDeInitCallback(huart);
#else
/* DeInit the low level hardware */
HAL_UART_MspDeInit(huart);
#endif /* (USE_HAL_UART_REGISTER_CALLBACKS) */
huart->ErrorCode = HAL_UART_ERROR_NONE;
huart->gState = HAL_UART_STATE_RESET;
huart->RxState = HAL_UART_STATE_RESET;
huart->ReceptionType = HAL_UART_RECEPTION_STANDARD;
/* Process Unlock */
__HAL_UNLOCK(huart);
return HAL_OK;
}
When I look for the reference of HAL_UART_MspDeInit, this appears (stm32f4xx_hal_uart.c):
/**
* @brief UART MSP DeInit.
* @param huart Pointer to a UART_HandleTypeDef structure that contains
* the configuration information for the specified UART module.
* @retval None
*/
__weak void HAL_UART_MspDeInit(UART_HandleTypeDef *huart)
{
/* Prevent unused argument(s) compilation warning */
UNUSED(huart);
/* NOTE: This function should not be modified, when the callback is needed,
the HAL_UART_MspDeInit could be implemented in the user file
*/
}
But there is another reference implemented (stm32f4xx_hal_msp.c):
/**
* @brief UART MSP De-Initialization
* This function freeze the hardware resources used in this example
* @param huart: UART handle pointer
* @retval None
*/
void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
{
if(huart->Instance==USART1)
{
/* USER CODE BEGIN USART1_MspDeInit 0 */
/* USER CODE END USART1_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_USART1_CLK_DISABLE();
/**USART1 GPIO Configuration
PA9 ------> USART1_TX
PA10 ------> USART1_RX
*/
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9|GPIO_PIN_10);
/* USER CODE BEGIN USART1_MspDeInit 1 */
/* USER CODE END USART1_MspDeInit 1 */
}
}
How should I de-initialize these peripherals?
Solved! Go to Solution.
2022-05-25 08:02 PM
I found (Google found) some references that worked
Google found this one: "when I run the below code block (that works in STM32)"
The code that worked:
uint32_t JumpAddress;
typedef void (*pFunction)(void);
pFunction Jump_To_Application;
#define APPLICATION_ADDRESS (uint32_t)0x08008000
HAL_RCC_DeInit();
JumpAddress = *(__IO uint32_t*) (APPLICATION_ADDRESS + 4);
Jump_To_Application = (pFunction) JumpAddress;
SCB->VTOR = APPLICATION_ADDRESS;
__set_MSP(*(__IO uint32_t*) (APPLICATION_ADDRESS ));
Jump_To_Application();
USART1 initialization uses these instructions:
UART_HandleTypeDef huart1;
huart1.Instance = USART1;
huart1.Init.BaudRate = 115200;
huart1.Init.WordLength = UART_WORDLENGTH_8B;
huart1.Init.StopBits = UART_STOPBITS_1;
huart1.Init.Parity = UART_PARITY_NONE;
huart1.Init.Mode = UART_MODE_TX_RX;
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
if (HAL_UART_Init(&huart1) != HAL_OK) {
Error_Handler();
}
When operating on this reference type UART_HandleTypeDef, the code execution failed. If I left any of these lines it would no longer work:
huart1.Instance = USART1;
huart1.Init.BaudRate = 115200;
huart1.Init.WordLength = UART_WORDLENGTH_8B;
huart1.Init.StopBits = UART_STOPBITS_1;
huart1.Init.Parity = UART_PARITY_NONE;
huart1.Init.Mode = UART_MODE_TX_RX;
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
The instruction that resolved was this:
SCB->VTOR = APPLICATION_ADDRESS;
Ref.:
[How to Create a Super Simple Bootloader]
https://www.youtube.com/playlist?list=PLnMKNibPkDnEb1sphpdFJ3bR9dNy7S6mO
[STM32 USB training - 11.3 USB MSC DFU host labs]
https://www.youtube.com/watch?v=CGUC1wqSLCE
[STM32 USB training - 09.9 USB DFU device labs]
2022-05-25 02:29 AM
"when I add peripherals in the bootloader, it no longer works"
What, exactly, "doesn't work", and how do you detect that?
What symptoms do you observe?
What debugging have you done to see what's going on?
2022-05-25 08:02 PM
I found (Google found) some references that worked
Google found this one: "when I run the below code block (that works in STM32)"
The code that worked:
uint32_t JumpAddress;
typedef void (*pFunction)(void);
pFunction Jump_To_Application;
#define APPLICATION_ADDRESS (uint32_t)0x08008000
HAL_RCC_DeInit();
JumpAddress = *(__IO uint32_t*) (APPLICATION_ADDRESS + 4);
Jump_To_Application = (pFunction) JumpAddress;
SCB->VTOR = APPLICATION_ADDRESS;
__set_MSP(*(__IO uint32_t*) (APPLICATION_ADDRESS ));
Jump_To_Application();
USART1 initialization uses these instructions:
UART_HandleTypeDef huart1;
huart1.Instance = USART1;
huart1.Init.BaudRate = 115200;
huart1.Init.WordLength = UART_WORDLENGTH_8B;
huart1.Init.StopBits = UART_STOPBITS_1;
huart1.Init.Parity = UART_PARITY_NONE;
huart1.Init.Mode = UART_MODE_TX_RX;
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
if (HAL_UART_Init(&huart1) != HAL_OK) {
Error_Handler();
}
When operating on this reference type UART_HandleTypeDef, the code execution failed. If I left any of these lines it would no longer work:
huart1.Instance = USART1;
huart1.Init.BaudRate = 115200;
huart1.Init.WordLength = UART_WORDLENGTH_8B;
huart1.Init.StopBits = UART_STOPBITS_1;
huart1.Init.Parity = UART_PARITY_NONE;
huart1.Init.Mode = UART_MODE_TX_RX;
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
The instruction that resolved was this:
SCB->VTOR = APPLICATION_ADDRESS;
Ref.:
[How to Create a Super Simple Bootloader]
https://www.youtube.com/playlist?list=PLnMKNibPkDnEb1sphpdFJ3bR9dNy7S6mO
[STM32 USB training - 11.3 USB MSC DFU host labs]
https://www.youtube.com/watch?v=CGUC1wqSLCE
[STM32 USB training - 09.9 USB DFU device labs]
2022-05-25 08:04 PM
About the reference below, just comment it and the IDE redirected to the other implementation
__weak void HAL_UART_MspDeInit(UART_HandleTypeDef *huart)
2022-05-25 08:48 PM