1 /*
2 * Copyright 2022 NXP
3 * All rights reserved.
4 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 */
7
8 #include "fsl_romapi_flexspi.h"
9 #include "fsl_romapi.h"
10
11 #define FLEXSPI_FLASH_API_TREE ((flexspi_nor_flash_driver_t *)(((uint32_t *)ROM_API_TREE_ADDR)[5]))
12
flexspi_nor_flash_version(void)13 uint32_t flexspi_nor_flash_version(void)
14 {
15 assert(FLEXSPI_FLASH_API_TREE);
16 return FLEXSPI_FLASH_API_TREE->version;
17 }
18
19 //!@brief Initialize Serial NOR devices via FlexSPI
flexspi_nor_flash_init(uint32_t instance,flexspi_nor_config_t * config)20 status_t flexspi_nor_flash_init(uint32_t instance, flexspi_nor_config_t *config)
21 {
22 assert(FLEXSPI_FLASH_API_TREE);
23 return FLEXSPI_FLASH_API_TREE->init(instance, config);
24 }
25
26 //!@brief Wait until Serial NOR device is idle
flexspi_nor_flash_wait_busy(uint32_t instance,flexspi_nor_config_t * config,uint32_t address,bool keepState)27 status_t flexspi_nor_flash_wait_busy(uint32_t instance, flexspi_nor_config_t *config, uint32_t address, bool keepState)
28 {
29 assert(FLEXSPI_FLASH_API_TREE);
30 return FLEXSPI_FLASH_API_TREE->wait_busy(instance, config, address, keepState);
31 }
32 //!@brief Program data to Serial NOR via FlexSPI
flexspi_nor_flash_page_program(uint32_t instance,flexspi_nor_config_t * config,uint32_t dstAddr,const uint32_t * src,bool keepState)33 status_t flexspi_nor_flash_page_program(
34 uint32_t instance, flexspi_nor_config_t *config, uint32_t dstAddr, const uint32_t *src, bool keepState)
35 {
36 assert(FLEXSPI_FLASH_API_TREE);
37 return FLEXSPI_FLASH_API_TREE->page_program(instance, config, dstAddr, src, keepState);
38 }
39
40 //!@brief Erase all the Serial NOR devices connected on FlexSPI
flexspi_nor_flash_erase_all(uint32_t instance,flexspi_nor_config_t * config)41 status_t flexspi_nor_flash_erase_all(uint32_t instance, flexspi_nor_config_t *config)
42 {
43 assert(FLEXSPI_FLASH_API_TREE);
44 return FLEXSPI_FLASH_API_TREE->erase_all(instance, config);
45 }
46
47 //!@brief Erase Flash Region specified by address and length
flexspi_nor_flash_erase(uint32_t instance,flexspi_nor_config_t * config,uint32_t start,uint32_t length)48 status_t flexspi_nor_flash_erase(uint32_t instance, flexspi_nor_config_t *config, uint32_t start, uint32_t length)
49 {
50 assert(FLEXSPI_FLASH_API_TREE);
51 return FLEXSPI_FLASH_API_TREE->erase(instance, config, start, length);
52 }
53
54 //!@brief Erase one sector specified by address
flexspi_nor_flash_erase_sector(uint32_t instance,flexspi_nor_config_t * config,uint32_t address)55 status_t flexspi_nor_flash_erase_sector(uint32_t instance, flexspi_nor_config_t *config, uint32_t address)
56 {
57 assert(FLEXSPI_FLASH_API_TREE);
58 return FLEXSPI_FLASH_API_TREE->erase_sector(instance, config, address);
59 }
60
61 //!@brief Erase one block specified by address
flexspi_nor_flash_erase_block(uint32_t instance,flexspi_nor_config_t * config,uint32_t address)62 status_t flexspi_nor_flash_erase_block(uint32_t instance, flexspi_nor_config_t *config, uint32_t address)
63 {
64 assert(FLEXSPI_FLASH_API_TREE);
65 return FLEXSPI_FLASH_API_TREE->erase_block(instance, config, address);
66 }
67
68 //!@brief Read data from Serial NOR
flexspi_nor_flash_read(uint32_t instance,flexspi_nor_config_t * config,uint32_t * dst,uint32_t start,uint32_t bytes)69 status_t flexspi_nor_flash_read(
70 uint32_t instance, flexspi_nor_config_t *config, uint32_t *dst, uint32_t start, uint32_t bytes)
71 {
72 assert(FLEXSPI_FLASH_API_TREE);
73 return FLEXSPI_FLASH_API_TREE->read(instance, config, dst, start, bytes);
74 }
75
76 //!@brief Configure Clock for FlexSPI
flexspi_clock_config(uint32_t instance,uint32_t freq,uint32_t sampleClkMode)77 void flexspi_clock_config(uint32_t instance, uint32_t freq, uint32_t sampleClkMode)
78 {
79 assert(FLEXSPI_FLASH_API_TREE);
80 FLEXSPI_FLASH_API_TREE->config_clock(instance, freq, sampleClkMode);
81 }
82
83 //!@brief Set the clock source for FlexSPI NOR
flexspi_nor_set_clock_source(uint32_t clockSource)84 status_t flexspi_nor_set_clock_source(uint32_t clockSource)
85 {
86 assert(FLEXSPI_FLASH_API_TREE);
87 return FLEXSPI_FLASH_API_TREE->set_clock_source(clockSource);
88 }
89
90 //!@brief Get FlexSPI NOR Configuration Block based on specified option
flexspi_nor_get_config(uint32_t instance,flexspi_nor_config_t * config,serial_nor_config_option_t * option)91 status_t flexspi_nor_get_config(uint32_t instance, flexspi_nor_config_t *config, serial_nor_config_option_t *option)
92 {
93 assert(FLEXSPI_FLASH_API_TREE);
94 return FLEXSPI_FLASH_API_TREE->get_config(instance, config, option);
95 }
96
97 //!@brief Reset FlexSPI NOR Flash
flexspi_nor_hw_reset(uint32_t instance,uint32_t reset_logic)98 void flexspi_nor_hw_reset(uint32_t instance, uint32_t reset_logic)
99 {
100 assert(FLEXSPI_FLASH_API_TREE);
101 FLEXSPI_FLASH_API_TREE->hw_reset(instance, reset_logic);
102 }
103
104 //!@brief Perform FlexSPI command
flexspi_command_xfer(uint32_t instance,flexspi_xfer_t * xfer)105 status_t flexspi_command_xfer(uint32_t instance, flexspi_xfer_t *xfer)
106 {
107 assert(FLEXSPI_FLASH_API_TREE);
108 return FLEXSPI_FLASH_API_TREE->xfer(instance, xfer);
109 }
110
111 //!@brief Configure FlexSPI Lookup table
flexspi_update_lut(uint32_t instance,uint32_t seqIndex,const uint32_t * lutBase,uint32_t numberOfSeq)112 status_t flexspi_update_lut(uint32_t instance, uint32_t seqIndex, const uint32_t *lutBase, uint32_t numberOfSeq)
113 {
114 assert(FLEXSPI_FLASH_API_TREE);
115 return FLEXSPI_FLASH_API_TREE->update_lut(instance, seqIndex, lutBase, numberOfSeq);
116 }
117
118 //!@brief Partially Program data to Serial NOR via FlexSPI
flexspi_nor_flash_partial_program(uint32_t instance,flexspi_nor_config_t * config,uint32_t dstAddr,const uint32_t * src,uint32_t length,bool keepState)119 status_t flexspi_nor_flash_partial_program(uint32_t instance,
120 flexspi_nor_config_t *config,
121 uint32_t dstAddr,
122 const uint32_t *src,
123 uint32_t length,
124 bool keepState)
125 {
126 assert(FLEXSPI_FLASH_API_TREE);
127 return FLEXSPI_FLASH_API_TREE->partial_program(instance, config, dstAddr, src, length, keepState);
128 }
129