drv_spi_flash.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright (c) 2006-2023, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2018-11-27 zylx first version
  9. */
  10. #include <board.h>
  11. #include <drv_qspi.h>
  12. #include <rtdevice.h>
  13. #include <rthw.h>
  14. #include <finsh.h>
  15. #include <drv_spi.h>
  16. #ifdef BSP_USING_SPI_FLASH
  17. #include "spi_flash.h"
  18. #include "spi_flash_sfud.h"
  19. static int rt_hw_spi_flash_init(void)
  20. {
  21. rt_hw_spi_device_attach("spi1", "spi10", 24); // CS:PB8
  22. if (RT_NULL == rt_sfud_flash_probe("W25Q128", "spi10"))
  23. {
  24. return -RT_ERROR;
  25. };
  26. return RT_EOK;
  27. }
  28. INIT_COMPONENT_EXPORT(rt_hw_spi_flash_init);
  29. #if defined(RT_USING_DFS_ELMFAT) && !defined(BSP_USING_SDCARD)
  30. #include <dfs_fs.h>
  31. #define BLK_DEV_NAME "W25Q128"
  32. int mnt_init(void)
  33. {
  34. rt_thread_delay(RT_TICK_PER_SECOND);
  35. if (dfs_mount(BLK_DEV_NAME, "/", "elm", 0, 0) == 0)
  36. {
  37. rt_kprintf("file system initialization done!\n");
  38. }
  39. else
  40. {
  41. if(dfs_mkfs("elm", BLK_DEV_NAME) == 0)
  42. {
  43. if (dfs_mount(BLK_DEV_NAME, "/", "elm", 0, 0) == 0)
  44. {
  45. rt_kprintf("file system initialization done!\n");
  46. }
  47. else
  48. {
  49. rt_kprintf("file system initialization failed!\n");
  50. }
  51. }
  52. }
  53. return 0;
  54. }
  55. INIT_ENV_EXPORT(mnt_init);
  56. #endif /* defined(RT_USING_DFS_ELMFAT) && !defined(BSP_USING_SDCARD) */
  57. #endif /* BSP_USING_SPI_FLASH */