Driver API for QSPI (plib_qspi.h) More...
Data Structures | |
| struct | QSPI_INSTRUCTION_FRAME |
| Description of one Serial Memory mode instruction frame (QSPI_IFR). More... | |
Macros | |
| #define | QSPI_MEMORY_BASE_ADDRESS (QSPIMEM_ADDR) |
| Base address of the memory-mapped QSPI window (QSPIMEM). | |
| #define | QSPI_MEMORY_SIZE (QSPIMEM_SIZE) |
| Size of the memory-mapped QSPI window in bytes. | |
| #define | QSPI_BAUD_MAX (QSPI_SCR_SCBR_Msk >> QSPI_SCR_SCBR_Pos) |
| Maximum value of the serial clock baud rate divider (QSPI_SCR.SCBR). | |
| #define | QSPI_DUMMY_CYCLES_MAX (QSPI_IFR_NBDUM_Msk >> QSPI_IFR_NBDUM_Pos) |
| Maximum number of dummy cycles (QSPI_IFR.NBDUM). | |
| #define | QSPI_DELAY_MAX (QSPI_MR_DLYBCT_Msk >> QSPI_MR_DLYBCT_Pos) |
| Maximum value of any of the QSPI delay fields (DLYBS, DLYBCT, DLYCS). | |
| #define | QSPI_WPMR_UNLOCK_KEY (QSPI_WPMR_WPKEY_PASSWD_Val) |
| Password that must accompany a write to QSPI_WPMR.WPEN. | |
| #define | QSPI_INTERRUPT_NONE (0x00000000U) |
| #define | QSPI_INTERRUPT_RDRF (QSPI_IER_RDRF_Msk) |
| #define | QSPI_INTERRUPT_TDRE (QSPI_IER_TDRE_Msk) |
| #define | QSPI_INTERRUPT_TXEMPTY (QSPI_IER_TXEMPTY_Msk) |
| #define | QSPI_INTERRUPT_OVRES (QSPI_IER_OVRES_Msk) |
| #define | QSPI_INTERRUPT_CSR (QSPI_IER_CSR_Msk) |
| #define | QSPI_INTERRUPT_CSS (QSPI_IER_CSS_Msk) |
| #define | QSPI_INTERRUPT_INSTRE (QSPI_IER_INSTRE_Msk) |
| #define | QSPI_INTERRUPT_ALL (QSPI_IER_Msk) |
| #define | QSPI_STATUS_FLAG_NONE (0x00000000U) |
| #define | QSPI_STATUS_FLAG_RDRF (QSPI_SR_RDRF_Msk) |
| #define | QSPI_STATUS_FLAG_TDRE (QSPI_SR_TDRE_Msk) |
| #define | QSPI_STATUS_FLAG_TXEMPTY (QSPI_SR_TXEMPTY_Msk) |
| #define | QSPI_STATUS_FLAG_OVRES (QSPI_SR_OVRES_Msk) |
| #define | QSPI_STATUS_FLAG_CSR (QSPI_SR_CSR_Msk) |
| #define | QSPI_STATUS_FLAG_CSS (QSPI_SR_CSS_Msk) |
| #define | QSPI_STATUS_FLAG_INSTRE (QSPI_SR_INSTRE_Msk) |
| #define | QSPI_STATUS_FLAG_QSPIENS (QSPI_SR_QSPIENS_Msk) |
| #define | QSPI_STATUS_FLAG_ALL (QSPI_SR_Msk) |
| #define | QSPI_STATUS_FLAG_READ_TO_CLEAR (QSPI_SR_OVRES_Msk | QSPI_SR_CSR_Msk | QSPI_SR_INSTRE_Msk) |
| The subset of QSPI_SR flags that are cleared by reading the register. | |
| #define | QSPI_ERROR_NONE (0x00U) |
| #define | QSPI_ERROR_OVERRUN (0x01U) |
Typedefs | |
| typedef uint32_t | QSPI_INTERRUPT_SOURCE |
| QSPI interrupt source bitmask type. | |
| typedef uint32_t | QSPI_STATUS_FLAG |
| QSPI status flag bitmask type (QSPI_SR). | |
| typedef uint32_t | QSPI_ERROR |
| QSPI error status bitmask type. | |
| typedef void(* | QSPI_CALLBACK) (QSPI_STATUS_FLAG status) |
| QSPI callback function type. | |
Enumerations | |
| enum | QSPI_HWREG_STATUS { QSPI_HWREG_OK = 0 , QSPI_HWREG_ERROR , QSPI_HWREG_INVALID_PARAM , QSPI_HWREG_TIMEOUT , QSPI_HWREG_BUSY , QSPI_HWREG_UNSUPPORTED } |
| Result of a QSPI hardware register operation. More... | |
| enum | QSPI_OPERATING_MODE { QSPI_OPERATING_MODE_SPI = (int32_t)QSPI_MR_SMM_SPI_Val , QSPI_OPERATING_MODE_MEMORY = (int32_t)QSPI_MR_SMM_MEMORY_Val } |
| QSPI operating mode (QSPI_MR.SMM). More... | |
| enum | QSPI_CHIP_SELECT_MODE { QSPI_CHIP_SELECT_MODE_NOT_RELOADED = (int32_t)QSPI_MR_CSMODE_NOT_RELOADED_Val , QSPI_CHIP_SELECT_MODE_LASTXFER = (int32_t)QSPI_MR_CSMODE_LASTXFER_Val , QSPI_CHIP_SELECT_MODE_SYSTEMATICALLY = (int32_t)QSPI_MR_CSMODE_SYSTEMATICALLY_Val } |
| Chip select behaviour at the end of a transfer (QSPI_MR.CSMODE). More... | |
| enum | QSPI_TRANSFER_SIZE { QSPI_TRANSFER_SIZE_8BIT = 0 , QSPI_TRANSFER_SIZE_9BIT = 1 , QSPI_TRANSFER_SIZE_10BIT = 2 , QSPI_TRANSFER_SIZE_11BIT = 3 , QSPI_TRANSFER_SIZE_12BIT = 4 , QSPI_TRANSFER_SIZE_13BIT = 5 , QSPI_TRANSFER_SIZE_14BIT = 6 , QSPI_TRANSFER_SIZE_15BIT = 7 , QSPI_TRANSFER_SIZE_16BIT = 8 } |
| Number of bits per transfer in SPI mode (QSPI_MR.NBBITS). More... | |
| enum | QSPI_CLOCK_POLARITY { QSPI_CLOCK_POLARITY_IDLE_LOW = 0 , QSPI_CLOCK_POLARITY_IDLE_HIGH = 1 } |
| Inactive state of QSCK (QSPI_SCR.CPOL). More... | |
| enum | QSPI_CLOCK_PHASE { QSPI_CLOCK_PHASE_CAPTURE_LEADING = 0 , QSPI_CLOCK_PHASE_CAPTURE_TRAILING = 1 } |
| QSCK edge on which data is captured (QSPI_SCR.CPHA). More... | |
| enum | QSPI_LANE_WIDTH { QSPI_LANE_WIDTH_SINGLE_BIT_SPI = (int32_t)QSPI_IFR_WIDTH_SINGLE_BIT_SPI_Val , QSPI_LANE_WIDTH_DUAL_OUTPUT = (int32_t)QSPI_IFR_WIDTH_DUAL_OUTPUT_Val , QSPI_LANE_WIDTH_QUAD_OUTPUT = (int32_t)QSPI_IFR_WIDTH_QUAD_OUTPUT_Val , QSPI_LANE_WIDTH_DUAL_IO = (int32_t)QSPI_IFR_WIDTH_DUAL_IO_Val , QSPI_LANE_WIDTH_QUAD_IO = (int32_t)QSPI_IFR_WIDTH_QUAD_IO_Val , QSPI_LANE_WIDTH_DUAL_CMD = (int32_t)QSPI_IFR_WIDTH_DUAL_CMD_Val , QSPI_LANE_WIDTH_QUAD_CMD = (int32_t)QSPI_IFR_WIDTH_QUAD_CMD_Val } |
| Number of data lanes used by each phase of an instruction frame (QSPI_IFR.WIDTH). More... | |
| enum | QSPI_ADDRESS_LENGTH { QSPI_ADDRESS_LENGTH_24BIT = (int32_t)QSPI_IFR_ADDRL_24_BIT_Val , QSPI_ADDRESS_LENGTH_32BIT = (int32_t)QSPI_IFR_ADDRL_32_BIT_Val } |
| Length of the address phase of an instruction frame (QSPI_IFR.ADDRL). More... | |
| enum | QSPI_OPTION_LENGTH { QSPI_OPTION_LENGTH_1BIT = (int32_t)QSPI_IFR_OPTL_OPTION_1BIT_Val , QSPI_OPTION_LENGTH_2BIT = (int32_t)QSPI_IFR_OPTL_OPTION_2BIT_Val , QSPI_OPTION_LENGTH_4BIT = (int32_t)QSPI_IFR_OPTL_OPTION_4BIT_Val , QSPI_OPTION_LENGTH_8BIT = (int32_t)QSPI_IFR_OPTL_OPTION_8BIT_Val } |
| Length of the option phase of an instruction frame (QSPI_IFR.OPTL). More... | |
| enum | QSPI_TRANSFER_TYPE { QSPI_TRANSFER_TYPE_READ = (int32_t)QSPI_IFR_TFRTYP_TRSFR_READ_Val , QSPI_TRANSFER_TYPE_READ_MEMORY = (int32_t)QSPI_IFR_TFRTYP_TRSFR_READ_MEMORY_Val , QSPI_TRANSFER_TYPE_WRITE = (int32_t)QSPI_IFR_TFRTYP_TRSFR_WRITE_Val , QSPI_TRANSFER_TYPE_WRITE_MEMORY = (int32_t)QSPI_IFR_TFRTYP_TRSFR_WRITE_MEMORY_Val } |
| Kind of data transfer performed by an instruction frame (QSPI_IFR.TFRTYP). More... | |
Functions | |
| void | QSPI_Enable (void) |
| Enables the QSPI (QSPI_CR.QSPIEN). | |
| void | QSPI_Disable (void) |
| Disables the QSPI (QSPI_CR.QSPIDIS). | |
| bool | QSPI_IsEnabled (void) |
| Checks whether the QSPI is enabled (QSPI_SR.QSPIENS). | |
| void | QSPI_ResetSoftware (void) |
| Performs a software reset of the QSPI (QSPI_CR.SWRST). | |
| void | QSPI_EndTransfer (void) |
| Marks the current transfer as the last one (QSPI_CR.LASTXFER). | |
| void | QSPI_SetOperatingMode (QSPI_OPERATING_MODE mode) |
| Selects SPI mode or Serial Memory mode (QSPI_MR.SMM). | |
| void | QSPI_SetChipSelectMode (QSPI_CHIP_SELECT_MODE mode) |
| Sets the chip select mode (QSPI_MR.CSMODE). | |
| void | QSPI_SetTransferSize (QSPI_TRANSFER_SIZE size) |
| Sets the number of bits per transfer in SPI mode (QSPI_MR.NBBITS). | |
| void | QSPI_SetLoopback (bool is_enabled) |
| Enables or disables the local loopback path (QSPI_MR.LLB). | |
| void | QSPI_SetDelayBetweenConsecutiveTransfers (uint8_t delay) |
| Sets the delay between consecutive transfers (QSPI_MR.DLYBCT). | |
| void | QSPI_SetDelayBetweenChipSelects (uint8_t delay) |
| Sets the minimum inactive chip select delay (QSPI_MR.DLYCS). | |
| void | QSPI_Send (uint16_t data) |
| Writes one character to the transmit holding register (QSPI_TDR.TD). | |
| uint16_t | QSPI_Receive (void) |
| Reads one character from the receive holding register (QSPI_RDR.RD). | |
| bool | QSPI_TxIsReady (void) |
| Checks whether QSPI_TDR can accept a character (QSPI_SR.TDRE). | |
| bool | QSPI_RxIsReady (void) |
| Checks whether QSPI_RDR holds an unread character (QSPI_SR.RDRF). | |
| bool | QSPI_TransferIsComplete (void) |
| Checks whether all requested transfers have completed (QSPI_SR.TXEMPTY). | |
| void | QSPI_SetClockPolarity (QSPI_CLOCK_POLARITY polarity) |
| Sets the inactive state of QSCK (QSPI_SCR.CPOL). | |
| void | QSPI_SetClockPhase (QSPI_CLOCK_PHASE phase) |
| Sets the QSCK edge on which data is captured (QSPI_SCR.CPHA). | |
| void | QSPI_SetDelayBeforeSck (uint8_t delay) |
| Sets the delay before the first QSCK edge (QSPI_SCR.DLYBS). | |
| QSPI_HWREG_STATUS | QSPI_SetBusSpeed (uint32_t bus_speed, uint32_t clk_frequency) |
| Sets the serial clock baud rate (QSPI_SCR.SCBR). | |
| uint32_t | QSPI_GetBusSpeed (uint32_t clk_frequency) |
| Gets the serial clock baud rate currently configured. | |
| void | QSPI_SetInstructionAddress (uint32_t address) |
| Sets the address sent by an instruction frame (QSPI_IAR.ADDR). | |
| void | QSPI_SetInstructionCode (uint8_t instruction, uint8_t option) |
| Sets the instruction and option codes (QSPI_ICR). | |
| QSPI_HWREG_STATUS | QSPI_SetInstructionFrame (const QSPI_INSTRUCTION_FRAME *frame) |
| Configures and launches an instruction frame (QSPI_IFR). | |
| uint32_t | QSPI_SyncInstructionFrame (void) |
| Synchronizes APB and AHB accesses after launching a data frame. | |
| volatile uint8_t * | QSPI_GetMemoryPointer (uint32_t offset) |
| Gets a pointer into the memory-mapped QSPI window. | |
| bool | QSPI_SetDummyCycles (uint8_t dummy_cycles) |
| Sets the number of dummy cycles of an instruction frame (QSPI_IFR.NBDUM). | |
| void | QSPI_SetContinuousRead (bool is_enabled) |
| Enables or disables continuous read mode (QSPI_IFR.CRM). | |
| void | QSPI_SetScrambling (bool is_enabled) |
| Enables or disables the scrambling function (QSPI_SMR.SCREN). | |
| void | QSPI_SetScramblingRandomValueDisable (bool is_disabled) |
| Enables or disables the scrambling random value (QSPI_SMR.RVDIS). | |
| void | QSPI_SetScramblingKey (uint32_t key) |
| Sets the user scrambling key (QSPI_SKR.USRK). | |
| void | QSPI_EnableInterrupt (QSPI_INTERRUPT_SOURCE source) |
| Enables the specified QSPI interrupt sources (QSPI_IER). | |
| void | QSPI_DisableInterrupt (QSPI_INTERRUPT_SOURCE source) |
| Disables the specified QSPI interrupt sources (QSPI_IDR). | |
| QSPI_INTERRUPT_SOURCE | QSPI_GetInterruptMask (void) |
| Gets the set of enabled interrupt sources (QSPI_IMR). | |
| QSPI_STATUS_FLAG | QSPI_GetStatus (void) |
| Reads the status register, preserving the read-to-clear flags. | |
| bool | QSPI_StatusFlagIsSet (QSPI_STATUS_FLAG flag) |
| Checks whether the specified status flags are set. | |
| void | QSPI_ClearStatus (QSPI_STATUS_FLAG flag) |
| Discards latched read-to-clear status flags. | |
| QSPI_ERROR | QSPI_GetError (void) |
| Gets the current QSPI error state. | |
| void | QSPI_SetCallbackHandler (QSPI_CALLBACK callback) |
| Registers a callback for QSPI interrupts. | |
| void | QSPI_EnableWriteProtection (void) |
| Enables write protection of the QSPI configuration registers. | |
| void | QSPI_DisableWriteProtection (void) |
| Disables write protection of the QSPI configuration registers. | |
| bool | QSPI_WriteProtectionIsEnabled (void) |
| Checks whether write protection is enabled (QSPI_WPMR.WPEN). | |
| bool | QSPI_WriteProtectedIsViolated (void) |
| Checks whether a write protection violation has occurred (QSPI_WPSR.WPVS). | |
| uint8_t | QSPI_GetViolationSourceRegOffset (void) |
| Gets the register offset that caused the write protection violation (QSPI_WPSR.WPVSRC). | |
Driver API for QSPI (plib_qspi.h)
The following example demonstrates typical usage of the QSPI peripheral:
| #define QSPI_BAUD_MAX (QSPI_SCR_SCBR_Msk >> QSPI_SCR_SCBR_Pos) |
Maximum value of the serial clock baud rate divider (QSPI_SCR.SCBR).
| #define QSPI_DELAY_MAX (QSPI_MR_DLYBCT_Msk >> QSPI_MR_DLYBCT_Pos) |
Maximum value of any of the QSPI delay fields (DLYBS, DLYBCT, DLYCS).
| #define QSPI_DUMMY_CYCLES_MAX (QSPI_IFR_NBDUM_Msk >> QSPI_IFR_NBDUM_Pos) |
Maximum number of dummy cycles (QSPI_IFR.NBDUM).
| #define QSPI_ERROR_NONE (0x00U) |
No error
| #define QSPI_ERROR_OVERRUN (0x01U) |
QSPI_RDR was not read before new data came
| #define QSPI_INTERRUPT_ALL (QSPI_IER_Msk) |
All seven sources
| #define QSPI_INTERRUPT_CSR (QSPI_IER_CSR_Msk) |
Chip select rise
| #define QSPI_INTERRUPT_CSS (QSPI_IER_CSS_Msk) |
Chip select status change
| #define QSPI_INTERRUPT_INSTRE (QSPI_IER_INSTRE_Msk) |
Instruction end
| #define QSPI_INTERRUPT_NONE (0x00000000U) |
No source
| #define QSPI_INTERRUPT_OVRES (QSPI_IER_OVRES_Msk) |
Overrun error
| #define QSPI_INTERRUPT_RDRF (QSPI_IER_RDRF_Msk) |
Receive data register full
| #define QSPI_INTERRUPT_TDRE (QSPI_IER_TDRE_Msk) |
Transmit data register empty
| #define QSPI_INTERRUPT_TXEMPTY (QSPI_IER_TXEMPTY_Msk) |
Transmission registers empty
| #define QSPI_MEMORY_BASE_ADDRESS (QSPIMEM_ADDR) |
Base address of the memory-mapped QSPI window (QSPIMEM).
| #define QSPI_MEMORY_SIZE (QSPIMEM_SIZE) |
Size of the memory-mapped QSPI window in bytes.
| #define QSPI_STATUS_FLAG_ALL (QSPI_SR_Msk) |
All eight flags
| #define QSPI_STATUS_FLAG_CSR (QSPI_SR_CSR_Msk) |
CS rise; cleared on read
| #define QSPI_STATUS_FLAG_CSS (QSPI_SR_CSS_Msk) |
Live CS state; 0 = asserted
| #define QSPI_STATUS_FLAG_INSTRE (QSPI_SR_INSTRE_Msk) |
Instr. end; cleared on read
| #define QSPI_STATUS_FLAG_NONE (0x00000000U) |
No flag set
| #define QSPI_STATUS_FLAG_OVRES (QSPI_SR_OVRES_Msk) |
Overrun; cleared on read
| #define QSPI_STATUS_FLAG_QSPIENS (QSPI_SR_QSPIENS_Msk) |
Live enable state
| #define QSPI_STATUS_FLAG_RDRF (QSPI_SR_RDRF_Msk) |
Cleared by reading QSPI_RDR
| #define QSPI_STATUS_FLAG_READ_TO_CLEAR (QSPI_SR_OVRES_Msk | QSPI_SR_CSR_Msk | QSPI_SR_INSTRE_Msk) |
The subset of QSPI_SR flags that are cleared by reading the register.
A single read of QSPI_SR clears all three at once, so any code that polls one of them would destroy the other two. QSPI_GetStatus() latches these bits so that no event is lost; use QSPI_ClearStatus() to discard a latched bit.
| #define QSPI_STATUS_FLAG_TDRE (QSPI_SR_TDRE_Msk) |
Cleared by writing QSPI_TDR
| #define QSPI_STATUS_FLAG_TXEMPTY (QSPI_SR_TXEMPTY_Msk) |
Cleared by writing QSPI_TDR
| #define QSPI_WPMR_UNLOCK_KEY (QSPI_WPMR_WPKEY_PASSWD_Val) |
Password that must accompany a write to QSPI_WPMR.WPEN.
| typedef void(* QSPI_CALLBACK) (QSPI_STATUS_FLAG status) |
QSPI callback function type.
Invoked from QSPI_Handler, that is from interrupt context.
Delivery consumes the event: the read-to-clear flags reported here are dropped from the internal latch, so each interrupt reports only what is new. A polling caller must therefore not expect to see an event that the ISR has already delivered to a callback.
| status | Flags that caused this interrupt: the asserted QSPI_SR flags masked by the sources enabled in QSPI_IMR. Always non-zero. |
| typedef uint32_t QSPI_ERROR |
QSPI error status bitmask type.
Defined as uint32_t so values can be OR'd together using bitwise operators without violating MISRA Rule 10.1 (enum essential type restriction).
Overrun is the only error the QSPI reports. A write protection violation is reported separately through QSPI_WriteProtectedIsViolated().
| typedef uint32_t QSPI_INTERRUPT_SOURCE |
QSPI interrupt source bitmask type.
Defined as uint32_t so values can be OR'd together using bitwise operators without violating MISRA Rule 10.1 (enum essential type restriction).
QSPI_SR.QSPIENS is deliberately absent: it is a status-only bit and has no counterpart in QSPI_IER, QSPI_IDR or QSPI_IMR.
| typedef uint32_t QSPI_STATUS_FLAG |
QSPI status flag bitmask type (QSPI_SR).
Defined as uint32_t so values can be OR'd together using bitwise operators without violating MISRA Rule 10.1 (enum essential type restriction).
| enum QSPI_ADDRESS_LENGTH |
Chip select behaviour at the end of a transfer (QSPI_MR.CSMODE).
| enum QSPI_CLOCK_PHASE |
| enum QSPI_CLOCK_POLARITY |
| enum QSPI_HWREG_STATUS |
Result of a QSPI hardware register operation.
Shared shape with the sibling serial PLIBs. The QSPI implementation only ever returns QSPI_HWREG_OK or QSPI_HWREG_INVALID_PARAM - it has no blocking path, so QSPI_HWREG_TIMEOUT and QSPI_HWREG_BUSY cannot occur.
| enum QSPI_LANE_WIDTH |
Number of data lanes used by each phase of an instruction frame (QSPI_IFR.WIDTH).
Read as instruction / address-option / data.
| enum QSPI_OPERATING_MODE |
QSPI operating mode (QSPI_MR.SMM).
Writing QSPI_OPERATING_MODE_MEMORY forces QSPI_MR.CSMODE to QSPI_CHIP_SELECT_MODE_LASTXFER, and QSPI_MR.DLYBCT must then be zero.
| Enumerator | |
|---|---|
| QSPI_OPERATING_MODE_SPI | SPI mode |
| QSPI_OPERATING_MODE_MEMORY | Serial Memory mode |
| enum QSPI_OPTION_LENGTH |
Length of the option phase of an instruction frame (QSPI_IFR.OPTL).
The option code cannot be shorter than the number of lanes carrying it, so the legal values depend on QSPI_LANE_WIDTH. See QSPI_SetInstructionFrame().
| Enumerator | |
|---|---|
| QSPI_OPTION_LENGTH_1BIT | 1 bit long |
| QSPI_OPTION_LENGTH_2BIT | 2 bits long |
| QSPI_OPTION_LENGTH_4BIT | 4 bits long |
| QSPI_OPTION_LENGTH_8BIT | 8 bits long |
| enum QSPI_TRANSFER_SIZE |
Number of bits per transfer in SPI mode (QSPI_MR.NBBITS).
The field is 4 bits wide and encodes 8 through 16 bits per character. Only the two endpoints carry symbolic names in the device header; the intermediate values are equally valid.
| enum QSPI_TRANSFER_TYPE |
Kind of data transfer performed by an instruction frame (QSPI_IFR.TFRTYP).
The _MEMORY variants address actual memory contents: scrambling is applied when enabled, and a read at a random location (a fetch) is possible. The other two address the memory's own registers: scrambling is never applied and random-location reads are not possible.
| void QSPI_ClearStatus | ( | QSPI_STATUS_FLAG | flag | ) |
Discards latched read-to-clear status flags.
Clears the named flags from the internal latch so a later QSPI_GetStatus() no longer reports them. Flags outside QSPI_STATUS_FLAG_READ_TO_CLEAR are ignored: the hardware owns them and they cannot be cleared this way.
| flag | One or more QSPI_STATUS_FLAG values, OR'd together. |
| void QSPI_Disable | ( | void | ) |
Disables the QSPI (QSPI_CR.QSPIDIS).
| void QSPI_DisableInterrupt | ( | QSPI_INTERRUPT_SOURCE | source | ) |
Disables the specified QSPI interrupt sources (QSPI_IDR).
QSPI_IDR is write-only and clear-only, so sources not named in source are left untouched.
| source | One or more QSPI_INTERRUPT_SOURCE values, OR'd together. |
| void QSPI_DisableWriteProtection | ( | void | ) |
Disables write protection of the QSPI configuration registers.
Clears QSPI_WPMR.WPEN with the required key.
| void QSPI_Enable | ( | void | ) |
Enables the QSPI (QSPI_CR.QSPIEN).
Enabling sets QSPI_SR.TDRE, which reads as zero while the peripheral is disabled.
| void QSPI_EnableInterrupt | ( | QSPI_INTERRUPT_SOURCE | source | ) |
Enables the specified QSPI interrupt sources (QSPI_IER).
QSPI_IER is write-only and set-only, so sources not named in source are left untouched. Enabling a source here does not enable the QSPI interrupt in the NVIC.
| source | One or more QSPI_INTERRUPT_SOURCE values, OR'd together. |
| void QSPI_EnableWriteProtection | ( | void | ) |
Enables write protection of the QSPI configuration registers.
Sets QSPI_WPMR.WPEN with the required key. While enabled, writes to QSPI_MR, QSPI_SCR, QSPI_SMR and QSPI_SKR are discarded and recorded in QSPI_WPSR. QSPI_IFR, QSPI_IAR and QSPI_ICR are not protected, so instruction frames still work normally.
| void QSPI_EndTransfer | ( | void | ) |
Marks the current transfer as the last one (QSPI_CR.LASTXFER).
With QSPI_CHIP_SELECT_MODE_LASTXFER the chip select is deasserted once the character in QSPI_TDR has been sent. In Serial Memory mode this is the step that closes an instruction frame, and must be issued after all data has been moved through the memory window.
| uint32_t QSPI_GetBusSpeed | ( | uint32_t | clk_frequency | ) |
Gets the serial clock baud rate currently configured.
Returns clk_frequency / (SCBR + 1) using the value held in QSPI_SCR.SCBR.
| clk_frequency | Peripheral clock frequency in Hz. |
clk_frequency is zero. | QSPI_ERROR QSPI_GetError | ( | void | ) |
Gets the current QSPI error state.
Overrun is the only error the peripheral reports. The overrun indication is consumed by this call, mirroring the read-to-clear behaviour of QSPI_SR.OVRES in hardware, so a second call reports QSPI_ERROR_NONE unless a new overrun has occurred.
| QSPI_INTERRUPT_SOURCE QSPI_GetInterruptMask | ( | void | ) |
Gets the set of enabled interrupt sources (QSPI_IMR).
| volatile uint8_t * QSPI_GetMemoryPointer | ( | uint32_t | offset | ) |
Gets a pointer into the memory-mapped QSPI window.
In Serial Memory mode all data moves through this window rather than through QSPI_TDR and QSPI_RDR. The returned pointer is volatile because each access drives a transfer on the serial bus.
| offset | Byte offset from QSPI_MEMORY_BASE_ADDRESS. |
offset is at or beyond QSPI_MEMORY_SIZE. | QSPI_STATUS_FLAG QSPI_GetStatus | ( | void | ) |
Reads the status register, preserving the read-to-clear flags.
Performs exactly one read of QSPI_SR. That read clears OVRES, CSR and INSTRE in hardware, all three at once, so this function latches them internally before returning; a caller polling one flag therefore cannot destroy another. The remaining flags reflect the state at the moment of the read.
QSPI_Handler. Because of that, calling this to perform the dummy QSPI_SR read that the datasheet places before QSPI_CR.LASTXFER is not on its own enough to make the following wait meaningful: follow it with QSPI_ClearStatus(QSPI_STATUS_FLAG_INSTRE | QSPI_STATUS_FLAG_CSR) so an instruction end left over from an earlier frame cannot satisfy the wait immediately. | uint8_t QSPI_GetViolationSourceRegOffset | ( | void | ) |
Gets the register offset that caused the write protection violation (QSPI_WPSR.WPVSRC).
| bool QSPI_IsEnabled | ( | void | ) |
Checks whether the QSPI is enabled (QSPI_SR.QSPIENS).
true if enabled, false if disabled. | uint16_t QSPI_Receive | ( | void | ) |
Reads one character from the receive holding register (QSPI_RDR.RD).
Reading QSPI_RDR clears QSPI_SR.RDRF. Check QSPI_RxIsReady() first; reading an empty QSPI_RDR returns the previous contents.
| void QSPI_ResetSoftware | ( | void | ) |
Performs a software reset of the QSPI (QSPI_CR.SWRST).
Equivalent to a power-on reset of the peripheral. Any transfer in progress is abandoned and the chip select is deasserted. Because the reset returns QSPI_SR to zero, the latched read-to-clear flags are discarded too - otherwise a stale INSTRE would make the next QSPI_StatusFlagIsSet() report an instruction end that belonged to the abandoned transfer.
| bool QSPI_RxIsReady | ( | void | ) |
Checks whether QSPI_RDR holds an unread character (QSPI_SR.RDRF).
true if a character is waiting, false otherwise. | void QSPI_Send | ( | uint16_t | data | ) |
Writes one character to the transmit holding register (QSPI_TDR.TD).
Writing QSPI_TDR clears QSPI_SR.TDRE and QSPI_SR.TXEMPTY. Check QSPI_TxIsReady() before calling, otherwise the previous character is lost.
| data | Character to transmit. Bits above the configured transfer size are ignored by the hardware. |
| QSPI_HWREG_STATUS QSPI_SetBusSpeed | ( | uint32_t | bus_speed, |
| uint32_t | clk_frequency ) |
Sets the serial clock baud rate (QSPI_SCR.SCBR).
Computes SCBR = (clk_frequency / bus_speed) - 1. Because the divider is an integer, the achieved rate is the nearest value at or above bus_speed that the divider can express; read it back with QSPI_GetBusSpeed().
| bus_speed | Desired QSCK frequency in Hz. Must be non-zero and no greater than clk_frequency. |
| clk_frequency | Peripheral clock frequency in Hz. |
bus_speed exceeds clk_frequency, or if the required divider exceeds QSPI_BAUD_MAX. A non-QSPI_HWREG_OK return means the requested rate is not reachable from the peripheral clock.
| void QSPI_SetCallbackHandler | ( | QSPI_CALLBACK | callback | ) |
Registers a callback for QSPI interrupts.
The callback is invoked from QSPI_Handler, that is from interrupt context, with the status flags that were asserted. Keep it short and do not block in it. Only sources enabled through QSPI_EnableInterrupt() can cause it to run.
| callback | Pointer to the callback function. Pass NULL to unregister. |
| void QSPI_SetChipSelectMode | ( | QSPI_CHIP_SELECT_MODE | mode | ) |
Sets the chip select mode (QSPI_MR.CSMODE).
| mode | Chip select behaviour at the end of a transfer. |
| void QSPI_SetClockPhase | ( | QSPI_CLOCK_PHASE | phase | ) |
Sets the QSCK edge on which data is captured (QSPI_SCR.CPHA).
| phase | Clock phase to apply. |
| void QSPI_SetClockPolarity | ( | QSPI_CLOCK_POLARITY | polarity | ) |
Sets the inactive state of QSCK (QSPI_SCR.CPOL).
| polarity | Clock polarity to apply. |
| void QSPI_SetContinuousRead | ( | bool | is_enabled | ) |
Enables or disables continuous read mode (QSPI_IFR.CRM).
| is_enabled | true to enable continuous read mode, false to disable. |
| void QSPI_SetDelayBeforeSck | ( | uint8_t | delay | ) |
Sets the delay before the first QSCK edge (QSPI_SCR.DLYBS).
The delay between chip select assertion and the first clock edge, in peripheral clock periods, equals delay. A value of zero gives half a QSCK period.
| delay | Field value, 0 to QSPI_DELAY_MAX. |
| void QSPI_SetDelayBetweenChipSelects | ( | uint8_t | delay | ) |
Sets the minimum inactive chip select delay (QSPI_MR.DLYCS).
The delay in peripheral clock periods equals delay. A value of zero gives one peripheral clock period.
| delay | Field value, 0 to QSPI_DELAY_MAX. |
| void QSPI_SetDelayBetweenConsecutiveTransfers | ( | uint8_t | delay | ) |
Sets the delay between consecutive transfers (QSPI_MR.DLYBCT).
The delay in peripheral clock periods is delay * 32. A value of zero means no delay is inserted.
| delay | Field value, 0 to QSPI_DELAY_MAX. |
| bool QSPI_SetDummyCycles | ( | uint8_t | dummy_cycles | ) |
Sets the number of dummy cycles of an instruction frame (QSPI_IFR.NBDUM).
Provided for adjusting the dummy cycle count without rewriting the whole frame; QSPI_SetInstructionFrame() sets the field too.
| dummy_cycles | Number of dummy cycles, 0 to QSPI_DUMMY_CYCLES_MAX. |
true if applied, false if dummy_cycles is out of range, in which case no register is written. | void QSPI_SetInstructionAddress | ( | uint32_t | address | ) |
Sets the address sent by an instruction frame (QSPI_IAR.ADDR).
Call this before QSPI_SetInstructionFrame() whenever the frame has is_address_enabled set.
| address | Address to send to the serial memory. |
| void QSPI_SetInstructionCode | ( | uint8_t | instruction, |
| uint8_t | option ) |
Sets the instruction and option codes (QSPI_ICR).
Call this before QSPI_SetInstructionFrame() whenever the frame has is_instruction_enabled or is_option_enabled set. Both fields are written together in a single register access.
| instruction | Instruction code (QSPI_ICR.INST). |
| option | Option code (QSPI_ICR.OPT). Pass zero when the frame has no option phase. |
| QSPI_HWREG_STATUS QSPI_SetInstructionFrame | ( | const QSPI_INSTRUCTION_FRAME * | frame | ) |
Configures and launches an instruction frame (QSPI_IFR).
Composes frame into a single write to QSPI_IFR. If the frame has no data phase the write itself starts the transfer; if it has one, the transfer starts on the first access to the memory window, and QSPI_SyncInstructionFrame() must be called first.
All parameters are validated before any register is touched, so a rejected frame leaves the hardware untouched.
| frame | Frame description. Must not be NULL. |
frame is NULL, ordummy_cycles exceeds QSPI_DUMMY_CYCLES_MAX, oroption_length is shorter than the number of lanes width uses for it - a 1-bit option code cannot be sent over 4 lanes, or| void QSPI_SetLoopback | ( | bool | is_enabled | ) |
Enables or disables the local loopback path (QSPI_MR.LLB).
With loopback enabled, QIO0 is internally connected to QIO1 so transmitted data is received back without leaving the device. Intended for self-test.
| is_enabled | true to enable loopback, false to disable it. |
| void QSPI_SetOperatingMode | ( | QSPI_OPERATING_MODE | mode | ) |
Selects SPI mode or Serial Memory mode (QSPI_MR.SMM).
| mode | Operating mode to apply. |
| void QSPI_SetScrambling | ( | bool | is_enabled | ) |
Enables or disables the scrambling function (QSPI_SMR.SCREN).
Scrambling is applied only to frames using QSPI_TRANSFER_TYPE_READ_MEMORY or QSPI_TRANSFER_TYPE_WRITE_MEMORY.
| is_enabled | true to enable scrambling and unscrambling. |
| void QSPI_SetScramblingKey | ( | uint32_t | key | ) |
Sets the user scrambling key (QSPI_SKR.USRK).
| key | Scrambling key. |
| void QSPI_SetScramblingRandomValueDisable | ( | bool | is_disabled | ) |
Enables or disables the scrambling random value (QSPI_SMR.RVDIS).
| is_disabled | true to disable the random value, false to allow it. |
| void QSPI_SetTransferSize | ( | QSPI_TRANSFER_SIZE | size | ) |
Sets the number of bits per transfer in SPI mode (QSPI_MR.NBBITS).
| size | Character length, 8 to 16 bits. |
| bool QSPI_StatusFlagIsSet | ( | QSPI_STATUS_FLAG | flag | ) |
Checks whether the specified status flags are set.
Reads the status through QSPI_GetStatus(), so read-to-clear flags are latched rather than consumed and this function is safe to call in a polling loop.
| flag | One or more QSPI_STATUS_FLAG values, OR'd together. |
true if any of the flags in flag is set.| uint32_t QSPI_SyncInstructionFrame | ( | void | ) |
Synchronizes APB and AHB accesses after launching a data frame.
Performs the read of QSPI_IFR that the hardware requires between the write that configures a frame with a data phase and the first access to the memory window. Skipping it leaves the two buses unsynchronized and the first data access unreliable.
The register value is returned rather than discarded so the read cannot be optimized away, which also makes this the QSPI_IFR getter.
| bool QSPI_TransferIsComplete | ( | void | ) |
Checks whether all requested transfers have completed (QSPI_SR.TXEMPTY).
true if the transmit shift register and QSPI_TDR are both empty. | bool QSPI_TxIsReady | ( | void | ) |
Checks whether QSPI_TDR can accept a character (QSPI_SR.TDRE).
true if QSPI_TDR is empty, false if a character is still pending. | bool QSPI_WriteProtectedIsViolated | ( | void | ) |
Checks whether a write protection violation has occurred (QSPI_WPSR.WPVS).
true if a protected register was written while protection was on. | bool QSPI_WriteProtectionIsEnabled | ( | void | ) |
Checks whether write protection is enabled (QSPI_WPMR.WPEN).
true if write protection is enabled. | QSPI_ADDRESS_LENGTH QSPI_INSTRUCTION_FRAME::address_length |
Length of the address phase
| uint8_t QSPI_INSTRUCTION_FRAME::dummy_cycles |
Dummy cycles between address and data, 0 to QSPI_DUMMY_CYCLES_MAX
| uint8_t QSPI_INSTRUCTION_FRAME::instruction |
Instruction code sent when is_instruction_enabled is true (QSPI_ICR.INST)
| bool QSPI_INSTRUCTION_FRAME::is_address_enabled |
Send the address held in QSPI_IAR
| bool QSPI_INSTRUCTION_FRAME::is_continuous_read_enabled |
Enable continuous read mode; requires QSPI_TRANSFER_TYPE_READ_MEMORY
| bool QSPI_INSTRUCTION_FRAME::is_data_enabled |
The frame has a data phase, moved through the memory-mapped window
| bool QSPI_INSTRUCTION_FRAME::is_instruction_enabled |
Send the instruction code
| bool QSPI_INSTRUCTION_FRAME::is_option_enabled |
Send the option code
| uint8_t QSPI_INSTRUCTION_FRAME::option |
Option code sent when is_option_enabled is true (QSPI_ICR.OPT)
| QSPI_OPTION_LENGTH QSPI_INSTRUCTION_FRAME::option_length |
Length of the option phase; must be consistent with width
| QSPI_TRANSFER_TYPE QSPI_INSTRUCTION_FRAME::transfer_type |
Whether the frame reads or writes, and whether it targets memory data
| QSPI_LANE_WIDTH QSPI_INSTRUCTION_FRAME::width |
Number of lanes used by each phase of the frame