2021-12-13 09:06 AM
I am writing a code to jump to another application in the flash. In the last step I am initiating peripherals. My question is related if it is sure to de init peripherals without disable the peripheral first. Example:
LL_CRC_DeInit(CRC);
LL_AHB1_GRP1_DisableClock(LL_AHB1_GRP1_PERIPH_CRC);
LL_USART_DeInit(E22_UART);
In Usart part of code, I am not disabling the peripheral. It uses dma, so I think dma should be de initialited first.
Also, is it necessary disable the peripheral clock after de initialization process?
2021-12-13 09:15 AM
If your code uses interrupts, you need to disable those from happening as the vector table will probably be incorrect shortly after you jump.
If you are using DMA, you will need to deinitialize or stop that as the buffers will be out of scope after the jump.
A quick way to deinitialize would be:
__HAL_RCC_USART1_FORCE_RESET();
__HAL_RCC_DMA2_FORCE_RESET();
__HAL_RCC_DMA2_RELEASE_RESET();
__HAL_RCC_USART1_RELEASE_RESET();
> My question is related if it is sure to de init peripherals without disable the peripheral first.
Deinitializing in this manner also disables the peripheral. It's fine to do both simultaneously.
2021-12-13 09:33 AM
this is my final code:
// de init crc
LL_CRC_DeInit(CRC);
LL_AHB1_GRP1_DisableClock(LL_AHB1_GRP1_PERIPH_CRC);
// de init dma
LL_DMA_DeInit(_E22_DMA, _E22_DMA_STREAM_RX);
LL_DMA_DeInit(_E22_DMA, _E22_DMA_STREAM_TX);
LL_DMA_DeInit(_FLASH_EXT_DMA, _FLASH_EXT_DMA_STREAM_RX);
LL_DMA_DeInit(_FLASH_EXT_DMA, _FLASH_EXT_DMA_STREAM_TX);
LL_AHB1_GRP1_DisableClock(LL_AHB1_GRP1_PERIPH_DMA2);
// de init e22 usart
LL_USART_DeInit(E22_UART);
LL_APB2_GRP1_DisableClock(LL_APB2_GRP1_PERIPH_USART1);
// de init flash ext spi
LL_SPI_DeInit(FLASH_EXT_SPI);
LL_APB2_GRP1_DisableClock(LL_APB2_GRP1_PERIPH_SPI1);
// de init dev serial usart
LL_USART_DeInit(DEV_SERIAL_UART);
LL_APB2_GRP1_DisableClock(LL_APB2_GRP1_PERIPH_USART6);
// de init gpios
LL_GPIO_DeInit(GPIOE);
LL_GPIO_DeInit(GPIOC);
LL_GPIO_DeInit(GPIOH);
LL_GPIO_DeInit(GPIOA);
LL_GPIO_DeInit(GPIOB);
LL_GPIO_DeInit(GPIOD);
LL_AHB1_GRP1_DisableClock(LL_AHB1_GRP1_PERIPH_GPIOE);
LL_AHB1_GRP1_DisableClock(LL_AHB1_GRP1_PERIPH_GPIOC);
LL_AHB1_GRP1_DisableClock(LL_AHB1_GRP1_PERIPH_GPIOH);
LL_AHB1_GRP1_DisableClock(LL_AHB1_GRP1_PERIPH_GPIOA);
LL_AHB1_GRP1_DisableClock(LL_AHB1_GRP1_PERIPH_GPIOB);
LL_AHB1_GRP1_DisableClock(LL_AHB1_GRP1_PERIPH_GPIOD);
I am using idle interrupt for usart. I am not catching your idea about de initialize interrupt. It is not perform automatically when I de init the usart?
Do you mean this for instance:
NVIC_DisableIRQ(USART1_IRQn);
2021-12-13 11:43 AM
You don't technically have to tear everything down to transfer control/ownership.
The criticality with HAL is a) the instances, and b) the interrupt handling. At the Low Level hand-off can be done, especially with clocks, PLLs, external memories and GPIO, etc.