2018-02-22 09:16 AM
Hello everyone.
I'm making a custom bootloader for my stm32f107 wich jump to my application location.
My application just toggle a led using timer interuption and send me caracters using USART.
When I flash it using st-flash it works perfectly, but after the jump form bootloader not (LED is toggling slower than expected and USART send me wrong characters..)
I change the .ld of the application
ROM (rx) : ORIGIN = 0x800C000, LENGTH = 256K-0xC000
Here is my bootloader code:
&sharpdefine APPLICATION_ADDRESS 0x0800C000
typedef void (*pFunction)(void);
pFunction appEntry;uint32_t appStack, test, i;int main(void)
{__disable_irq(); // not sure of the utility
appStack = (uint32_t) *((__IO uint32_t*)APPLICATION_ADDRESS); appEntry = (pFunction) *(__IO uint32_t*) (APPLICATION_ADDRESS + 4); SCB->VTOR = APPLICATION_ADDRESS; __set_MSP(appStack);appEntry();
while(1);
return 0;
}Here is my application code:
void main()
{ __enable_irq(); NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0xC000);SetSysClockTo72();
SetupLeds();
Setup_USARTS();
SetupTimers();
while(1);
}
void SetSysClockTo72(void)
{ RCC_DeInit (); // RCC system reset(for debug purpose) RCC_HSEConfig (RCC_HSE_ON); // Enable HSE// Wait till HSE is ready
while (RCC_GetFlagStatus(RCC_FLAG_HSERDY) == RESET);RCC_HCLKConfig (RCC_SYSCLK_Div1); // HCLK = SYSCLK
RCC_PCLK2Config (RCC_HCLK_Div1); // PCLK2 = HCLK (APB2) RCC_PCLK1Config (RCC_HCLK_Div2); // PCLK1 = HCLK/2 (APB1) RCC_ADCCLKConfig (RCC_PCLK2_Div4); // ADCCLK = PCLK2/4*(vu32 *)0x40022000 = 0x01; // Flash 2 wait state
// PLLCLK = 8MHz * 9 = 72 MHz
RCC_PLLConfig ((uint32_t)0x00010000, RCC_PLLMul_9);// Enable PLL
RCC_PLLCmd (ENABLE);// Attente synchronisation PLL
while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);// Select PLL as system clock source
RCC_SYSCLKConfig (RCC_SYSCLKSource_PLLCLK);// Wait till PLL is used as system clock source
while (RCC_GetSYSCLKSource() != 0x08);//SysTick_Config(SystemCoreClock/1000);
}If anyone have a clue I would be very grateful!
I can add the rest of the code if needed!
Alex.
#system-clock #custom-bootloader #usart-tx-issue2018-02-22 09:32 AM
Could you perhaps use a debugger and step through the code and review the peripheral registers?
How about outputting the internal clocks via PA8 MCO and reviewing that with a scope?
Send a stream of 'U' characters via the USART, and scope bit timing.
It's using a 8 MHz clock, not 25 MHz, make sure the HSE_VALUE correctly reflects the source clock.
Check code in SystemInit(), this is usually called prior to main(), should set up clocks etc. Make sure that's working properly or if it has expectations of the clocking state upon entry, ie HSI. If the loader has set up clocks does app need to tear them down and restart them?