我知道有几种方法定义到FLASH(FRAM)里
比如:const int x @ 0x3333 = 123;
不过好像只能是const的,我想把一些变量也放到FRAM里,程序运行的过程中,可以随时更改,这样就不用检测电源掉电了。
如果掉电,复位电路复位后重新运行程序,在FRAM里读取这些变量就可以了。
不知道怎么把变量也定义到FRAM里,请各位指教下。IAR环境,谢谢了~
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Guo Yan 说:我知道有几种方法定义到FLASH(FRAM)里
比如:const int x @ 0x3333 = 123;
不过好像只能是const的,我想把一些变量也放到FRAM里,程序运行的过程中,可以随时更改,这样就不用检测电源掉电了。
如果掉电,复位电路复位后重新运行程序,在FRAM里读取这些变量就可以了。
不知道怎么把变量也定义到FRAM里,请各位指教下。IAR环境,谢谢了~
用
__persistent 来定义
*******************************************************************************
*
* MSP430 CODE EXAMPLE DISCLAIMER
*
* MSP430 code examples are self-contained low-level programs that typically
* demonstrate a single peripheral function or device feature in a highly
* concise manner. For this the code may rely on the device's power-on default
* register values and settings such as the clock configuration and care must
* be taken when combining code from several examples to avoid potential side
* effects. Also see www.ti.com/grace for a GUI- and www.ti.com/msp430ware
* for an API functional library-approach to peripheral configuration.
*
* --/COPYRIGHT--*/
//******************************************************************************
// MSP430FR243x Demo - FRAM write, use #pragma PERSISTENT to initialize variable in FRAM.
//
// Description: Program use #pragma PERSISTENT(in CCS) or __persistent(in IAR)
// to statically-initialize variable Port_event in FRAM.
// Download and run the program. Program automatically enters
// LPM4.5 and measure the current. Use button S1 (or P1.3) on the
// target board to wake the device up from LPM4.5 and toggle the
// LED (on P1.0). The interrupt times will be recorded in FRAM
// and blink the LED (on P1.0) if more than 5 times.
//
// This demo was tested on MSP-EXP430FR2433 target board.
//
// ACLK = XT1 = 32kHz, MCLK = SMCLK = default DCODIV = ~1MHz.
//
// MSP430FR2433
// -----------------
// /|\| |
// | | |
// | | |
// --|RST |
// | |
// | |
// | P1.0|-->LED
// | |
// | P1.3|<--- S1 push-button
//
// Ling Zhu
// Texas Instruments Inc.
// Aug 2015
// Built with IAR Embedded Workbench v6.10 & Code Composer Studio v6.0.1
//******************************************************************************
#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
SYSCFG0 = FRWPPW | DFWP; // Program FRAM write enable
Port_event++; // Record the port event in FRAM
SYSCFG0 = FRWPPW | PFWP | DFWP; // 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 &= ~(BIT3); // Configure P1.3 as input direction pin
P1OUT |= BIT3; // Configure P1.3 as pulled-up
P1REN |= BIT3; // P1.3 pull-up register enable
P1IES |= BIT3; // P1.3 Hi/Low edge
P1IFG = 0; // Clear all P1 interrupt flags
P1IE |= BIT3; // P1.3 interrupt enabled
// Explicitly clear RTC control registers to disable it
// just incase if the RTC was previously enabled
RTCCTL = 0;
#ifdef __MSP430_HAS_LCD_E__
// Explicitly disable the LCD module
// just incase if the LCD was previously enabled
LCDCTL0 = 0;
#endif
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);
}
void initGpio()
{
P1DIR = 0xFB; P2DIR = 0xFF; P3DIR = 0xFF;
P1REN = 0xFF; P2REN = 0xFF; P3REN = 0xFF;
P1OUT = 0x00; P2OUT = 0x00; P3OUT = 0x00;
// Disable the GPIO power-on default high-impedance mode
// to activate previously configured port settings
PM5CTL0 &= ~LOCKLPM5;
}