/* * FlexNVM.h * * Created on: 24. nov 2025 * Author: oliver.voorel */ #ifndef FLEXNVM_H_ #define FLEXNVM_H_ #include "S32K118.h" #include "main.h" /* Datasheet page 783 CHIP | P-FLASH | Flex-NVM | Flex-RAM | S32K116 | 128 KB | 32 KB | 2 KB | S32K118 | 256 KB | 32 KB | 2 KB | */ /* DEFINES */ #define FCCOB_3 0 #define FCCOB_2 1 #define FCCOB_1 2 #define FCCOB_0 3 #define FCCOB_7 4 #define FCCOB_6 5 #define FCCOB_5 6 #define FCCOB_4 7 #define FCCOB_B 8 #define FCCOB_A 9 #define FCCOB_9 0xA #define FCCOB_8 0xB #define FTFC_RD1BLCK_CMD 0x00 #define FTFC_RD1SCTN_CMD 0x01 #define FTFC_PGMCHK_CMD 0x02 #define FTFC_PGM8_CMD 0x07 #define FTFC_ERSBLK_CMD 0x08 #define FTFC_ERSSCTN_CMD 0x09 #define FTFC_RD1SALL_CMD 0x40 #define FTFC_PGMPART_CMD 0x80 #define DFLASH_START 0x10000000 #define DFLASH_END 0x10007fff /* For non-CSEc enabled parts, the number of Flash Keys must be configured as 2'b00 (no keys). FCCOB1[1:0] | Nr of keys | Nr of Bytes (subtracts from total EEERAM) 2'b00 | Zero | 0 2'b01 | 1 to 5 keys | 128 Bytes 2'b10 | 1 to 10 keys| 256 Bytes 2'b11 | 1 to 20 keys| 512 Bytes */ #define FTFC_CSEC 0x00 /* The FCCOB[2] field is for the enhanced Security Flag Extension (SFE) is in a 8-bit field, but only bit [0] is used (bits [7:1] are ignored). This feature is an extension to the SHE specification. For standard SHE usage model, the user should configure this as 'not enabled' (SFE == 0x00). */ #define FTFC_SFE 0x00 /* EEPROM Load on Reset — Determines whether the flash reset sequence takes time to load the FlexRAM with valid EEPROM data. '0' = FlexRAM is not loaded with valid EEPROM data during the flash reset sequence (see the Set FlexRAM Function command to load the FlexRAM with valid EEPROM data) '1' = FlexRAM is loaded with valid EEPROM data during the flash reset sequence For CSEc enabled parts, the FlexRAM is always loaded with valid EEPROM data during the flash reset sequence, and will include the inaccessible Key addresses as applicable. */ #define FTFC_EEERST 0 /* EEPROM Size — Encoding of the total available FlexRAM for emulated EEPROM use. NOTE: 1. EEESIZE must be 0 bytes (1111b) when the FlexNVM partition code is set to 'NoEEPROM'. 2. For CSEc enabled parts, the EEE size must be b'0011' - 2,048 Bytes b'0000 0000' = Reserved b'0000 0001' = Reserved b'0000 0010' = Reserved b'0000 0011' = 2,048 Bytes b'0000 0100' = Reserved b'0000 0101' = Reserved b'0000 0110' = Reserved b'0000 0111' = Reserved b'0000 1000' = Reserved b'0000 1001' = Reserved b'0000 1010' = Reserved b'0000 1011' = Reserved b'0000 1100' = Reserved b'0000 1101' = Reserved b'0000 1110' = Reserved b'0000 1111' = 0 Bytes */ #define FTFC_EEESIZE 0x03 /* FlexNVM Partition Code — Encoding of the data flash / emulated EEPROM backup split within the FlexNVM memory block. FlexNVM memory not partitioned for data flash is used to store EEPROM records. DEPART | D-FLASH(KB) | EEPROM (KB) b0000 0000 | 32 | 0 b0000 0011 | 0 | 32 b0000 1000 | 0 | 32 b0000 1001 | 8 | 24 b0000 1011 | 32 | 0 b0000 1111 | DEFAULT | - */ #define FTFC_DEPART 0x03 /* Command Complete Interrupt Enable The CCIE bit controls interrupt generation when an FTFC/CSEc command completes. 0b - Command complete interrupt disabled 1b - Command complete interrupt enabled. An interrupt request is generated whenever the FSTAT[CCIF] flag is set. */ #define FTFC_CCIE 0 /* Read Collision Error Interrupt Enable The RDCOLLIE bit controls interrupt generation when an FTFC read collision error occurs. 0b - Read collision error interrupt disabled 1b - Read collision error interrupt enabled. An interrupt request is generated whenever an FTFC read collision error is detected (see the description of FSTAT[RDCOLERR]) */ #define FTFC_RDCOLLIE 0 /* PRIVATE TYPES */ typedef enum{ FLEX_NVM_OK = 0 , FLEX_NVM_CONFIGURED = 1 , FLEX_NVM_PROGRAMMED = 2 , FLEX_NVM_ERR = -1, FLEX_NVM_PROTECTION_VIOLATION = -2, } Flex_NVM_statusType; typedef enum{ MARGIN_NORMAL = 0x00, MARGIN_USER = 0x01, MARGIN_FACTORY = 0x02, } FlexNVM_margin; /* PROTOTYPES */ Flex_NVM_statusType init_FlexNVM(void); Flex_NVM_statusType FlexNVM_RD1SALL(FlexNVM_margin margin); Flex_NVM_statusType FlexNVM_PGM8(uint64_t adr, uint8_t* data); Flex_NVM_statusType FlexNVM_ERSBLK(uint64_t adr); Flex_NVM_statusType FlexNVM_RD1BLCK(uint64_t adr, FlexNVM_margin margin); uint8_t get_FlexNVM_status(void); void launch_FlexNVM_CMD(void); bool FlexNVM_RAMRDY(void); bool FlexNVM_EEERDY(void); bool FlexNVM_RDY(void); #endif /* FLEXNVM_H_ */