你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

请教下,使用 iap 程序跳转 运行失败 ?

[复制链接]
hpdell 提问时间:2017-12-11 12:14 /
阅读主题, 点击返回1楼
收藏 评论38 发布时间:2017-12-11 12:14
38个回答
hpdell 回答时间:2017-12-13 09:41:44
eagle0754 发表于 2017-12-13 08:35
The stack pointer for stack 'CSTACK' (currently 0x20022CD8) is outside the stack range (0x200003B0 t ...

好的,多谢多谢啊
hpdell 回答时间:2017-12-13 09:48:43
eagle0754 发表于 2017-12-13 08:35
The stack pointer for stack 'CSTACK' (currently 0x20022CD8) is outside the stack range (0x200003B0 t ...

你好,我放在 app 地址 的值如下:

0x08020000 - 0x08080000 表示 app的起始地址  
  // 根据不同的 用户 app 的地址,仿真得到的结果值
  JumpAddress = ((*(__IO uint32_t*) 0x08080000 ) & 0x2FFE0000 );  // = 0x20020000 仿真后得到的结果值
  
  JumpAddress = ((*(__IO uint32_t*) 0x08060000 ) & 0x2FFE0000 );   // = 0x2FFE0000 仿真后得到的结果值
  
  JumpAddress = ((*(__IO uint32_t*) 0x08040000 ) & 0x2FFE0000 );   // = 0x2D700000 仿真后得到的结果值
  
  JumpAddress = ((*(__IO uint32_t*) 0x08020000 ) & 0x2FFE0000 );   // = 0x2F3E0000 仿真后得到的结果值

这个又说明什么情况啊 ??
任风吹吹 回答时间:2017-12-13 10:24:23
楼主,你的option byte nDBANK的值多少?
wofei1314 回答时间:2017-12-13 11:40:13
  1. /**
  2.   ******************************************************************************
  3.   * @file    GPIO/Boot_From_Flash_AXIM_Sectors/Src/main.c
  4.   * @author  MCD Application Team
  5.   * @version V0.1.0
  6.   * @date    15-January-2015
  7.   * @brief   This example describes how to configure STM32F7xx to boot from Flash AXI sector 0 or sector 2
  8.                                                  trought the Tamper button.
  9.   ******************************************************************************
  10.   * @attention
  11.   *
  12.   * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
  13.   *
  14.   * Redistribution and use in source and binary forms, with or without modification,
  15.   * are permitted provided that the following conditions are met:
  16.   *   1. Redistributions of source code must retain the above copyright notice,
  17.   *      this list of conditions and the following disclaimer.
  18.   *   2. Redistributions in binary form must reproduce the above copyright notice,
  19.   *      this list of conditions and the following disclaimer in the documentation
  20.   *      and/or other materials provided with the distribution.
  21.   *   3. Neither the name of STMicroelectronics nor the names of its contributors
  22.   *      may be used to endorse or promote products derived from this software
  23.   *      without specific prior written permission.
  24.   *
  25.   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  26.   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  27.   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  28.   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  29.   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  30.   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  31.   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  32.   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  33.   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  34.   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35.   *
  36.   ******************************************************************************
  37.   */

  38. /* Includes ------------------------------------------------------------------*/
  39. #include "main.h"

  40. /** @addtogroup STM32F7xx_HAL_Examples
  41.   * @{
  42.   */

  43. /** @addtogroup GPIO_IOToggle
  44.   * @{
  45.   */
  46. uint32_t boot_Address_Var = 0;

  47. /* Private typedef -----------------------------------------------------------*/
  48. /* Private define ------------------------------------------------------------*/
  49. /* Private macro -------------------------------------------------------------*/
  50. /* Private variables ---------------------------------------------------------*/
  51. //static GPIO_InitTypeDef  GPIO_InitStruct;

  52. /* Private function prototypes -----------------------------------------------*/
  53. void SystemClock_Config(void);
  54. static void Error_Handler(void);
  55. FLASH_OBProgramInitTypeDef pOBInit;
  56. static void BSP_LCD_Config(void);
  57. /* Private functions ---------------------------------------------------------*/

  58. /**
  59.   * @brief  Main program
  60.   * @param  None
  61.   * @retval None
  62.   */
  63. int main(void)
  64. {
  65.   /* This sample code shows how to use GPIO HAL API to toggle GPIOA-GPIO_PIN_0 IO
  66.     in an infinite loop. It is possible to connect a LED between GPIOA-GPIO_PIN_0
  67.     output and ground via a 330ohm resistor to see this external LED blink.
  68.     Otherwise an oscilloscope can be used to see the output GPIO signal */

  69.   /* STM32F7xx HAL library initialization:
  70.        - Configure the Flash prefetch
  71.        - Systick timer is configured by default as source of time base, but user
  72.          can eventually implement his proper time base source (a general purpose
  73.          timer for example or other time source), keeping in mind that Time base
  74.          duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and
  75.          handled in milliseconds basis.
  76.        - Set NVIC Group Priority to 4
  77.        - Low Level Initialization
  78.      */
  79.   if (HAL_Init() != HAL_OK)
  80.   {
  81.     Error_Handler();
  82.   }

  83.   /* Configure the system clock to 200 MHz */
  84.   SystemClock_Config();
  85.        
  86.   /* Configure Tamper push-button  and LEDs*/
  87.   BSP_PB_Init(BUTTON_WAKEUP, BUTTON_MODE_EXTI);
  88.        
  89.   /* LED init*/
  90.   BSP_LED_Init(LED1);
  91.   //BSP_LED_Init(LED2);
  92.   //BSP_LED_Init(LED3);
  93.   //BSP_LED_Init(LED4);
  94.   
  95.   BSP_LCD_Config();
  96.        
  97. //  /*##-1- Initialize the LCD #################################################*/
  98. //  /* Initialize the LCD */
  99. //  BSP_LCD_Init();
  100. //
  101. //  /* Initialise the LCD Layers */
  102. //  BSP_LCD_LayerDefaultInit(1, LCD_FB_START_ADDRESS);
  103. //  /* Set LCD Foreground Layer  */
  104. //  BSP_LCD_SelectLayer(1);
  105. //
  106. //  /* Set LCD font */
  107. //  BSP_LCD_SetFont(&Font20);
  108. //
  109. //  /*##-2- Display messages on LCD ############################################*/
  110. //  /* Clear the LCD */
  111. //  BSP_LCD_SetBackColor(LCD_COLOR_WHITE);
  112. //  BSP_LCD_Clear(LCD_COLOR_WHITE);
  113. //
  114. //  /* Set the LCD Text Color */
  115. //  BSP_LCD_SetTextColor(LCD_COLOR_DARKBLUE);
  116. //
  117. //  /* Display test name on LCD */
  118. //  BSP_LCD_DisplayStringAtLine(0, (uint8_t *)"     STM32F746xx Training    ");
  119. //  BSP_LCD_DisplayStringAtLine(2, (uint8_t *)"      Press User Button    ");
  120. //  BSP_LCD_DisplayStringAtLine(3, (uint8_t *)"   To configure BOOT Option bytes  ");
  121.          
  122.   /* Get BOOt_ADD0 option bytes value bytes */
  123.   pOBInit.OptionType = OPTIONBYTE_BOOTADDR_0;       
  124.   pOBInit.BootAddr0 = FLASH->OPTCR1 & 0x0000FFFF;//0x0 - 0x2004 ffff之间任何的地址,以16kb为间隔

  125.   while (1)
  126.   {                         
  127.                  while (boot_Address_Var == 0)
  128.                  {
  129.                         if((pOBInit.BootAddr0 | OB_BOOTADDR_AXIM_FLASH) == OB_BOOTADDR_AXIM_FLASH)
  130.                         {
  131.                                 BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
  132.                                 BSP_LCD_DisplayStringAtLine(6, (uint8_t *)"   Boot from Flash_AXI sector0 ");                               
  133.                                 BSP_LCD_DisplayStringAtLine(7, (uint8_t *)"      LED1 is blinking     ");
  134.                        
  135.                                  /* Toggle LED1 */                               
  136.                                  BSP_LED_Toggle(LED1);                                               
  137.                                  /* Insert delay 100 ms */
  138.                                  HAL_Delay(100);
  139.                         }       
  140.                         else
  141.                         {                                
  142.                                 BSP_LCD_SetTextColor(LCD_COLOR_BLUE);
  143.                                 BSP_LCD_DisplayStringAtLine(6, (uint8_t *)"   Boot from Flash_AXI sector2 ");
  144.                                 BSP_LCD_DisplayStringAtLine(7, (uint8_t *)"      LED1 is on     ");
  145.                                
  146.                                 /* Toggle LED4 */                               
  147.                                  BSP_LED_On(LED1);
  148.                                  /* Insert delay 100 ms */
  149.                                  //HAL_Delay(100);               
  150.                         }
  151.                 }
  152.        
  153.                 /* Check current option bytes value and re-configure boot address*/
  154.                 if((pOBInit.BootAddr0 | OB_BOOTADDR_AXIM_FLASH) == OB_BOOTADDR_AXIM_FLASH)
  155.                 {
  156.                         /* Configure BOOT_ADD0 option bytes at address 0x0801 0000 of Flash_AXIM in sector 2 */
  157.                         pOBInit.BootAddr0 = ((uint32_t)0x2008);//0x2008 for 0x802 0000               
  158.                 }       
  159.                 else
  160.                 {
  161.                         /* Configure BOOT_ADD0 option bytes at address 0x0800 0000 of Flash_AXIM in sector 0 */
  162.                         pOBInit.BootAddr0 = OB_BOOTADDR_AXIM_FLASH;
  163.                 }
  164.                        
  165.           /* Allow Access to option bytes sector */
  166.           HAL_FLASH_OB_Unlock();
  167.           /* Program option bytes */
  168.           HAL_FLASHEx_OBProgram(&pOBInit);
  169.        
  170.          /* Start the Option Bytes programming process */
  171.      if (HAL_FLASH_OB_Launch() != HAL_OK)
  172.       {
  173.         /* User can add here some code to deal with this error */
  174.         while (1)
  175.         {
  176.         }
  177.       }
  178.         /* Prevent Access to option bytes sector */
  179.       HAL_FLASH_OB_Lock();

  180.         /* Generate Reset by software */
  181.       NVIC_SystemReset();
  182.                                
  183.   }

  184. }

  185. /**
  186.   * @brief  Initializes the STM32756G-EVAL's LCD and LEDs resources.
  187.   * @param  None
  188.   * @retval None
  189.   */
  190. static void BSP_LCD_Config(void)
  191. {
  192.   /*##- Initialize the LCD #################################################*/
  193.   /* Initialize the LCD */
  194.   BSP_LCD_Init();

  195.   /* Initialise the LCD Layers */
  196.   BSP_LCD_LayerDefaultInit(1, LCD_FB_START_ADDRESS);
  197.   /* Set LCD Foreground Layer  */
  198.   BSP_LCD_SelectLayer(1);

  199.   /* Set LCD font */
  200.   BSP_LCD_SetFont(&Font24);
  201.   

  202.   /*##- Display messages on LCD ############################################*/
  203.   /* Clear the LCD */
  204.   BSP_LCD_SetBackColor(LCD_COLOR_WHITE);
  205.   BSP_LCD_Clear(LCD_COLOR_WHITE);

  206.   /* Set the LCD Text Color */
  207.   BSP_LCD_SetTextColor(LCD_COLOR_DARKBLUE);

  208.   /* Display test name on LCD */
  209.   BSP_LCD_DisplayStringAtLine(0, (uint8_t *)"         STM32F7xxx Training        ");
  210.   BSP_LCD_DisplayStringAtLine(2, (uint8_t *)"         Press User Button      ");
  211.   BSP_LCD_DisplayStringAtLine(3, (uint8_t *)"   To configure BOOT Option bytes  ");
  212. }


  213. /**
  214.   * @brief  System Clock Configuration
  215.   *         The system Clock is configured as follow :
  216.   *            System Clock source            = PLL (HSE)
  217.   *            SYSCLK(Hz)                     = 200000000
  218.   *            HCLK(Hz)                       = 200000000
  219.   *            AHB Prescaler                  = 1
  220.   *            APB1 Prescaler                 = 4
  221.   *            APB2 Prescaler                 = 2
  222.   *            HSE Frequency(Hz)              = 25000000
  223.   *            PLL_M                          = 25
  224.   *            PLL_N                          = 400
  225.   *            PLL_P                          = 2
  226.   *            PLLSAI_N                       = 384
  227.   *            PLLSAI_P                       = 8
  228.   *            VDD(V)                         = 3.3
  229.   *            Main regulator output voltage  = Scale1 mode
  230.   *            Flash Latency(WS)              = 6
  231.   * @param  None
  232.   * @retval None
  233.   */
  234. void SystemClock_Config(void)
  235. {
  236.   RCC_ClkInitTypeDef RCC_ClkInitStruct;
  237.   RCC_OscInitTypeDef RCC_OscInitStruct;
  238.   HAL_StatusTypeDef ret = HAL_OK;

  239.   /* Enable HSE Oscillator and activate PLL with HSE as source */
  240.   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  241.   RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  242.   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  243.   RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  244.   RCC_OscInitStruct.PLL.PLLM = 25;
  245. /* RCC_OscInitStruct.PLL.PLLN = 400;
  246.   RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;*/
  247.   RCC_OscInitStruct.PLL.PLLN = 432;  
  248.   RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  249.   RCC_OscInitStruct.PLL.PLLQ = 9;
  250.   HAL_RCC_OscConfig(&RCC_OscInitStruct);
  251.          
  252.   ret = HAL_PWREx_EnableOverDrive();

  253.   if(ret != HAL_OK)
  254.   {
  255.     while(1) { ; }
  256.   }  
  257.   
  258.   /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
  259.      clocks dividers */
  260.   RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
  261.   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  262.   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  263.   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
  264.   RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
  265.   //HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_6);
  266.   ret = HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_7);
  267.   if(ret != HAL_OK)
  268.   {
  269.     while(1) { ; }
  270.   }  
  271. }


  272. /**
  273.   * @brief  This function is executed in case of error occurrence.
  274.   * @param  None
  275.   * @retval None
  276.   */
  277. static void Error_Handler(void)
  278. {
  279.   /* User may add here some code to deal with this error */
  280.   while(1)
  281.   {
  282.   }
  283. }

  284. #ifdef  USE_FULL_ASSERT

  285. /**
  286.   * @brief  Reports the name of the source file and the source line number
  287.   *         where the assert_param error has occurred.
  288.   * @param  file: pointer to the source file name
  289.   * @param  line: assert_param error line source number
  290.   * @retval None
  291.   */
  292. void assert_failed(uint8_t *file, uint32_t line)
  293. {
  294.   /* User can add his own implementation to report the file name and line number,
  295.      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

  296.   /* Infinite loop */
  297.   while (1)
  298.   {
  299.   }
  300. }
  301. #endif

  302. /**
  303.   * @}
  304.   */

  305. /**
  306.   * @}
  307.   */

  308. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
复制代码
wofei1314 回答时间:2017-12-13 11:41:58
请参照我贴的代码,完成擦除Flash之后,写入数据,然后跳转的时候直接设置Boot位置....软复位即可跳转

评分

参与人数 1ST金币 +3 收起 理由
zero99 + 3

查看全部评分

hpdell 回答时间:2017-12-13 16:44:37
任风吹吹 发表于 2017-12-13 10:24
楼主,你的option byte nDBANK的值多少?

我现在app 的运行地址是 0x08040000 这个,我现在 吧  iAp 程序大小减小到 < 256KB了

现在操作 擦除 扇区的 起始扇区号为  FLASH_SECTOR_5 ,结束

FLASH_SECTOR_11 - FLASH_SECTOR_5 + 1

hpdell 回答时间:2017-12-13 16:45:42
wofei1314 发表于 2017-12-13 11:41
请参照我贴的代码,完成擦除Flash之后,写入数据,然后跳转的时候直接设置Boot位置....软复位即可跳转
...

好的,我参考一下,多些多谢啊
hpdell 回答时间:2017-12-13 21:43:33
本帖最后由 hpdell 于 2017-12-13 21:45 编辑
wofei1314 发表于 2017-12-13 11:41
请参照我贴的代码,完成擦除Flash之后,写入数据,然后跳转的时候直接设置Boot位置....软复位即可跳转
...

现在可以实现 app 无系统的程序跳转了,带系统的程序跳转貌似还是不行,

在 iap 程序跳转前,需要关闭

void Jump_To_APP(void)
{
  //检测APP地址是否合法

  printf("\r\n_______ *** *** Jump to the new program run please ... *** ***_______\r\n\r\n");
   
  // 判断栈顶地址是否在0x2000 0000 - 0x2000 2000之间,这个判断也可以使用,完全木有任何问题的
  if (((*(__IO uint32_t*) USER_FLASH_FIRST_PAGE_ADDRESS ) & 0x2FFE0000 ) == 0x20000000)
  {
    // 通过判断栈顶地址值是否正确来判断是否已经下载用户应用程序。因为用户程序的启动文件开始会初始化栈空间,如果栈顶地址正确,说明用户程序已经下载
//    __ASM("CPSID  I");
    // Jump to user application
    JumpAddress = *(__IO uint32_t*) (USER_FLASH_FIRST_PAGE_ADDRESS + 4);// 前4字节为中断向量表
    Jump_To_Application = (pFunction) JumpAddress;// 指向用户程序复位函数所在的地址
   
    // 关闭所有外设中断
    HAL_NVIC_DisableIRQ(ETH_IRQn);
    HAL_NVIC_DisableIRQ(USART1_IRQn); //关闭串口中断
    HAL_NVIC_DisableIRQ(SD_IRQn);
    HAL_NVIC_DisableIRQ(SD_DMAx_Rx_IRQn);
    HAL_NVIC_DisableIRQ(SD_DMAx_Tx_IRQn);
   
    PWM_Stop();   
    HAL_FLASH_Lock();
    __disable_irq();  //关闭总中断
   
    {
        /*
        Reset of all peripherals  
        这些外设关闭非常重要,否则不能够正常实现程序跳转功能,切记切记
        */
        __APB1_FORCE_RESET();
        __APB1_RELEASE_RESET();
        __APB2_FORCE_RESET();
        __APB2_RELEASE_RESET();
        
        __AHB1_FORCE_RESET();
        __AHB1_RELEASE_RESET();   
        
        __AHB2_FORCE_RESET();
        __AHB2_RELEASE_RESET();  
        
        __AHB3_FORCE_RESET();
        __AHB3_RELEASE_RESET();        

        HAL_RCC_DeInit();   
    }
   
   
    __set_PSP(*(volatile uint32_t*) USER_FLASH_FIRST_PAGE_ADDRESS);
    __set_CONTROL(0);   
   
    //设置APP程序堆栈指针
    __set_MSP(*(__IO uint32_t*) USER_FLASH_FIRST_PAGE_ADDRESS);  // 设置用户程序的栈指针
    __set_CONTROL(0);
   
    SysTick->CTRL  &= ~SysTick_CTRL_TICKINT_Msk;   // 关闭滴答定时器中断
    SysTick->VAL = 0;
    SysTick->LOAD = 0;   
   
    Jump_To_Application();  // 执行用户程序
  }
  else
  {
    printf("jump uaer app run error ??\r\n");
    for(;;)
    {}

  }
}




现在 app 程序带 系统的,跳转会失败,还需要关闭哪些 功能啊 ????????




wofei1314 回答时间:2017-12-14 10:42:36
hpdell 发表于 2017-12-13 21:43
现在可以实现 app 无系统的程序跳转了,带系统的程序跳转貌似还是不行,

在 iap 程序跳转前,需要关闭

这个和我贴的原理不一样啊,这种是原始方式的...

F7的可以通过向Flash写入boot地址数据,重启之后直接从新的Boot启动,无需关中断啥的...理论上和APP有没有系统无关
hpdell 回答时间:2017-12-14 21:47:55
wofei1314 发表于 2017-12-14 10:42
这个和我贴的原理不一样啊,这种是原始方式的...

F7的可以通过向Flash写入boot地址数据,重启之后直接从 ...

你好,你贴的这段代码我貌似没有看懂啊 ?

所属标签

相似问题

关于意法半导体
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
招聘信息
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
关注我们
st-img 微信公众号
st-img 手机版