drv_spi_flash.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * File : drv_spi_flash.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2017, RT-Thread Development Team
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2018-02-08 RT-Thread the first version
  23. */
  24. #include <rtthread.h>
  25. #include <rthw.h>
  26. #include <rtdevice.h>
  27. #define DBG_ENABLE
  28. #define DBG_SECTION_NAME "[FLASH]"
  29. #define DBG_LEVEL DBG_LOG
  30. #define DBG_COLOR
  31. #include <rtdbg.h>
  32. #define SPI_FLASH_DEVICE_NAME "spi00"
  33. #define SPI_FLASH_CHIP "gd25qxx"
  34. //#define DEBUG
  35. #ifdef DEBUG
  36. #define DEBUG_PRINTF(...) rt_kprintf(__VA_ARGS__)
  37. #else
  38. #define DEBUG_PRINTF(...)
  39. #endif
  40. #ifdef TINA_USING_SPI_FLASH
  41. #include "spi_flash.h"
  42. #if defined(RT_USING_SFUD)
  43. #include "spi_flash_sfud.h"
  44. rt_spi_flash_device_t spi_device;
  45. int rt_hw_spi_flash_with_sfud_init(void)
  46. {
  47. DEBUG_PRINTF("%s -> %d\n", __FUNCTION__, __LINE__);
  48. spi_device = rt_sfud_flash_probe(SPI_FLASH_CHIP, SPI_FLASH_DEVICE_NAME);
  49. if (spi_device == NULL)
  50. {
  51. DEBUG_PRINTF("%s -> %d\n", __FUNCTION__, __LINE__);
  52. return RT_ERROR;
  53. };
  54. DEBUG_PRINTF("%s -> %d\n", __FUNCTION__, __LINE__);
  55. return RT_EOK;
  56. }
  57. INIT_PREV_EXPORT(rt_hw_spi_flash_with_sfud_init);
  58. #elif defined(RT_USING_W25QXX)
  59. #include "spi_flash_w25qxx.h"
  60. int rt_hw_spi_flash_init(void)
  61. {
  62. DEBUG_PRINTF("%s -> %d\n", __FUNCTION__, __LINE__);
  63. return w25qxx_init(SPI_FLASH_CHIP, SPI_FLASH_DEVICE_NAME);
  64. }
  65. INIT_DEVICE_EXPORT(rt_hw_spi_flash_init);
  66. #endif
  67. #endif