drv_spi_flash.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. * 2018-04-02 Liuguang the first version.
  9. */
  10. #include "drv_spi_flash.h"
  11. #include "spi_flash.h"
  12. #include "spi_flash_sfud.h"
  13. #ifndef SPI_FLASH_USING_SPIBUS_NAME
  14. #define SPI_FLASH_USING_SPIBUS_NAME "spi4"
  15. #endif
  16. #ifndef SPI_FLASH_NAME
  17. #define SPI_FLASH_NAME "flash0"
  18. #endif
  19. #ifndef SPI_FLASH_USING_CS_PIN
  20. #define SPI_FLASH_USING_CS_PIN (79)
  21. #endif
  22. int rt_hw_spi_flash_init(void)
  23. {
  24. rt_err_t ret;
  25. extern rt_err_t rt1050_spi_bus_attach_device(const char *bus_name,
  26. const char *device_name, rt_uint32_t pin);
  27. ret = rt1050_spi_bus_attach_device(SPI_FLASH_USING_SPIBUS_NAME,
  28. SPI_FLASH_USING_SPIBUS_NAME "0", SPI_FLASH_USING_CS_PIN);
  29. if(ret != RT_EOK)
  30. {
  31. return ret;
  32. }
  33. if(rt_sfud_flash_probe(SPI_FLASH_NAME, SPI_FLASH_USING_SPIBUS_NAME "0") == RT_NULL)
  34. {
  35. return RT_ERROR;
  36. }
  37. return RT_EOK;
  38. }
  39. INIT_DEVICE_EXPORT(rt_hw_spi_flash_init);