• 瑞萨单片机学习:RA4M3单片机 BOOTloader升级 跳转到主程序 主程序无法执行问题


     一开始从BOOT更新了FLASH后,然后跳转程序,发现程序无法执行,注释掉就可以

    SystemInit()

    但是这样系统时钟没有经过初始化,延时函数会出问题。

    后来 经过挨着注释  最好发现注释掉函数里的下面这行就能跳转了。

    1. /* Call Post C runtime initialization hook. */
    2. // R_BSP_WarmStart(BSP_WARM_START_POST_C);

    1. /*******************************************************************************************************************//**
    2. * Initialize the MCU and the runtime environment.
    3. **********************************************************************************************************************/
    4. void SystemInit (void)
    5. {
    6. // *__Vectors = (uint32_t * )0x00038000;
    7. #if __FPU_USED
    8. /* Enable the FPU only when it is used.
    9. * Code taken from Section 7.1, Cortex-M4 TRM (DDI0439C) */
    10. /* Set bits 20-23 (CP10 and CP11) to enable FPU. */
    11. SCB->CPACR = (uint32_t) CP_MASK;
    12. #endif
    13. #if BSP_TZ_SECURE_BUILD
    14. /* Seal the main stack for secure projects. Reference:
    15. * https://developer.arm.com/documentation/100720/0300
    16. * https://developer.arm.com/support/arm-security-updates/armv8-m-stack-sealing */
    17. uint32_t * p_main_stack_top = (uint32_t *) __Vectors[0];
    18. *p_main_stack_top = BSP_TZ_STACK_SEAL_VALUE;
    19. #endif
    20. #if !BSP_TZ_NONSECURE_BUILD
    21. /* VTOR is in undefined state out of RESET:
    22. * https://developer.arm.com/documentation/100235/0004/the-cortex-m33-peripherals/system-control-block/system-control-block-registers-summary?lang=en.
    23. * Set the Secure/Non-Secure VTOR to the vector table address based on the build. This is skipped for non-secure
    24. * projects because SCB_NS->VTOR is set by the secure project before the non-secure project runs. */
    25. // SCB->VTOR = (uint32_t) &__Vectors;
    26. SCB->VTOR = (uint32_t)&__Vectors;
    27. #endif
    28. #if !BSP_TZ_CFG_SKIP_INIT
    29. #if BSP_FEATURE_BSP_VBATT_HAS_VBTCR1_BPWSWSTP
    30. /* Unlock VBTCR1 register. */
    31. R_SYSTEM->PRCR = (uint16_t) BSP_PRV_PRCR_PRC1_UNLOCK;
    32. /* The VBTCR1.BPWSWSTP must be set after reset on MCUs that have VBTCR1.BPWSWSTP. Reference section 11.2.1
    33. * "VBATT Control Register 1 (VBTCR1)" and Figure 11.2 "Setting flow of the VBTCR1.BPWSWSTP bit" in the RA4M1 manual
    34. * R01UM0007EU0110. This must be done before bsp_clock_init because LOCOCR, LOCOUTCR, SOSCCR, and SOMCR cannot
    35. * be accessed until VBTSR.VBTRVLD is set. */
    36. R_SYSTEM->VBTCR1 = 1U;
    37. FSP_HARDWARE_REGISTER_WAIT(R_SYSTEM->VBTSR_b.VBTRVLD, 1U);
    38. /* Lock VBTCR1 register. */
    39. R_SYSTEM->PRCR = (uint16_t) BSP_PRV_PRCR_LOCK;
    40. #endif
    41. #endif
    42. #if BSP_FEATURE_TFU_SUPPORTED
    43. R_BSP_MODULE_START(FSP_IP_TFU, 0U);
    44. #endif
    45. #if BSP_CFG_EARLY_INIT
    46. /* Initialize uninitialized BSP variables early for use in R_BSP_WarmStart. */
    47. bsp_init_uninitialized_vars();
    48. #endif
    49. /* Call pre clock initialization hook. */
    50. R_BSP_WarmStart(BSP_WARM_START_RESET);
    51. #if BSP_TZ_CFG_SKIP_INIT
    52. /* Initialize clock variables to be used with R_BSP_SoftwareDelay. */
    53. bsp_clock_freq_var_init();
    54. #else
    55. /* Configure system clocks. */
    56. bsp_clock_init();
    57. #if BSP_FEATURE_BSP_RESET_TRNG
    58. /* To prevent an undesired current draw, this MCU requires a reset
    59. * of the TRNG circuit after the clocks are initialized */
    60. bsp_reset_trng_circuit();
    61. #endif
    62. #endif
    63. /* Call post clock initialization hook. */
    64. R_BSP_WarmStart(BSP_WARM_START_POST_CLOCK);
    65. #if BSP_FEATURE_BSP_HAS_SP_MON
    66. /* Disable MSP monitoring */
    67. R_MPU_SPMON->SP[0].CTL = 0;
    68. /* Setup NMI interrupt */
    69. R_MPU_SPMON->SP[0].OAD = BSP_STACK_POINTER_MONITOR_NMI_ON_DETECTION;
    70. /* Setup start address */
    71. R_MPU_SPMON->SP[0].SA = BSP_PRV_STACK_LIMIT;
    72. /* Setup end address */
    73. R_MPU_SPMON->SP[0].EA = BSP_PRV_STACK_TOP;
    74. /* Set SPEEN bit to enable NMI on stack monitor exception. NMIER bits cannot be cleared after reset, so no need
    75. * to read-modify-write. */
    76. R_ICU->NMIER = R_ICU_NMIER_SPEEN_Msk;
    77. /* Enable MSP monitoring */
    78. R_MPU_SPMON->SP[0].CTL = 1U;
    79. #endif
    80. #if BSP_FEATURE_TZ_HAS_TRUSTZONE
    81. /* Use CM33 stack monitor. */
    82. __set_MSPLIM(BSP_PRV_STACK_LIMIT);
    83. // __set_MSPLIM(0);
    84. #endif
    85. #if BSP_CFG_C_RUNTIME_INIT
    86. /* Initialize C runtime environment. */
    87. /* Zero out BSS */
    88. #if defined(__ARMCC_VERSION)
    89. memset((uint8_t *) &Image$$BSS$$ZI$$Base, 0U, (uint32_t) &Image$$BSS$$ZI$$Length);
    90. #elif defined(__GNUC__)
    91. memset(&__bss_start__, 0U, ((uint32_t) &__bss_end__ - (uint32_t) &__bss_start__));
    92. #elif defined(__ICCARM__)
    93. memset((uint32_t *) __section_begin(".bss"), 0U, (uint32_t) __section_size(".bss"));
    94. #endif
    95. /* Copy initialized RAM data from ROM to RAM. */
    96. #if defined(__ARMCC_VERSION)
    97. memcpy((uint8_t *) &Image$$DATA$$Base, (uint8_t *) &Load$$DATA$$Base, (uint32_t) &Image$$DATA$$Length);
    98. #elif defined(__GNUC__)
    99. memcpy(&__data_start__, &__etext, ((uint32_t) &__data_end__ - (uint32_t) &__data_start__));
    100. #elif defined(__ICCARM__)
    101. memcpy((uint32_t *) __section_begin(".data"), (uint32_t *) __section_begin(".data_init"),
    102. (uint32_t) __section_size(".data"));
    103. /* Copy functions to be executed from RAM. */
    104. #pragma section=".code_in_ram"
    105. #pragma section=".code_in_ram_init"
    106. memcpy((uint32_t *) __section_begin(".code_in_ram"),
    107. (uint32_t *) __section_begin(".code_in_ram_init"),
    108. (uint32_t) __section_size(".code_in_ram"));
    109. /* Copy main thread TLS to RAM. */
    110. #pragma section="__DLIB_PERTHREAD_init"
    111. #pragma section="__DLIB_PERTHREAD"
    112. memcpy((uint32_t *) __section_begin("__DLIB_PERTHREAD"), (uint32_t *) __section_begin("__DLIB_PERTHREAD_init"),
    113. (uint32_t) __section_size("__DLIB_PERTHREAD_init"));
    114. #endif
    115. /* Initialize static constructors */
    116. #if defined(__ARMCC_VERSION)
    117. int32_t count = Image$$INIT_ARRAY$$Limit - Image$$INIT_ARRAY$$Base;
    118. for (int32_t i = 0; i < count; i++)
    119. {
    120. void (* p_init_func)(void) =
    121. (void (*)(void))((uint32_t) &Image$$INIT_ARRAY$$Base + (uint32_t) Image$$INIT_ARRAY$$Base[i]);
    122. p_init_func();
    123. }
    124. #elif defined(__GNUC__)
    125. int32_t count = __init_array_end - __init_array_start;
    126. for (int32_t i = 0; i < count; i++)
    127. {
    128. __init_array_start[i]();
    129. }
    130. #elif defined(__ICCARM__)
    131. void const * pibase = __section_begin("SHT$$PREINIT_ARRAY");
    132. void const * ilimit = __section_end("SHT$$INIT_ARRAY");
    133. __call_ctors(pibase, ilimit);
    134. #endif
    135. #endif // BSP_CFG_C_RUNTIME_INIT
    136. /* Initialize SystemCoreClock variable. */
    137. SystemCoreClockUpdate();
    138. #if !BSP_CFG_PFS_PROTECT
    139. #if BSP_TZ_SECURE_BUILD
    140. R_PMISC->PWPRS = 0; ///< Clear BOWI bit - writing to PFSWE bit enabled
    141. R_PMISC->PWPRS = 1U << BSP_IO_PWPR_PFSWE_OFFSET; ///< Set PFSWE bit - writing to PFS register enabled
    142. #else
    143. R_PMISC->PWPR = 0; ///< Clear BOWI bit - writing to PFSWE bit enabled
    144. R_PMISC->PWPR = 1U << BSP_IO_PWPR_PFSWE_OFFSET; ///< Set PFSWE bit - writing to PFS register enabled
    145. #endif
    146. #endif
    147. #if FSP_PRIV_TZ_USE_SECURE_REGS
    148. /* Ensure that the PMSAR registers are reset (Soft reset does not reset PMSAR). */
    149. R_BSP_RegisterProtectDisable(BSP_REG_PROTECT_SAR);
    150. for (uint32_t i = 0; i < 9; i++)
    151. {
    152. R_PMISC->PMSAR[i].PMSAR = UINT16_MAX;
    153. }
    154. R_BSP_RegisterProtectEnable(BSP_REG_PROTECT_SAR);
    155. #endif
    156. #if BSP_TZ_SECURE_BUILD
    157. /* Initialize security features. */
    158. R_BSP_SecurityInit();
    159. #endif
    160. /* Call Post C runtime initialization hook. */
    161. // R_BSP_WarmStart(BSP_WARM_START_POST_C);
    162. /* Initialize ELC events that will be used to trigger NVIC interrupts. */
    163. bsp_irq_cfg();
    164. /* Call any BSP specific code. No arguments are needed so NULL is sent. */
    165. bsp_init(NULL);
    166. }

  • 相关阅读:
    让交互更加生动!有意思的鼠标跟随 3D 旋转动效
    SpringTask基础使用
    【数据结构】如何设计循环队列?图文解析(LeetCode)
    Java Thread.yield()方法具有什么功能呢?
    角互补三角形面积公式的证明过程
    GAIN的代码实现(4)——基于GAN的Spam数据集缺失数据填补(序)【改进版】
    一种基于共识机制的数字集群终端防失控方案研究
    windows环境下搭建redis5.x集群
    mysql不是内部或外部命令,也不是可运行的程序或批处理文件解决
    Vue3中父组件与子组件的传值
  • 原文地址:https://blog.csdn.net/qq_21370051/article/details/125101305