MPC5744 Registers Protection

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

MPC5744 Registers Protection

1,241 次查看
ahmedsoubky
Contributor II

Hello,

According to the MPC5744 reference manual REG_PROT is a generic module and the mechanisms explained apply to different microcontroller registers sets.

As the generic explanation is hard to apply on specific modules, would you please provide example code how to enable the hard lock on any peripheral  ( for instance SPI or any other module).

Thanks in advance,

Best Regards

标签 (1)
0 项奖励
1 回复

967 次查看
lukaszadrapa
NXP TechSupport
NXP TechSupport

Hi,

here is a piece of code that I found in my repository. Originally it was written for MPC5604E but it's the same for MPC5744P. Used header file is attached. It's just test code to see how it works:

    unsigned int lock = 0;

    //just write something to DSPI_A.MCR register to see we can write the register
    DSPI_A.MCR.R = 0xFFFFFFFF;
    DSPI_A.MCR.R = 0x00000000;
    
    //get the lock status of this register. It will be zero because protection is not active
    GET_SOFTLOCK(DSPI_A.MCR.R, lock);
    
    //write new value to register and lock the register for further access
    DSPI_A.MCR.R = WRITE_WITH_LOCK32(DSPI_A.MCR.R,0xFFFFFFFF);
    
    //this write will not work because register is protected
    DSPI_A.MCR.R = 0x00000000;
    
    //get the lock status - it will be 0x0F - all four bytes are locked
    GET_SOFTLOCK(DSPI_A.MCR.R, lock);
    
    //clear the lock bits
    CLR_SOFTLOCK32(DSPI_A.MCR.R);
    
    //we can write the register again
    DSPI_A.MCR.R = 0x00000000;
    
    //get the lock status - it will be zero, protection is not active
    GET_SOFTLOCK(DSPI_A.MCR.R, lock);
    
    //set lock
    SET_SOFTLOCK32(DSPI_A.MCR.R);
    
    //try to write the register - it will not work
    DSPI_A.MCR.R = 0xFFFFFFFF;
    
    //and check status...
    GET_SOFTLOCK(DSPI_A.MCR.R, lock);

Regards,

Lukas