STM32F7 FMC/SDRAM deinitialization problem
Hi,
I'm writing a custom bootloader that reads a *.dfu file from an USB memory stick and programs the internal/external flash accordingly.
So far, everything is working fine... I've tested it on an Nucleo STM32F767 and on a STM32F746G-DISCO and I can successfully update my applications just by putting the new *.dfu on a USB MSC.
The only problem I'm facing is with the FMC controller...if it's not used/initialized in the bootloader, jumping to applications works fine... if the bootloader initialize the FMC, then jumping to the application at the end of the boot process fails...
The question is: how am I supposed to de-initialize the FMC ? as I'm using the external SDRAM of the STM32F746G-DISCO, calling HAL_SDRAM_DeInit() is enough ?
Reported below is my jump-code...
any ideas ?
thanks a lot,
Giampaolo
void executeApplicationCode(void)
{
uint32_t appStack;
pFunction appEntry;
#if 0
// SysTick is not used so far...
SysTick->CTRL = 0;
SysTick->LOAD = 0;
SysTick->VAL = 0;
#endif
HAL_RCC_DeInit();
HAL_DeInit();
// FPU settings
#if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2)); // set CP10 and CP11 Full Access
#endif
// Reset the RCC clock configuration to the default reset state
RCC->CR |= (uint32_t)0x00000001; // Set HSION bit
RCC->CFGR = 0x00000000; // Reset CFGR register
RCC->CR &= (uint32_t)0xFEF6FFFF; // Reset HSEON, CSSON and PLLON bits
RCC->PLLCFGR = 0x24003010; // Reset PLLCFGR register
RCC->CR &= (uint32_t)0xFFFBFFFF; // Reset HSEBYP bit
RCC->CIR = 0x00000000; // Disable all interrupts
#if 0
__disable_irq();
#endif
// get the application stack pointer
appStack = (uint32_t) * ((__IO uint32_t*)APPLICATION_ADDRESS);
// get the application entry point
appEntry = (pFunction) * (__IO uint32_t*) (APPLICATION_ADDRESS + 4);
// reconfigure vector table offset
SCB->VTOR = APPLICATION_ADDRESS;
// initialize user application's Stack Pointer
__set_MSP(appStack);
// jump to application address
appEntry();
}and here is my de-initialization function (invoked before jumping to the app):
void peripheralsDeinitialize(void)
{
HAL_DisableFMCMemorySwapping();
// HAL_DisableMemorySwappingBank();
SCB_DisableICache();
SCB_DisableDCache();
// MX_USB_HOST_Init();
USBH_DeInit(&hUsbHostFS);
// MX_FATFS_Init();
// MX_USART6_UART_Init();
HAL_UART_DeInit(&huart6);
// tengo la seriale 1 attiva per il debug
// MX_USART1_UART_Init();
// HAL_UART_DeInit(&huart1);
// MX_TIM8_Init();
HAL_TIM_Base_DeInit(&htim8);
// MX_TIM5_Init();
HAL_TIM_Base_DeInit(&htim5);
// MX_TIM3_Init();
HAL_TIM_Base_DeInit(&htim3);
// MX_TIM2_Init();
HAL_TIM_Base_DeInit(&htim2);
// MX_TIM1_Init();
HAL_TIM_Base_DeInit(&htim1);
// MX_QUADSPI_Init();
HAL_QSPI_DeInit(&hqspi);
// MX_LTDC_Init();
HAL_LTDC_DeInit(&hltdc);
// MX_GFXSIMULATOR_Init();
// MX_FMC_Init(); // WARNING! se e' presente, il bootloader non e' in grado di lanciare correttamente il testTouchGFX_03 HAL_SDRAM_DeInit()
HAL_SDRAM_DeInit(&hsdram1); // non avendo inizializzato l'FMC, non lo deinizializzo neppure...
// MX_DMA2D_Init();
HAL_DMA2D_DeInit(&hdma2d);
// MX_DCMI_Init();
HAL_DCMI_DeInit(&hdcmi);
// MX_ADC3_Init();
HAL_ADC_DeInit(&hadc3);
// MX_GPIO_Init();
#if 0
__HAL_RCC_GPIOA_CLK_DISABLE();
__HAL_RCC_GPIOB_CLK_DISABLE();
__HAL_RCC_GPIOC_CLK_DISABLE();
__HAL_RCC_GPIOD_CLK_DISABLE();
__HAL_RCC_GPIOG_CLK_DISABLE();
__HAL_RCC_GPIOH_CLK_DISABLE();
__HAL_RCC_USART3_CLK_DISABLE();
#endif
}