drv_spi_flash.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * File : drv_spi_flash.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006-2013, 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. * 2018-04-02 Liuguang the first version.
  13. */
  14. #include "drv_spi_flash.h"
  15. #include "spi_flash.h"
  16. #include "spi_flash_sfud.h"
  17. #ifndef SPI_FLASH_USING_SPIBUS_NAME
  18. #define SPI_FLASH_USING_SPIBUS_NAME "spi4"
  19. #endif
  20. #ifndef SPI_FLASH_NAME
  21. #define SPI_FLASH_NAME "flash0"
  22. #endif
  23. #ifndef SPI_FLASH_USING_CS_PIN
  24. #define SPI_FLASH_USING_CS_PIN (79)
  25. #endif
  26. int rt_hw_spi_flash_init(void)
  27. {
  28. rt_err_t ret;
  29. extern rt_err_t rt1050_spi_bus_attach_device(const char *bus_name,
  30. const char *device_name, rt_uint32_t pin);
  31. ret = rt1050_spi_bus_attach_device(SPI_FLASH_USING_SPIBUS_NAME,
  32. SPI_FLASH_USING_SPIBUS_NAME "0", SPI_FLASH_USING_CS_PIN);
  33. if(ret != RT_EOK)
  34. {
  35. return ret;
  36. }
  37. if(rt_sfud_flash_probe(SPI_FLASH_NAME, SPI_FLASH_USING_SPIBUS_NAME "0") == RT_NULL)
  38. {
  39. return RT_ERROR;
  40. }
  41. return RT_EOK;
  42. }
  43. INIT_DEVICE_EXPORT(rt_hw_spi_flash_init);