请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
器件型号:MSP430FR5962 各位专家、您好!
能不能有人检查下面的代码并告诉我为什么 MPU 不能清除段2标志。 当我尝试清除段2标志时、我的器件将被复位。 我还在评论中提到了器件复位的位置。 请查找以下代码:
#include <MSP430FR5962.h>
unsigned int *ptr = 0;
unsigned int Data =0;
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop WDT
// Configure GPIO
P1DIR |= BIT0; // Configure P1.0 for LED
// Disable the GPIO power-on default high-impedance mode to activate
// previously configured port settings
PM5CTL0 &= ~LOCKLPM5;
while (MPUCTL1 & MPUSEG2IFG) // has reset occurred due to Seg2
{
P1OUT ^= BIT0; // Toggle LED
__delay_cycles(30000); // Delay to see toggle
/* it is getting reset after the violation when it is trying to execute the below statements*/
MPUCTL0 &= ~MPUENA;
MPUCTL1 &= ~MPUSEG2IFG;
}
// Configure MPU
MPUCTL0 = MPUPW; // Write PWD to access MPU registers
MPUSEGB1 = 0x0F00; // B1 = 0x6000; B2 = 0x8000
MPUSEGB2 = 0x0FF7; // Borders are assigned to segments
// Segment 1 - Execute, Read
// Segment 2 - Violation, Execute, Read
// Segment 3 - Execute, Read
MPUSAM = MPUSEG1RE | MPUSEG1XE | MPUSEG1WE |
MPUSEG2VS | MPUSEG2RE | MPUSEG2XE |
MPUSEG3RE | MPUSEG3XE | MPUSEG3WE |
MPUSEGIRE | MPUSEGIXE | MPUSEGIWE;
MPUCTL0 = MPUPW | MPUENA | MPUSEGIE;
Data = 0x88;
// Cause an MPU violation by writing to segment 2
ptr = (unsigned int *)0xF002;
*ptr = Data;
while(1); // Code never gets here
}