0

我想在 Flash 中放置一个表格并直接从我的 C 程序中读取它。根据 Microchip 的说法,这是由微芯片完成的,__attribute__((space(psv)))但是,作为微芯片周围的大多数事情,他们自己的示例效果不佳(通常已过时且未更新):https ://microchipdeveloper.com/16bit:psv

所以这就是我想要做的:

uint16_t __attribute__((space(psv))) ConfDiskImage[] = {
    /*AOUT*/ 0x01E0,0x0004,0x3333,0x4053,
    /*   1*/ 0x01E1,0x0012,0x0005,0x0000,0x0000,0x0000,0x4120,0x0000,0x0000,0x0000,0x4120,
    /*   2*/ 0x01E2,0x0012,0x0006,0x0000,0x0000,0x0000,0x4120,0x0000,0x0000,0x0000,0x4120,
    /*   3*/ 0x01E3,0x0012,0x0007,0x0000,0x0000,0x0000,0x4120,0x0000,0x0000,0x0000,0x4120,
    /*EOD */ 0x0000,0x0000
};

当我编译时,我得到:"warning: ignoring space attribute applied to automatic ConfDiskImage"

我正在使用 MPLAB X IDE 5.45 和 XC16-gcc v1.50。微控制器:dsPIC33EP256MC506

关于如何让它留在闪存中(不被复制到 RAM)并用指针直接从闪存读取它的任何想法?

4

1 回答 1

0

我怀疑您真正需要的可能更多,但您提出的问题的简单答案是使用const存储类。

例如:

/*
 * File:   main.c
 * Author: dan1138
 * Target: dsPIC33EP256MC506
 * Compiler: XC16 v1.61
 * IDE: MPLABX v5.45
 *
 * Created on February 19, 2021, 11:56 PM
 */

#pragma config ICS = PGD2, JTAGEN = OFF, ALTI2C1 = OFF, ALTI2C2 = OFF, WDTWIN = WIN25
#pragma config WDTPOST = PS32768, WDTPRE = PR128, PLLKEN = ON, WINDIS = OFF
#pragma config FWDTEN = OFF, POSCMD = NONE, OSCIOFNC = ON, IOL1WAY = OFF, FCKSM = CSECMD
#pragma config FNOSC = FRCDIVN, PWMLOCK = OFF, IESO = ON, GWRP = OFF, GCP = OFF

#include "xc.h"

const uint16_t ConfDiskImage[] = {
    /*AOUT*/ 0x01E0,0x0004,0x3333,0x4053,
    /*   1*/ 0x01E1,0x0012,0x0005,0x0000,0x0000,0x0000,0x4120,0x0000,0x0000,0x0000,0x4120,
    /*   2*/ 0x01E2,0x0012,0x0006,0x0000,0x0000,0x0000,0x4120,0x0000,0x0000,0x0000,0x4120,
    /*   3*/ 0x01E3,0x0012,0x0007,0x0000,0x0000,0x0000,0x4120,0x0000,0x0000,0x0000,0x4120,
    /*EOD */ 0x0000,0x0000
};

int main(void) 
{
    const uint16_t *pData;
    
    pData = ConfDiskImage; /* point to the start of the image */
    /*
     * Walk the image
     */
    for(;;)
    {
        if((!*pData) && (!*pData+1))
        {
            /* At end of image point to the start */
            pData = ConfDiskImage;
        }
        pData++; /* skip record type */
        pData += 1+*pData/2;
    }
    return 0;
}
于 2021-02-20T08:38:26.960 回答