SmartSnippets DA1459x SDK
qspi_macronix_v2.h
Go to the documentation of this file.
1 
42 #ifndef _QSPI_MACRONIX_V2_H_
43 #define _QSPI_MACRONIX_V2_H_
44 
45 #include "qspi_common.h"
46 
47 #define QSPI_MACRONIX_MANUFACTURER_ID (0xC2)
48 #define QSPI_MACRONIX_MX25U_TYPE (0x25)
49 #define QSPI_MACRONIX_MX25R_TYPE (0x28)
50 
51 #define QSPI_MACRONIX_READ_CONFIG_REG_OPCODE (0x15)
52 #define QSPI_MACRONIX_READ_SECURITY_REG_OPCODE (0x2B)
53 
54 #define QSPI_MACRONIX_PAGE_PROGRAM_4IO_OPCODE (0x38)
55 
56 #define QSPI_MACRONIX_SUSPEND_OPCODE (0xB0)
57 #define QSPI_MACRONIX_RESUME_OPCODE (0x30)
58 
59 #define QSPI_MACRONIX_STATUS_REG_QUAD_ENABLE_BIT (6)
60 #define QSPI_MACRONIX_STATUS_REG_QUAD_ENABLE_MASK (1 << QSPI_MACRONIX_STATUS_REG_QUAD_ENABLE_BIT)
61 
62 #define QSPI_MACRONIX_STATUS_REG3_ADDR_MODE_BIT (0)
63 #define QSPI_MACRONIX_STATUS_REG3_ADDR_MODE_MASK (1 << QSPI_MACRONIX_STATUS_REG3_ADDR_MODE_BIT)
64 
65 #define QSPI_MACRONIX_STATUS_REG3_DRV_STRENGTH_BITS (5)
66 #define QSPI_MACRONIX_STATUS_REG3_DRV_STRENGTH_MASK (3 << QSPI_MACRONIX_STATUS_REG3_DRV_STRENGTH_BITS)
67 
68 #define QSPI_MACRONIX_SECURITY_REG_ERASE_SUSPEND_BIT (3)
69 #define QSPI_MACRONIX_SECURITY_REG_ERASE_SUSPEND_MASK (1 << QSPI_MACRONIX_SECURITY_REG_ERASE_SUSPEND_BIT)
70 
71 #define QSPI_MACRONIX_SECURITY_REG_PROGRAM_SUSPEND_BIT (2)
72 #define QSPI_MACRONIX_SECURITY_REG_PROGRAM_SUSPEND_MASK (1 << QSPI_MACRONIX_SECURITY_REG_PROGRAM_SUSPEND_BIT)
73 
74 #define QSPI_MACRONIX_SECURITY_REG_SUSPEND_MASK (QSPI_MACRONIX_SECURITY_REG_ERASE_SUSPEND_MASK | \
75  QSPI_MACRONIX_SECURITY_REG_PROGRAM_SUSPEND_MASK)
76 
77 __UNUSED __RETAINED_CODE static uint8_t qspi_macronix_read_register(HW_QSPIC_ID id, uint8_t opcode, uint8_t mask)
78 {
79  __DBG_QSPI_VOLATILE__ uint8_t reg_val;
80 
81  ASSERT_WARNING((opcode == QSPI_READ_STATUS_REG_OPCODE) ||
82  (opcode == QSPI_MACRONIX_READ_CONFIG_REG_OPCODE) ||
83  (opcode == QSPI_MACRONIX_READ_SECURITY_REG_OPCODE));
84 
86  hw_qspi_write8(id, opcode);
87  reg_val = hw_qspi_read8(id);
89 
90  return (reg_val & mask);
91 }
92 
93 // This function is used by macronix flash memory families where the status register and the
94 // configuration register are modified simultaneously.
95 __UNUSED __RETAINED_CODE static void qspi_macronix_write_status_and_config_reg(HW_QSPIC_ID id, uint8_t status_reg, uint8_t config_reg)
96 {
97  // The hw_qspi_write16() swaps the MSB with LSB, therefore the status_reg and config_reg
98  // are swapped in regs too.
99  __DBG_QSPI_VOLATILE__ uint16_t regs = ((((uint16_t) (status_reg)) << 8) & 0xFF00) | config_reg;
100 
101  hw_qspi_cs_enable(id);
102  hw_qspi_write8(id, QSPI_WRITE_STATUS_REG_OPCODE);
103  hw_qspi_write16(id, regs);
104  hw_qspi_cs_disable(id);
105 }
106 
107 __UNUSED __RETAINED_CODE static uint8_t qspi_macronix_read_status_reg(HW_QSPIC_ID id)
108 {
109  return qspi_macronix_read_register(id, QSPI_READ_STATUS_REG_OPCODE, 0xFF);
110 }
111 
112 __UNUSED __RETAINED_CODE static void qspi_macronix_write_status_reg(HW_QSPIC_ID id, uint8_t status_reg)
113 {
114  __DBG_QSPI_VOLATILE__ uint8_t config_reg;
115 
116  config_reg = qspi_macronix_read_register(id, QSPI_MACRONIX_READ_CONFIG_REG_OPCODE, 0xFF);
117  qspi_macronix_write_status_and_config_reg(id, status_reg, config_reg);
118 }
119 
120 __UNUSED __RETAINED_CODE static bool qspi_macronix_is_suspended(HW_QSPIC_ID id)
121 {
122  __DBG_QSPI_VOLATILE__ uint8_t is_suspended;
123 
124  is_suspended = qspi_macronix_read_register(id, QSPI_MACRONIX_READ_SECURITY_REG_OPCODE,
125  QSPI_MACRONIX_SECURITY_REG_SUSPEND_MASK);
126  return (bool) is_suspended;
127 }
128 
129 __UNUSED __RETAINED_CODE static bool qspi_macronix_is_busy(HW_QSPIC_ID id, HW_QSPI_BUSY_LEVEL busy_level)
130 {
131  __DBG_QSPI_VOLATILE__ HW_QSPI_BUSY_LEVEL is_busy;
132 
133  is_busy = (HW_QSPI_BUSY_LEVEL) (qspi_macronix_read_status_reg(id) & QSPI_STATUS_REG_BUSY_MASK);
134 
135  return (bool) (is_busy == busy_level);
136 }
137 
138 #endif /* _QSPI_MACRONIX_V2_H_ */
139 
HW_QSPIC_ID
void * HW_QSPIC_ID
QSPI Controller ID.
Definition: hw_qspi_v2.h:439
hw_qspi_cs_enable
__STATIC_FORCEINLINE void hw_qspi_cs_enable(HW_QSPIC_ID id)
Enable CS on QSPI bus in manual access mode.
Definition: hw_qspi_v2.h:525
__UNUSED
#define __UNUSED
Attribute to silence warnings about unused parameters/variables/function.
Definition: sdk_defs.h:380
HW_QSPI_BUSY_LEVEL
HW_QSPI_BUSY_LEVEL
QSPIC device busy status setting.
Definition: hw_qspi_v2.h:94
hw_qspi_read8
__STATIC_FORCEINLINE uint8_t hw_qspi_read8(HW_QSPIC_ID id)
Generate 8 bits data transfer from the external device to the QSPIC (manual mode)
Definition: hw_qspi_v2.h:1127
hw_qspi_write16
__STATIC_FORCEINLINE void hw_qspi_write16(HW_QSPIC_ID id, uint16_t data)
Generate 16 bits data transfer from the QSPIC to the external device (manual mode)
Definition: hw_qspi_v2.h:1154
hw_qspi_write8
__STATIC_FORCEINLINE void hw_qspi_write8(HW_QSPIC_ID id, uint8_t data)
Generate 8 bits data transfer from the QSPIC to the external device (manual mode)
Definition: hw_qspi_v2.h:1167
hw_qspi_cs_disable
__STATIC_FORCEINLINE void hw_qspi_cs_disable(HW_QSPIC_ID id)
Disable CS on QSPI bus in manual access mode.
Definition: hw_qspi_v2.h:535
qspi_common.h
QSPI flash driver common definitions.