drv_spiflash.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. * File : gpio.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2015, RT-Thread Development Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2017-11-08 ZYH the first version
  13. */
  14. #include <rtthread.h>
  15. #if defined(RT_USING_W25QXX) || defined(RT_USING_SFUD)
  16. #include <drv_spi.h>
  17. #ifdef RT_USING_W25QXX
  18. #include "spi_flash_w25qxx.h"
  19. #elif defined(RT_USING_SFUD)
  20. #include "string.h"
  21. #include "spi_flash.h"
  22. #include "spi_flash_sfud.h"
  23. sfud_flash sfud_norflash0;
  24. rt_spi_flash_device_t spi_device;
  25. #endif
  26. int rt_nor_flash_init(void)
  27. {
  28. stm32_spi_bus_attach_device(RT_FLASH_CS_PIN, RT_FLASH_SPI_BUS_NAME, "norspi");
  29. #ifdef RT_USING_W25QXX
  30. return w25qxx_init("flash0", "norspi");
  31. #elif defined(RT_USING_SFUD)
  32. spi_device = rt_sfud_flash_probe("flash0", "norspi");
  33. if (spi_device == RT_NULL)
  34. {
  35. return -RT_ERROR;
  36. }
  37. memcpy(&sfud_norflash0, spi_device->user_data, sizeof(sfud_flash));
  38. return 0;
  39. #endif
  40. }
  41. INIT_DEVICE_EXPORT(rt_nor_flash_init);
  42. #endif