cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103 - Std Periph Driver not working with bootloader

Jason Smith
Associate II
Posted on April 03, 2017 at 05:58

I am running into an issue with the ST Standard Peripheral Driver. If I download my project to my STM32F103 at Vector 0x08000000, it runs fine. If I use my bootloader to load my project to 0x08004000 (I set this in the linker tab as well), it will not work. Other projects work fine when using the bootloader but this project is my first one with the Std. Periph. Driver. Does the driver expect vector 0x08000000 somewhere that I need to edit a source or header file?

1 ACCEPTED SOLUTION

Accepted Solutions
Posted on April 08, 2017 at 06:18

Disregard. I figured it out.  I was using the Standard Peripheral Driver in my bootloader as well as my program.  I wasn't calling RCC_DeInit().  I added that right before I jump to location 0x8004000 in my bootloader and now my bootloaded program works.

View solution in original post

8 REPLIES 8
Posted on April 03, 2017 at 06:26

Make sure SCB->VTOR is set correctly in system_stm32f10x.c, see end of SystemInit(), and defines.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Jason Smith
Associate II
Posted on April 03, 2017 at 13:36

Does the periph driver use SCB->VTOR?  I don't have to set this in my other projects that bootload correctly.

Posted on April 03, 2017 at 15:39

I've told you twice that it does. 

http://www.keil.com/forum/62419/

 

>>

I don't have to set this in my other projects that bootload correctly.

But presumably you want to fix the ones that aren't working, so focus on them.

Make sure to enable interrupts if you disable them.

Make sure you service interrupts you have enabled, or turn them off before the hand-over.

SystemInit() will also tear down clocks and PLL settings, this frequently isn't required.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on April 03, 2017 at 16:19

STM32F10x_StdPeriph_Lib_V3.5.0\Project\STM32F10x_StdPeriph_Template\system_stm32f10x.c

...

/*!< Uncomment the following line if you need to relocate your vector Table in

Internal SRAM. */

/* ♯ define VECT_TAB_SRAM */

♯ define VECT_TAB_OFFSET 0x0 /*!< Vector Table base offset field.

This value must be a multiple of 0x200. */

...

/**

* @brief Setup the microcontroller system

* Initialize the Embedded Flash Interface, the PLL and update the

* SystemCoreClock variable.

* @note This function should be used only after reset.

* @param None

* @retval None

*/

void SystemInit (void)

{

...

♯ ifdef VECT_TAB_SRAM

SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM. */

♯ else

SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH. */

♯ endif

}
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on April 04, 2017 at 05:42

Sorry, I hastily read your answer and saw SRAM and thought it wasn't what I needed.  It pays to read sometimes.  Thanks for your help.

I changed VECT_TAB_OFFSET to 0x4000 and it still doesn't work.  Any ideas?

..

/*!< Uncomment the following line if you need to relocate your vector Table in

     Internal SRAM. */

/* &sharpdefine VECT_TAB_SRAM */

&sharpdefine VECT_TAB_OFFSET  0x4000 /*!< Vector Table base offset field.

                                  This value must be a multiple of 0x200. */
Posted on April 04, 2017 at 05:51

Make a simple/minimal project that demonstrates the failure, ideally complete with compiled .BIN or .HEX type file.

ZIP up and attach.

You could also try to step across the transition code, looking to see if/where thing go awry.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on April 07, 2017 at 05:56

Clive,

I can zip up what I have but I noticed this behavior only exhibits when bootloaded.  I do not know enough about keil to simulate bootloaded project.  I set the system_stm32f10x.c, Linker (linker tab), and Target (target tab) IROM Start to 0x8004000.  Will that setup cause it to be loaded to 0x8004000 and run from there simulating a bootloaded project?  I am trying to figure out if I sent you a minimal project if I need to send the bootloader as well?

  I have narrowed it down to this though:

......

void setupIO(void)

{     

    

  GPIO_InitTypeDef GPIO_InitStructure;  

  RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB , ENABLE);   <-- THIS LINE HERE CAUSES MY PROGRAM TO STOP RUNNING.                        

   

/*

    // MCU/Pwr Led

    GPIO_InitStructure.GPIO_Pin = MCULED_PIN;

    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;

    GPIO_Init(MCULED_GPIO, &GPIO_InitStructure);

*/

}

That line commented above is the what causes it my program to stop running.  I never call the setupIO function, yet, if I comment that line out my program will work.  In my main loop I have this (its nothing to do with the standard periph driver):

.....

/*----------------------------------------------------------------------------

  Main Program

 *----------------------------------------------------------------------------*/

int main (void) {

  unsigned int i;                            /* LED variable                  */

  RCC->APB2ENR |= (1UL << 3);                /* Enable GPIOB clock            */

  GPIOB->CRL    =  0x33333333;               /* PB.8..16 defined as Outputs   */

  while (1)  {                               /* Loop forever                  */

    for (i = 1<<0; i < 1<<7; i <<= 1) {     /* Blink LED 0,1,2,3,4,5,6       */

      GPIOB->BSRR = i;                       /* Turn LED on                   */

      wait ();                               /* call wait function            */

      GPIOB->BRR = i;                        /* Turn LED off                  */

    }

    for (i = 1<<7; i > 1<<0; i >>=1 ) {     /* Blink LED 7,6,5,4,3,2,1       */

      GPIOB->BSRR = i;                       /* Turn LED on                   */

      wait ();                               /* call wait function            */

      GPIOB->BRR = i;                        /* Turn LED off                  */

    }

  }

}

....

Any ideas what could be causing this?  Let me know if you stil want my program also.  Thanks for your help.

Posted on April 08, 2017 at 06:18

Disregard. I figured it out.  I was using the Standard Peripheral Driver in my bootloader as well as my program.  I wasn't calling RCC_DeInit().  I added that right before I jump to location 0x8004000 in my bootloader and now my bootloaded program works.