Private function prototypes ---------------------------------------------------*/ Private functions ------------------------------------------------------------*/ / * @brief * Initialize the SPI Flash * * @details * * @note * * @return * Error code *********************************************************************/
| 133 | * Error code |
| 134 | *********************************************************************/ |
| 135 | rt_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 |
no test coverage detected