AnsweredAssumed Answered

STM32F303xC bootloader

Question asked by Vycas.Arturas.001 on May 16, 2014
Latest reply on May 19, 2014 by Vycas.Arturas.001
Hi everyone, i'm trying to enter bootloader from my application, so i could use STM flash loader tool to upgrade software. Everything is working fine and im entering bootloader, but after i flash with flash loader tool, nothing is working, even though i get successful program verifying messages. I tried to reset processor., connecting NRST to ground after flashing with the loader, but that doesn't help. So i suppose i did something wrong with configuration, before entering bootloader and stopping all processes. Or maybe it's not a good idea to init my bootloader function in USART IRQ handler? Any advices and help which would allow me to solve this will be highly appreciated. Thanks in advance. :)

#include "stm32f30x.h"
#include "main.h"

USART_InitTypeDef USART_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;

void (*SystemMemoryBootJump) (void);
void BootLoaderInit(uint32_t BootLoaderStatus);

void USART1_Config(void)
  USART_InitStructure.USART_BaudRate = 9600; // Baud rate. Bits (or characters) per second.
  USART_InitStructure.USART_WordLength = USART_WordLength_8b; // Word lenght = 8 bits
  USART_InitStructure.USART_StopBits = USART_StopBits_1; // Use one stop bit
  USART_InitStructure.USART_Parity = USART_Parity_No ; // No parity
  USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; // Receive and transmit enabletd
  USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; // Hardware flow control disabled (RTS and CTS signals)
  USART_Init(USART1, &USART_InitStructure);
  USART_Cmd(USART1, ENABLE); // Enable USART1 parameters
  USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); // Enable Rx interrupt
  NVIC_EnableIRQ(USART1_IRQn); // Enable USART1 global interrupt

void USART1_Rx_Tx_Config(void)
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10; // use 9 and 10 pins for rx and tx
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
  GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_7);
  GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_7);

void USART1_IRQHandler(void)
  if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) // Check if interrupt has occured or not
        if((char)USART_ReceiveData(USART1) == 't') // If recieved t on rx pin , transmit T from tx pin
          GPIOE->ODR ^= GPIO_Pin_8; // Toggle led state
          USART_SendData(USART1, 'T'); // Transmit T

        if((char)USART_ReceiveData(USART1) == 0x7A)
          //USART_SendData(USART1, 0xEE);
        if((char)USART_ReceiveData(USART1) == 'o') // If recieved t on rx pin , transmit T from tx pin
          GPIOE->ODR ^= GPIO_Pin_9; // Toggle led state
          USART_SendData(USART1, 0x3C); // Transmit T


int main(void)
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); // Enable clock for port A
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOE, ENABLE); // Enable clock for port E
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); // USART1 clock enable
  // Port E pin 8 blue led configuration
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9; // use 8 pin to blink led
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; 
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOE, &GPIO_InitStructure);
  // NVIC structure for USART1 interrupt
  NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

 // USART1_IRQHandler();
     // Do nothing, all happens in ISR (Interrupt service routine)  

void BootLoaderInit(uint32_t BootLoaderStatus)
    SystemMemoryBootJump=(void (*)(void)) (*((u32 *) 0x1FFFD804));// Point PC to System Memory reset vector (+4 the offset)
  if(BootLoaderStatus == 1)
    RCC_DeInit(); // Shut down all running tasks. Set all clock configuration to the reset state
    SysTick->CTRL = 0; // Reset the system timer
    SysTick->LOAD = 0; // Reset system reload value register
    SysTick->VAL = 0; // Reset system Current value register.
  //  __set_PRIMASK(1); // Disable all interrupts
    __set_MSP(0x20001258); // Set the main stack pointer value
    SystemMemoryBootJump(); // Jump to the boot mode
 //   while(1);