drv_spiflash.c 895 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Copyright (c) 2006-2018, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2019-3-30 bluebear233 first version
  9. */
  10. #include <rtdevice.h>
  11. #ifdef RT_USING_SPI
  12. #if defined(RT_USING_W25QXX) || defined(RT_USING_SFUD)
  13. static struct rt_spi_device spi_device;
  14. #ifdef RT_USING_W25QXX
  15. #include "spi_flash_w25qxx.h"
  16. #elif defined(RT_USING_SFUD)
  17. #include "spi_flash.h"
  18. #include "spi_flash_sfud.h"
  19. #endif
  20. static int rt_hw_spi_flash_init(void)
  21. {
  22. rt_spi_bus_attach_device(&spi_device, "qspi01", "qspi0", RT_NULL);
  23. #ifdef RT_USING_W25QXX
  24. return w25qxx_init("flash0", "qspi01");
  25. #elif defined(RT_USING_SFUD)
  26. if (rt_sfud_flash_probe("flash0", "qspi01") == RT_NULL)
  27. {
  28. return -RT_ERROR;
  29. }
  30. #endif
  31. return 0;
  32. }
  33. INIT_COMPONENT_EXPORT(rt_hw_spi_flash_init);
  34. #endif
  35. #endif