主题中讨论的其他器件:MSPWARE
你好
我想使用 FRAM 来为我的应用程序存储一些持久变量。 这些是校准变量、所以它们必须是写入/读取的。
我遵循了 CCS/Resource Explorer/MSPware 中的"msp430fr267x_framwrite_persistent.c"示例、该示例运行起来非常顺利、但我不知道这些变量存储在 FRAM 的哪个位置
#include <msp430.h> // Statically-initialized variable #ifdef __TI_COMPILER_VERSION__ #pragma PERSISTENT(Port_event) unsigned long Port_event = 0; #elif __IAR_SYSTEMS_ICC__ __persistent unsigned long Port_event = 0; #else // Port the following variable to an equivalent persistent functionality for the specific compiler being used unsigned long Port_event = 0; #endif void initGpio(void); int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop WDT // Configure GPIO initGpio(); // Determine whether we are coming out of an LPMx.5 or a regular RESET. if (SYSRSTIV == SYSRSTIV_LPM5WU) // MSP430 just woke up from LPMx.5 { // Add the variable Port_event in FRAM to record the button event // Write protection starts from the beginning of Program FRAM + 1024 bytes // Code start address + 1024 bytes, Linker command file should be modified SYSCFG0 = FRWPPW | FRWPOA0 | DFWP | PFWP;// Configure 1024 bytes for FRAM write Port_event++; // Record the port event in FRAM SYSCFG0 = FRWPPW | DFWP | PFWP; // Program FRAM write protected (not writable) do { P1OUT |= BIT0; // P1.0 = toggle __delay_cycles(100000); P1OUT &= ~BIT0; // P1.0 = toggle __delay_cycles(100000); }while (Port_event >= 5); // Recorded 5 port interrupts? } // Device powered up from a cold start. // It configures the device and puts the device into LPM4.5 P1DIR &= ~(BIT2); // Configure P1.2 as input direction pin P1OUT |= BIT2; // Configure P1.2 as pulled-up P1REN |= BIT2; // P1.2 pull-up register enable P1IES |= BIT2; // P1.2 Hi/Low edge P1IFG = 0; // Clear all P1 interrupt flags P1IE |= BIT2; // P1.2 interrupt enabled // Explicitly clear RTC control registers to disable it // just incase if the RTC was previously enabled RTCCTL = 0; PMMCTL0_H = PMMPW_H; // Open PMM Registers for write PMMCTL0_L |= PMMREGOFF; // and set PMMREGOFF PMMCTL0_H = 0; // Lock PMM Registers // Enter LPM4 Note that this operation does not return. The LPM4.5 // will exit through a RESET event, resulting in a re-start // of the code. __bis_SR_register(LPM4_bits | GIE); }
-- pragma persistent
#pragma PERSISTENT (端口事件)
无符号长整型 PORT_EVENT = 0;
--写变量
//在 FRAM 中添加变量 PORT_EVENT 以记录按钮事件
//写保护从程序 FRAM + 1024字节的开头开始
//代码起始地址+ 1024字节,应修改连接器命令文件
SYSCFG0 = FRWPPW | FRWPOA0 | DFWP | PFWP;//配置1024个字节进行 FRAM 写入
PORT_EVENT++;//在 FRAM 中记录端口事件
SYSCFG0 = FRWPPW | DFWP | PFWP;//程序 FRAM 受写保护(不可写)
在该示例的说明中提到 " 应修改链接器命令文件以更改存储器分区并指定 persistent 变量的位置"
能否提供有关如何将 persistent 变量"放置"到不同存储器位置的一些示例?
查看应用报告 SLAA628b、示例3 (针对 CCS)显示了如何分配一个新的内存块+定义一个存储在这个内存块中的段。
1.分配一个新的存储块(MY_SECTION)。
2.定义存储在此存储块(MY_SECTION)中的段(.Image)。
3.在程序中使用#pragma DATA_SECTION 来定义此段中的变量。
RAM : origin = 0x2000, length = 0x400 RAM2 : origin = 0xF100, length = 0x100 MY_SECTION : origin = 0xF200, length = 0x100 FRAM : origin = 0xF300, length = 0xC80 .Image : {} > MY_SECTION #pragma DATA_SECTION(a,".Image") unsigned char a;
问题是我无法使用第一个例子中的"--write variable"方法在这个新内存块上写入变量。
我是否应该在 FRAM 段内声明这个新的内存块? 如果是这种情况、您能否向我指出如何实现?
此外、我不知道创建新的内存块而不是使用已声明的持久内存是否是一个好的做法
此致