程序分散加载到外部QSPI FLASH 启动问题

发布于 2020-07-02 11:38:53

现在手上有一块原子 北极星 STM32H750 的板子,片上flash 128k,裸机的例程都是通过分散加载的方式把程序分两部分下载到片上和片外flash

#define m_stmflash_start                0X08000000        
#define m_stmflash_size                    0X20000            

#define m_qspiflash_start                0X90000000        
#define m_qspiflash_size                0X800000        
 
#define m_stmsram_start                    0X24000000        
#define m_stmsram_size                    0X80000            

  
 
LR_m_stmflash m_stmflash_start m_stmflash_size {        
  ER_m_stmflash m_stmflash_start m_stmflash_size {        
    *.o (RESET, +First)                                    
                                                        
    * (InRoot$$Sections)                                
    * (Veneer$$Code) 
    libinit.o
    libinit2.o
    libshutdown.o
    libshutdown2.o
    __rtentry.o
    __rtentry2.o
    __rtentry4.o
    rtexit.o
    rtexit2.o 
    
    use_no_semi_2.o
    heapauxi.o
    use_no_semi.o
    sys_stackheap_outer.o
    exit.o
    libspace.o
    fpinit.o
    lludivv7m.o
    startup_stm32h750xx.o
     
    rt_locale_intlibspace.o  
    lc_numeric_c.o 
    lc_ctype_c.o

    startup_stm32h750xx.o
    system_stm32h7xx.o
    stm32h7xx_hal.o
    stm32h7xx_hal_cortex.o
    stm32h7xx_hal_rcc.o
    stm32h7xx_hal_gpio.o
    stm32h7xx_hal_msp.o
    
    main.o 
    sys.o 
    usart.o
    delay.o
  } 
  RW_m_stmsram m_stmsram_start m_stmsram_size {            
   .ANY (+RW +ZI)                                        
  }
}

LR_m_qspiflash m_qspiflash_start m_qspiflash_size {        
   ER_m_qspiflash m_qspiflash_start m_qspiflash_size {    
    .ANY (+RO)                                             
  }                                                             
}

把一些通用的.o文件都放到片上,其他的都放在片外,这样自己写的应用程序都会放到片外

现在我想使用RT-thread操作系统,更改link.scf文件,

LR_IROM1 0x08000000 0x00020000  {    ; load region size_region
  ER_IROM1 0x08000000 0x00020000  {  ; load address = execution address
   *.o (RESET, +First)
   *(InRoot$$Sections)
   * (Veneer$$Code) 
    libinit.o
    libinit2.o
    libshutdown.o
    libshutdown2.o
    __rtentry.o
    __rtentry2.o
    __rtentry4.o
    rtexit.o
    rtexit2.o 

    heapauxi.o
    use_no_semi.o
    sys_stackheap_outer.o
    exit.o
    libspace.o
    fpinit.o
    lludivv7m.o
    startup_stm32h750xx.o

    system_stm32h7xx.o
    stm32h7xx_hal.o
    stm32h7xx_hal_cortex.o
    stm32h7xx_hal_rcc.o
    stm32h7xx_hal_gpio.o
    stm32h7xx_hal_msp.o
    stm32h7xx_hal_dma.o
    stm32h7xx_hal_uart.o
    stm32h7xx_hal_uart_ex.o
    stm32h7xx_hal_rcc_ex.o
    stm32h7xx_hal_pwr.o
    stm32h7xx_hal_pwr_ex.o
    clock.o
    components.o
    device.o
    idle.o
    ipc.o
    irq.o
    kservice.o
    mem.o
    object.o
    scheduler.o
    thread.o
    timer.o
    board.o
    drv_mpu.o
    drv_gpio.o
    drv_usart.o
    cpuport.o
    indicate_semi.o
    msh.o
    dataqueue.o
    sys_exit.o
    cmd.o
    serial.o
    drv_common.o
    completion.o
    pin.o
    strlen.o
    strcat.o
    strncmp.o
    rt_memcpy_v6.o
    rt_memcpy_w.o
    context_rvds.o
    memcmp.o
    strncpy.o
    rt_memclr.o
    rt_memclr_w.o
    main.o
    Led.o
  }
  RW_IRAM1 0x24000000 0x00080000  {  ; RW data
   .ANY (+RW +ZI)
  }
}

LR_m_qspiflash 0X90000000 0X800000 {        
   ER_m_qspiflash 0X90000000 0X800000 {    
    .ANY (+RO)
  }                                                             
}

编译完成后生成两个.bin文件ER_IROM1和ER_m_qspiflash,这种情况下程序运行正常,

#include "Led.h"

int main(void)
{
      rt_kprintf("hello world\r\n");
      LED_Init();

      HAL_GPIO_WritePin(GPIOB,GPIO_PIN_0,GPIO_PIN_RESET);    
      HAL_GPIO_WritePin(GPIOB,GPIO_PIN_1,GPIO_PIN_RESET);
    
      
      LED0_Toggle;
      //LED1_Toggle;
    while (1)
    {
        rt_thread_mdelay(1000);
        LED1_Toggle;
    }
    return RT_EOK;
}

在上面的加载过程中,文件Led.o被加载到了片上flash,但是这个文件是自己编写的程序,希望被加载到外部,所以在上面的把Led.o删掉,重新编译无错,运行时先打印了hello world , 执行LED_Init()时,报错了

 \ | /
- RT -     Thread Operating System
 / | \     4.0.2 build Jul  2 2020
 2006 - 2019 Copyright by rt-thread team
hello world

psr: 0x61000000
r00: 0x00000000
r01: 0x40011000
r02: 0x0800cce9
r03: 0x00000000
r04: 0x00000000
r05: 0xdeadbeef
r06: 0xdeadbeef
r07: 0xdeadbeef
r08: 0xdeadbeef
r09: 0xdeadbeef
r10: 0xdeadbeef
r11: 0xdeadbeef
r12: 0x9000014d
 lr: 0x08007ebb
 pc: 0x9000014c
hard fault on thread: main



thread   pri  status      sp     stack size max used left tick  error
-------- ---  ------- ---------- ----------  ------  ---------- ---
tidle0    31  ready   0x00000048 0x00000400    07%   0x00000020 000
main      10  running 0x00000044 0x00000800    07%   0x00000012 000
bus fault:
SCB_CFSR_BFSR:0x01 IBUSERR

刚刚接触这个分散加载,还不是很理解,哪位帮忙看看,如何能够把类似Led.c等自己的程序加载到外部,并运行,谢谢

查看更多

关注者
1
被浏览
247
5 个回答
aozima
aozima 2020-07-02
拒绝白嫖,拒绝键盘侠!

请把贴子中的代码用代码标签框起来,方便大家阅读。

whj467467222
whj467467222 2020-07-03

期待楼主的研究成果哦。
我目前的做法是直接暴力的把128K作为boot,直接跳转到0x9000 0000地址运行。

井地的蛙
井地的蛙 2020-07-07

外部QSPI初始化了吗,qspi需要初始化,并且设置成内存映射模式。

SimpleFan
SimpleFan 2020-08-12

楼主 解决问题了吗?我现在也想这样做,可是修改好分散加载文件后,死活运行不起来了

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友