MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / efm_spiFlash_init

Function efm_spiFlash_init

bsp/efm32/dev_sflash.c:135–176  ·  view source on GitHub ↗

Private function prototypes ---------------------------------------------------*/ Private functions ------------------------------------------------------------*/ / * @brief * Initialize the SPI Flash * * @details * * @note * * @return * Error code *********************************************************************/

Source from the content-addressed store, hash-verified

133 * Error code
134 *********************************************************************/
135rt_err_t efm_spiFlash_init(void)
136{
137 struct efm32_usart_device_t *usart;
138
139 usart = (struct efm32_usart_device_t *)(sFlash->user_data);
140
141#if defined(EFM32_GXXX_DK)
142 /* Enable SPI access to Flash */
143 DVK_writeRegister(BC_SPI_CFG, 0);
144#endif
145
146 do
147 {
148 /* Find SPI device */
149 sFlash = rt_device_find(SFLASH_USING_DEVICE_NAME);
150 if (sFlash == RT_NULL)
151 {
152 sflash_debug("SFLASH: Can't find device %s!\n",
153 SFLASH_USING_DEVICE_NAME);
154 break;
155 }
156 sflash_debug("SFLASH: Find device %s\n", SFLASH_USING_DEVICE_NAME);
157
158 /* Config chip slect pin */
159 if (!(usart->state & USART_STATE_AUTOCS))
160 {
161 GPIO_PinModeSet(SFLASH_CS_PORT, SFLASH_CS_PIN, gpioModePushPull, 1);
162 sFlashAutoCs = false;
163 }
164
165 /* Open SPI device */
166 if (sFlash->open(sFlash, RT_DEVICE_OFLAG_RDWR) != RT_EOK)
167 {
168 break;
169 }
170
171 return RT_EOK;
172 } while(0);
173
174 sflash_debug("SFLASH: Init failed!\n");
175 return -RT_ERROR;
176}
177
178/******************************************************************//**
179 * @brief

Callers 1

rt_application_initFunction · 0.85

Calls 3

DVK_writeRegisterFunction · 0.85
rt_device_findFunction · 0.85
GPIO_PinModeSetFunction · 0.85

Tested by

no test coverage detected