Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
ota在线升级
Bootloader
bootload跳转到app
5
RTT app跳转后运行一段时间就会hardfault
发布于 2024-04-15 19:55:44 浏览:477
订阅该版
用的是华大的hc32L196 bootloader是裸机跑的 大概分配的是30K的大小 然后app跑的是rtt bootloader没有任何硬件初始化 也没涉及到任何中断 按照官方iap例程在startup里 把new_vect_table 0x7800加上了 能正常跳转 能初始化thread 但是过会马上会进hardfault 如果从bootloader 加载 直接运行app的话没有问题 ```c { __disable_irq(); /* 关闭所有中断,清除所有中断挂起标志 */ for (uint32_t i = 0; i < 1; i++) { NVIC->ICER[i]=0xFFFFFFFF; NVIC->ICPR[i]=0xFFFFFFFF; } Boot2APP(); //跳转到APP部分 } ``` ```c void Boot2APP(void) { /* Test if user code is programmed starting from address "APPLICATION_ADDRESS" */ //因为用户程序开始位置(0x08004000处)的前4个字节存放的是堆栈的地址,堆栈地址必定是指向RAM空间的,而STM32的RAM空间起始地址为0x20000000,所以要进行判断。 if ((FLASH_If_Read_Word(APPLICATION_ADDRESS) & 0x2ff00000 ) == 0x20000000) { /* Jump to user application */ //程序跳转地址的确认,前面已经说过0x08004004处的4个字节存放的是复位函数的入口地址, //该句的意思为获得(ApplicationAddress + 4)地址处的数据,即为获得新的复位函数入口地址。 JumpAddress = *(__IO uint32_t*) (APPLICATION_ADDRESS + 4); //令Jump_To_Application这个函数指针指向复位函数入口地址。 JumpToApplication = (pFunction) JumpAddress; /* Initialize user application's Stack Pointer */ //堆栈的初始化,重新设定栈顶代地址,把栈顶地址设置为用户代码指向的栈顶地址。 __set_MSP(*(__IO uint32_t*) APPLICATION_ADDRESS); __set_CONTROL(0); //跳转到新的复位函数。 JumpToApplication(); } } ``` ```c void rt_hw_board_init(void) { App_SystemClkInit_RCH(SysctrlRchFreq16MHz); // Sysctrl_SetHCLKDiv(SysctrlHclkDiv1); Sysctrl_SetPCLKDiv(SysctrlPclkDiv1); Sysctrl_SetRTCAdjustClkFreq(SysctrlRTC16MHz); //补偿高速时钟源 Sysctrl_ClkSourceEnable(SysctrlClkRCL,TRUE); //配置内部低速时钟作为RTC时钟 Sysctrl_SetRCLTrim(SysctrlRclFreq32768); SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND); __enable_irq(); /* * TODO 1: OS Tick Configuration * Enable the hardware timer and call the rt_os_tick_callback function * periodically with the frequency RT_TICK_PER_SECOND. */ /* Call components board initial (use INIT_BOARD_EXPORT()) */ #ifdef RT_USING_COMPONENTS_INIT rt_components_board_init(); #endif #if defined(RT_USING_USER_MAIN) && defined(RT_USING_HEAP) rt_system_heap_init(rt_heap_begin_get(), rt_heap_end_get()); #endif } #ifdef RT_USING_CONSOLE static int uart_init(void) { return 0; } INIT_BOARD_EXPORT(uart_init); void rt_hw_console_output(const char *str) { } ``` ```c ;/****************************************************************************** ;* Copyright (C) 2019, Huada Semiconductor Co.,Ltd All rights reserved. ;* ;* This software is owned and published by: ;* Huada Semiconductor Co.,Ltd ("HDSC"). ;* ;* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND ;* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT. ;* ;* This software contains source code for use with HDSC ;* components. This software is licensed by HDSC to be adapted only ;* for use in systems utilizing HDSC components. HDSC shall not be ;* responsible for misuse or illegal use of this software for devices not ;* supported herein. HDSC is providing this software "AS IS" and will ;* not be responsible for issues arising from incorrect user implementation ;* of the software. ;* ;* Disclaimer: ;* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE, ;* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS), ;* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING, ;* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED ;* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED ;* WARRANTY OF NONINFRINGEMENT. ;* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT, ;* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT ;* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, ;* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR ;* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT, ;* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA, ;* SAVINGS OR PROFITS, ;* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. ;* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR ;* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED ;* FROM, THE SOFTWARE. ;* ;* This software may be replicated in part or whole for the licensed use, ;* with the restriction that this Disclaimer and Copyright notice must be ;* included with each copy of this software, whether used in part or whole, ;* at all times. ;*/ ;/*****************************************************************************/ ;/*****************************************************************************/ ;/* Startup for ARM */ ;/* Version V1.0 */ ;/* Date 2019-03-01 */ ;/* Target-mcu {MCU_PN_H} */ ;/*****************************************************************************/ ; Stack Configuration ; Stack Size (in Bytes) <0x0-0xFFFFFFFF:8> Stack_Size EQU 0x00000400 new_vect_table EQU 0x00007800 ;中断向量偏移长度 AREA STACK, NOINIT, READWRITE, ALIGN=3 Stack_Mem SPACE Stack_Size __initial_sp ; Heap Configuration ; Heap Size (in Bytes) <0x0-0xFFFFFFFF:8> Heap_Size EQU 0x00000000 AREA HEAP, NOINIT, READWRITE, ALIGN=3 __heap_base Heap_Mem SPACE Heap_Size __heap_limit PRESERVE8 THUMB ; Vector Table Mapped to Address 0 at Reset AREA RESET, DATA, READONLY EXPORT __Vectors EXPORT __Vectors_End EXPORT __Vectors_Size __Vectors DCD __initial_sp ; Top of Stack DCD Reset_Handler ; Reset DCD NMI_Handler ; NMI DCD HardFault_Handler ; Hard Fault DCD 0 ; Reserved DCD 0 ; Reserved DCD 0 ; Reserved DCD 0 ; Reserved DCD 0 ; Reserved DCD 0 ; Reserved DCD 0 ; Reserved DCD SVC_Handler ; SVCall DCD 0 ; Reserved DCD 0 ; Reserved DCD PendSV_Handler ; PendSV DCD SysTick_Handler ; SysTick DCD PORTA_IRQHandler DCD PORTB_IRQHandler DCD PORTC_E_IRQHandler DCD PORTD_F_IRQHandler DCD DMAC_IRQHandler DCD TIM3_IRQHandler DCD UART0_2_IRQHandler DCD UART1_3_IRQHandler DCD LPUART0_IRQHandler DCD LPUART1_IRQHandler DCD SPI0_IRQHandler DCD SPI1_IRQHandler DCD I2C0_IRQHandler DCD I2C1_IRQHandler DCD TIM0_IRQHandler DCD TIM1_IRQHandler DCD TIM2_IRQHandler DCD LPTIM0_1_IRQHandler DCD TIM4_IRQHandler DCD TIM5_IRQHandler DCD TIM6_IRQHandler DCD PCA_IRQHandler DCD WDT_IRQHandler DCD RTC_IRQHandler DCD ADC_DAC_IRQHandler DCD PCNT_IRQHandler DCD VC0_IRQHandler DCD VC1_2_IRQHandler DCD LVD_IRQHandler DCD LCD_IRQHandler DCD FLASH_RAM_IRQHandler DCD CLKTRIM_IRQHandler __Vectors_End __Vectors_Size EQU __Vectors_End - __Vectors AREA |.text|, CODE, READONLY ; Reset Handler Reset_Handler PROC EXPORT Reset_Handler [WEAK] IMPORT SystemInit IMPORT __main ;reset NVIC if in rom debug LDR R0, =0x20000000 LDR R2, =0x0 MOVS R1, #0 ; for warning, ADD R1, PC,#0 ; for A1609W, CMP R1, R0 BLS RAMCODE ; ram code base address. ADD R2, R0,R2 RAMCODE ; reset Vector table address. LDR R0, =0xE000ED08 LDR R2, =new_vect_table STR R2, [R0] LDR R0, =SystemInit BLX R0 LDR R0, =__main BX R0 ENDP ; Dummy Exception Handlers (infinite loops which can be modified) NMI_Handler PROC EXPORT NMI_Handler [WEAK] B . ENDP HardFault_Handler\ PROC EXPORT HardFault_Handler [WEAK] B . ENDP SVC_Handler PROC EXPORT SVC_Handler [WEAK] B . ENDP PendSV_Handler PROC EXPORT PendSV_Handler [WEAK] B . ENDP SysTick_Handler PROC EXPORT SysTick_Handler [WEAK] B . ENDP Default_Handler PROC EXPORT PORTA_IRQHandler [WEAK] EXPORT PORTB_IRQHandler [WEAK] EXPORT PORTC_E_IRQHandler [WEAK] EXPORT PORTD_F_IRQHandler [WEAK] EXPORT DMAC_IRQHandler [WEAK] EXPORT TIM3_IRQHandler [WEAK] EXPORT UART0_2_IRQHandler [WEAK] EXPORT UART1_3_IRQHandler [WEAK] EXPORT LPUART0_IRQHandler [WEAK] EXPORT LPUART1_IRQHandler [WEAK] EXPORT SPI0_IRQHandler [WEAK] EXPORT SPI1_IRQHandler [WEAK] EXPORT I2C0_IRQHandler [WEAK] EXPORT I2C1_IRQHandler [WEAK] EXPORT TIM0_IRQHandler [WEAK] EXPORT TIM1_IRQHandler [WEAK] EXPORT TIM2_IRQHandler [WEAK] EXPORT LPTIM0_1_IRQHandler [WEAK] EXPORT TIM4_IRQHandler [WEAK] EXPORT TIM5_IRQHandler [WEAK] EXPORT TIM6_IRQHandler [WEAK] EXPORT PCA_IRQHandler [WEAK] EXPORT WDT_IRQHandler [WEAK] EXPORT RTC_IRQHandler [WEAK] EXPORT ADC_DAC_IRQHandler [WEAK] EXPORT PCNT_IRQHandler [WEAK] EXPORT VC0_IRQHandler [WEAK] EXPORT VC1_2_IRQHandler [WEAK] EXPORT LVD_IRQHandler [WEAK] EXPORT LCD_IRQHandler [WEAK] EXPORT FLASH_RAM_IRQHandler [WEAK] EXPORT CLKTRIM_IRQHandler [WEAK] PORTA_IRQHandler PORTB_IRQHandler PORTC_E_IRQHandler PORTD_F_IRQHandler DMAC_IRQHandler TIM3_IRQHandler UART0_2_IRQHandler UART1_3_IRQHandler LPUART0_IRQHandler LPUART1_IRQHandler SPI0_IRQHandler SPI1_IRQHandler I2C0_IRQHandler I2C1_IRQHandler TIM0_IRQHandler TIM1_IRQHandler TIM2_IRQHandler LPTIM0_1_IRQHandler TIM4_IRQHandler TIM5_IRQHandler TIM6_IRQHandler PCA_IRQHandler WDT_IRQHandler RTC_IRQHandler ADC_DAC_IRQHandler PCNT_IRQHandler VC0_IRQHandler VC1_2_IRQHandler LVD_IRQHandler LCD_IRQHandler FLASH_RAM_IRQHandler CLKTRIM_IRQHandler B . ENDP ALIGN ; User Initial Stack & Heap IF :DEF:__MICROLIB EXPORT __initial_sp EXPORT __heap_base EXPORT __heap_limit ELSE IMPORT __use_two_region_memory EXPORT __user_initial_stackheap __user_initial_stackheap LDR R0, = Heap_Mem LDR R1, =(Stack_Mem + Stack_Size) LDR R2, = (Heap_Mem + Heap_Size) LDR R3, = Stack_Mem BX LR ALIGN ENDIF END ``` ![boot.png](https://oss-club.rt-thread.org/uploads/20240416/c373293631524e228c2441d2e7896b09.png)
查看更多
3
个回答
默认排序
按发布时间排序
crystal266
2024-04-16
嵌入式
参考 [rt-thread 中对 hardfault 的处理](https://club.rt-thread.org/ask/article/7f43c1654f9f1680.html "rt-thread 中对 hardfault 的处理") 把进入 hardfault 之前的函数调用信息打印出来进行分析
梦笑真美
2024-04-16
这家伙很懒,什么也没写!
中断什么的都要关掉先
sky_rain
2024-04-19
天高地迥,觉宇宙之无穷
移植下cmbacktrace 发生hardfault后会在串口自动打印堆栈,根据提示信息运行add2line工具可以定位到发生hardfault的代码位置,看看是什么问题
撰写答案
登录
注册新账号
关注者
0
被浏览
477
关于作者
Barricades
这家伙很懒,什么也没写!
提问
1
回答
0
被采纳
0
关注TA
发私信
相关问题
1
Linux下通过USBTinyISP为Arduino开发板烧?写Bootloader
2
请教修改NVIC后RTT调度函数失效的问题[已解决 bootloader中打开了不必要的中断]
3
进入bootloader的方式探讨
4
求助:IAP里的APP使用的RTT,跳转后出错。[已解决]
5
有没有人在STM32F103上用UART IAP跑过RT-Thread?
6
想做网口的IAP远程升级,不知可不可行
7
IAP问题
8
[已解决]请教基于RTT的IAP程序切换到应用程序不成功的问题(基于STM32F4)?
9
stm32f4xx-----IAP移植APP程序需要注意的地方
10
在调试IAP网络升级遇到跳转之后bootloader程序网络不通
推荐文章
1
RT-Thread应用项目汇总
2
玩转RT-Thread系列教程
3
国产MCU移植系列教程汇总,欢迎查看!
4
机器人操作系统 (ROS2) 和 RT-Thread 通信
5
五分钟玩转RT-Thread新社区
6
【技术三千问】之《玩转ART-Pi》,看这篇就够了!干货汇总
7
关于STM32H7开发板上使用SDIO接口驱动SD卡挂载文件系统的问题总结
8
STM32的“GPU”——DMA2D实例详解
9
RT-Thread隐藏的宝藏之completion
10
【ART-PI】RT-Thread 开启RTC 与 Alarm组件
最新文章
1
【RT-Thread】【ci】【scons】将ci.attachconfig.yml和scons结合使用
2
Rt-thread中OTA下载后,bootloader不搬程序
3
ulog 日志 LOG_HEX 输出时间改为本地日期时间
4
在RT-Thread Studio中构建前执行python命令
5
研究一了一段时间RTT,直接标准版上手太难,想用nano,但又舍不得组件
热门标签
RT-Thread Studio
串口
Env
LWIP
SPI
AT
Bootloader
Hardfault
CAN总线
FinSH
ART-Pi
USB
DMA
文件系统
RT-Thread
SCons
RT-Thread Nano
线程
MQTT
STM32
RTC
FAL
rt-smart
I2C_IIC
ESP8266
UART
WIZnet_W5500
ota在线升级
cubemx
PWM
flash
freemodbus
BSP
packages_软件包
潘多拉开发板_Pandora
定时器
ADC
flashDB
GD32
socket
编译报错
中断
Debug
rt_mq_消息队列_msg_queue
SFUD
msh
keil_MDK
ulog
C++_cpp
MicroPython
本月问答贡献
xusiwei1236
8
个答案
2
次被采纳
踩姑娘的小蘑菇
1
个答案
2
次被采纳
用户名由3_15位
9
个答案
1
次被采纳
bernard
4
个答案
1
次被采纳
RTT_逍遥
3
个答案
1
次被采纳
本月文章贡献
聚散无由
2
篇文章
15
次点赞
catcatbing
2
篇文章
5
次点赞
Wade
2
篇文章
4
次点赞
Ghost_Girls
1
篇文章
7
次点赞
YZRD
1
篇文章
2
次点赞
回到
顶部
发布
问题
分享
好友
手机
浏览
扫码手机浏览
投诉
建议
回到
底部