summaryrefslogtreecommitdiff
path: root/bsp/stm32/stm32f407-rt-spark/board/ports/soft_spi_flash_init.c
blob: 6caf5a79af624e358bb4f259b6acbf15d6f7e1c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*
 * Copyright (c) 2006-2022, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2022-6-14      solar        first version
 */

#include <rtthread.h>
#include <rtdevice.h>
#include "dev_spi_flash.h"
#include "dev_spi_flash_sfud.h"
#include <drv_spi.h>

#ifdef BSP_USING_SOFT_SPI_FLASH

static struct rt_spi_device soft_spi_flash_device;

static int rt_soft_spi_flash_init(void)
{
    __HAL_RCC_GPIOB_CLK_ENABLE();
    rt_spi_bus_attach_device_cspin(&soft_spi_flash_device, "swspi20", "swspi2",
                                   rt_pin_get("PB.14"), RT_NULL);

    if (RT_NULL == rt_sfud_flash_probe("W25Q128", "swspi20"))
    {
        return -RT_ERROR;
    }

    return RT_EOK;
}
INIT_COMPONENT_EXPORT(rt_soft_spi_flash_init);
#endif /* BSP_USING_SOFT_SPI_FLASH */