首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >-填充PIC32MX引导闪存的命令

-填充PIC32MX引导闪存的命令
EN

Stack Overflow用户
提问于 2016-03-14 13:16:45
回答 2查看 972关注 0票数 0

在过去的几个星期里,我一直在努力找出这种方法不起作用的原因。我试着阅读了在我的、PIC32、、MCU、MCU、以及我正在使用的XC32编译器上可以找到的所有文档(v1.34),但到目前为止还没有成功。

我需要一个特殊的常量值写入物理引导闪存地址0x1FC02FEC (虚拟地址:)这个常数是0x3BDFED92

我已经成功地在我的主程序上(如果我直接使用Real编程我的pic32 )通过以下命令行(我把xc32-ld放在Properties下的“附加选项”下)成功地做到了这一点:

代码语言:javascript
复制
--fill=0x3bdfed92@0x9FC02FEC

然后,我能够(在我的主程序中)检查这个地址是否确实有正确的值存储在其中,这也是有效的。为此,我使用了以下代码:

代码语言:javascript
复制
if(*(int *)(0x9fc02fec) == 0x3bdfed92)

我的问题如下。我不希望我的主程序十六进制文件将常量写入该位置。我希望我的引导装载器十六进制文件能够做到这一点,我的主程序必须能够读取该位置,并查看是否存在该常量。如果我在引导加载程序的xc32-ld中使用--填充命令,它成功地编写了常量,就像主程序一样(我在调试模式下使用相同的-fill命令运行了引导加载程序,并检查了0x1FC02FEC地址的常量)。问题是,当我的引导程序通过MicroSD读取一个新的主程序,然后跳转到新的主程序时,所有的东西都不能工作。似乎,在它跳到新的主程序之前,一些不好的事情发生了,一切都崩溃了。当程序从引导加载程序跳转到主程序时,几乎就像将值写入1FC02FEC位置一样是一个问题。

这有什么原因吗?我希望我的解释是可以的,如果没有,请让我知道,我会尝试用一种更容易理解的方式重述。

我正在使用Microchip提供的示例代码来使用MicroSD卡进行引导加载程序。以下是守则:

代码语言:javascript
复制
int main(void)
{
    volatile UINT i;
    volatile BYTE led = 0;

    // Setup configuration
    (void)SYSTEMConfig(SYS_FREQ, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);

    InitLED();
    TRISBbits.TRISB14 = 0;
    LATBbits.LATB14 = 0;

    ClrWdt();

    // Create a startup delay to resolve trigger switch bouncing issues
    unsigned char x;
    WORD ms = 500;
    DWORD dwCount = 25;

    while(ms--)
    {
        ClrWdt();
        x=4;
        while(x--)
        {
            volatile DWORD _dcnt;

            _dcnt = dwCount*((DWORD)(0.00001/(1.0/GetInstructionClock())/10));
            while(_dcnt--)
            {
                    #if defined(__C32__)
                            Nop();
                            Nop();
                            Nop();
                    #endif
            }
        }
    }


    if(!CheckTrigger() && ValidAppPresent())
    {
        // This means the switch is not pressed. Jump
        // directly to the application

        JumpToApp();        
    }
    else if(CheckTrigger() && ValidAppPresent()){

        if(MDD_MediaDetect()){
            if(FSInit()){
                myFile = FSfopen("image.hex","r");

                if(myFile == NULL){
                    JumpToApp();
                }
            }
            else{
                JumpToApp();
            }
        }
        else{
            JumpToApp();
        }

    }

    //Initialize the media
    while (!MDD_MediaDetect())
    {
        // Waiting for media to be inserted.
        BlinkLED();
    }

    // Initialize the File System
    if(!FSInit())
    {
         //Indicate error and stay in while loop.
         Error();
         while(1);
    }


    myFile = FSfopen("image.hex","r");

    if(myFile == NULL)// Make sure the file is present.
    {
        //Indicate error and stay in while loop.
         Error();
         while(1);
    }     

    // Erase Flash (Block Erase the program Flash)
    EraseFlash();
    // Initialize the state-machine to read the records.
    record.status = REC_NOT_FOUND;

     while(1)
     {
         ClrWdt();

         // For a faster read, read 512 bytes at a time and buffer it.
         readBytes = FSfread((void *)&asciiBuffer[pointer],1,512,myFile);

         if(readBytes == 0)
         {
             // Nothing to read. Come out of this loop
             // break;
             FSfclose(myFile);
             // Something fishy. The hex file has ended abruptly, looks like there was no "end of hex record".
             //Indicate error and stay in while loop.
             Error();
             while(1);             
         }

         for(i = 0; i < (readBytes + pointer); i ++)
         {

          // This state machine seperates-out the valid hex records from the read 512 bytes.
             switch(record.status)
             {
                 case REC_FLASHED:
                 case REC_NOT_FOUND:
                     if(asciiBuffer[i] == ':')
                     {
                      // We have a record found in the 512 bytes of data in the buffer.
                         record.start = &asciiBuffer[i];
                         record.len = 0;
                         record.status = REC_FOUND_BUT_NOT_FLASHED;
                     }
                     break;
                 case REC_FOUND_BUT_NOT_FLASHED:
                     if((asciiBuffer[i] == 0x0A) || (asciiBuffer[i] == 0xFF))
                     {
                      // We have got a complete record. (0x0A is new line feed and 0xFF is End of file)
                         // Start the hex conversion from element
                         // 1. This will discard the ':' which is
                         // the start of the hex record.
                         ConvertAsciiToHex(&record.start[1],hexRec);
                         WriteHexRecord2Flash(hexRec);
                         record.status = REC_FLASHED;
                     }
                     break;
             }
             // Move to next byte in the buffer.
             record.len ++;
         }

         if(record.status == REC_FOUND_BUT_NOT_FLASHED)
         {
          // We still have a half read record in the buffer. The next half part of the record is read 
          // when we read 512 bytes of data from the next file read. 
             memcpy(asciiBuffer, record.start, record.len);
             pointer = record.len;
             record.status = REC_NOT_FOUND;
         }
         else
         {
             pointer = 0;
         }
         // Blink LED at Faster rate to indicate programming is in progress.
         led += 3;
         mLED = ((led & 0x80) == 0);

     }//while(1)


    return 0;
}
EN

回答 2

Stack Overflow用户

发布于 2016-03-14 14:00:40

如果我记得清楚(很久以前我使用了PIC32),您可以添加到链接器脚本中:

代码语言:javascript
复制
MEMORY
{
   //... other stuff
   signature (RX) : ORIGIN = 0x9FC02FEC, length 0x4
} 

然后

代码语言:javascript
复制
SECTIONS
{
   .signature_section:
   {
      BYTE(0x3b);
      BYTE(0xdf);
      BYTE(0xed);
      BYTE(0x92);
   }>signature
}

在谷歌上搜索我也发现,你可以在你的源代码中这样做,我希望.

代码语言:javascript
复制
const int __attribute__((space(prog), address(0x9FC02FEC))) signature = 0x3bdfed92; 
票数 1
EN

Stack Overflow用户

发布于 2016-03-14 14:13:04

在我的程序中,我使用一个属性将某个值放置在内存空间中的某个位置。我的引导程序和应用程序可以读取这个位置。对你来说,这可能是一种更简单的方法。这是使用xc16和一个较小的部分,但我也是在PIC32上完成的。

代码语言:javascript
复制
#define CHECK_SUM 0x45FB
#define CH_HIGH ((CHECK_SUM & 0xFF00) >> 8)
#define CH_LOW  ((CHECK_SUM & 0x00FF) >> 0)
const char __attribute__((space(prog), address(APP_CS_LOC))) CHKSUM[2] = {CH_LOW,CH_HIGH};

只要一张便条,当你读到它时,它将是正确的格式:高->低。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35988654

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档