This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

In App Programming STM32 problem with Image linking

Hi,

There Two programs Program A and B;
Prog A is the Application Image
Prog B suppost be bootload program
Flow chart here:
i67.tinypic.com/6o397a.png

Code for Prog A is here:

/* Includes ----------------------------------------------------*/
#include "main.h"
#include "stm32l4xx_hal.h"

/* Private function prototypes ----------------------------------*/
void SystemClock_Config(void);
void Error_Handler(void);
static void MX_GPIO_Init(void);

int main(void)
{

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();

  /* Initialize all configured peripherals */
  MX_GPIO_Init();

  while (1)
  {
     HAL_GPIO_WritePin(LED_GPIO_Port,LED_Pin,GPIO_PIN_SET);
     HAL_Delay(100);
     HAL_GPIO_WritePin(LED_GPIO_Port,LED_Pin,GPIO_PIN_RESET);
     HAL_Delay(100);
  }
}

Code for Prog B is here:

/* Private variables ----------------------------------------------*/
#define APPLICATION_ADDRESS     (uint32_t)0x08004000

uint32_t JumpAddress;
typedef  void (*pFunction)(void);
pFunction JumpToApplication;

/* Private function prototypes ------------------------------------*/
void SystemClock_Config(void);
void Error_Handler(void);
static void MX_GPIO_Init(void);

/
int main(void)
{


  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();

  /* Initialize all configured peripherals */
  MX_GPIO_Init();


  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
        if (!HAL_GPIO_ReadPin(Button_GPIO_Port,Button_Pin))
        {
            /* working*/
            HAL_GPIO_WritePin(LED_GPIO_Port,LED_Pin,GPIO_PIN_SET);
            HAL_Delay(1000);
            HAL_GPIO_WritePin(LED_GPIO_Port,LED_Pin,GPIO_PIN_RESET);
            HAL_Delay(1000);

        }else
        {
            /* Jump to user application */
      JumpAddress = *(__IO uint32_t*) (APPLICATION_ADDRESS + 4);
      JumpToApplication = (pFunction) JumpAddress;
      /* Initialize user application's Stack Pointer */
      __set_MSP(*(__IO uint32_t*) APPLICATION_ADDRESS);
      JumpToApplication();
        }}}

Prog A has Memory address assigned to 0x08004000 in system_stm32l4xx.c file using
#define VECT_TAB_OFFSET 0x4000
SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET;

After reset, when Button is Pressed MCU goes in Prog B (at 0x08000 000) and toggles LED at 1s
This works fine.
However when button is not pressed, MCU suppos to jump to 0x0800 4000 and run the code(Prog A) from there this doesn't seems to be working.

If you see the debug screen;
i63.tinypic.com/s3giaa.png

After the line:
__set_MSP(*(__IO uint32_t*) APPLICATION_ADDRESS);

the Value of SP changes from 0x2000 0410 to 0x2000 0408
0x2000 0408 is the value of mem address 0x08004000
and the of Prog A intial value while 0x2000 0410 is value of mem address 0x0800 0000 i.e. Prog B initial value.

Does that mean the Program jumps to 0x0800 4000 but is not running the code properly?