2015-06-11 43 views
4

我嘗試爲STM32L1系列卡創建自定義啓動加載程序,我需要將我的啓動加載程序代碼放在閃存底部。然後我可以適當地閃光我的記憶。 我知道它可以在鏈接器腳本中指定,但我不知道該怎麼做。 我宣佈我的bootloader區是這樣的:將啓動加載程序放在FLASH內存的底部

.bootsection : 
    { 
    . = ALIGN(4); 
    KEEP(*(.bootsection)) /* Bootloader code */ 
    . = ALIGN(4); 
    } >FLASH 

我的記憶設置是這樣的:

MEMORY 
{ 
    FLASH (rx)  : ORIGIN = 0x08000000, LENGTH = 512K 
    RAM (xrw)  : ORIGIN = 0x20000000, LENGTH = 80K 
    MEMORY_B1 (rx) : ORIGIN = 0x60000000, LENGTH = 0K 
} 

人有命令的想法?

+0

也許嘗試更改'> FLASH'到'> FLASH AT> FLASH' –

+0

類似於> FLASH AT 0x0 ...? – kidz55

+0

這是不正確的鏈接腳本語法...我認爲這樣做會給你一個語法錯誤。 –

回答

2

這裏是我的鏈接腳本,我試圖用一些新的存儲部分

MEMORY 
    { 
     FLASH (rx)  : ORIGIN = 0x08000000, LENGTH = 510K 
     MEM_BOOT (rx) : ORIGIN = 0x0807CFFE, LENGTH = 2K 
     RAM (xrw)  : ORIGIN = 0x20000000, LENGTH = 80K 
     MEMORY_B1 (rx) : ORIGIN = 0x60000000, LENGTH = 0K 
    } 

    /* Define output sections */ 
    SECTIONS 
    { 
     /* The startup code goes first into FLASH */ 
     .isr_vector : 
     { 
     . = ALIGN(4); 
     KEEP(*(.isr_vector)) /* Startup code */ 
     . = ALIGN(4); 
     } >FLASH 


     .bootsection : 
     { 
     . = ALIGN(4); 
     KEEP(*(.bootsection)) /* Bootloader code */ 
     . = ALIGN(4); 
     } >MEM_BOOT 

這裏是我的啓動代碼,我wroted閃存程序,但擦除程序還沒寫。

#define MY_BL_FUNCTIONS __attribute__((section(".bootsection"))) 

void BootLoader(void) MY_BL_FUNCTIONS; 
uint8_t Flash_Write (uint32_t StartAddress, uint8_t *p, uint32_t Size) MY_BL_FUNCTIONS; 

void BootLoader(void) { 
    char buffer[1000]; 
    int i = 0; 
    /*test if we enter the bootloader , toggle the led and send a string to the usart */ 
    GPIO_ToggleBits(GPIOA, GPIO_Pin_5); 
    do { 
     buffer[i] = Uart2ReadChar(); 
     i++; 
    } while (buffer[i] != '\0'); 

    SendString(buffer,USART2); 
} 

uint8_t Flash_Write (uint32_t StartAddress, uint8_t *p, uint32_t Size) 
{ 
     uint32_t idx; 
     uint32_t Address; 
     __IO FLASH_Status status = FLASH_COMPLETE; 

     Address = StartAddress; 

     /* Unlock the FLASH Program memory */ 
     FLASH_Unlock (); 

     /* Clear all pending flags */ 
     FLASH_ClearFlag (FLASH_FLAG_EOP  | 
         FLASH_FLAG_WRPERR | 
         FLASH_FLAG_PGAERR | 
         FLASH_FLAG_SIZERR | 
         FLASH_FLAG_OPTVERR); 

     while (Address < StartAddress + Size) 
     { 
      status = FLASH_FastProgramWord (Address, *(uint32_t *)p); 
      Address = Address + 4; 
      p = p + 4; 
      if (status != FLASH_COMPLETE) return status; 
     } 

     /* Lock the FLASH Program memory */ 
     FLASH_Lock (); 

     return (uint8_t)status; 
} 
+0

Flash_Write()代碼中似乎存在一個錯誤。如果函數FLASH_FastProgramWord()返回一個不同的FLASH_COMPLETE值,那麼你的函數退出並且保持閃存解鎖。 – ViniCoder

相關問題