drv_spi_flash.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2018-02-08 RT-Thread the first version
  9. */
  10. #include <rtthread.h>
  11. #include <rthw.h>
  12. #include <rtdevice.h>
  13. #define DBG_TAG "FLASH"
  14. #define DBG_LVL DBG_LOG
  15. #include <rtdbg.h>
  16. #define SPI_FLASH_DEVICE_NAME "spi00"
  17. #define SPI_FLASH_CHIP "gd25qxx"
  18. //#define DEBUG
  19. #ifdef DEBUG
  20. #define DEBUG_PRINTF(...) rt_kprintf(__VA_ARGS__)
  21. #else
  22. #define DEBUG_PRINTF(...)
  23. #endif
  24. #if defined(TINA_USING_SPI_FLASH) && defined(RT_USING_SFUD)
  25. #include "spi_flash.h"
  26. #include <spi_flash_sfud.h>
  27. rt_spi_flash_device_t spi_device;
  28. int rt_hw_spi_flash_with_sfud_init(void)
  29. {
  30. DEBUG_PRINTF("%s -> %d\n", __FUNCTION__, __LINE__);
  31. spi_device = rt_sfud_flash_probe(SPI_FLASH_CHIP, SPI_FLASH_DEVICE_NAME);
  32. if (spi_device == NULL)
  33. {
  34. DEBUG_PRINTF("%s -> %d\n", __FUNCTION__, __LINE__);
  35. return -RT_ERROR;
  36. };
  37. DEBUG_PRINTF("%s -> %d\n", __FUNCTION__, __LINE__);
  38. return RT_EOK;
  39. }
  40. INIT_PREV_EXPORT(rt_hw_spi_flash_with_sfud_init);
  41. #endif /* defined(TINA_USING_SPI_FLASH) && defined(RT_USING_SFUD) */