drv_spi_flash.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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_TAG "FLASH"
  28. #define DBG_LVL DBG_LOG
  29. #include <rtdbg.h>
  30. #define SPI_FLASH_DEVICE_NAME "spi00"
  31. #define SPI_FLASH_CHIP "gd25qxx"
  32. //#define DEBUG
  33. #ifdef DEBUG
  34. #define DEBUG_PRINTF(...) rt_kprintf(__VA_ARGS__)
  35. #else
  36. #define DEBUG_PRINTF(...)
  37. #endif
  38. #ifdef TINA_USING_SPI_FLASH
  39. #include "spi_flash.h"
  40. #if defined(RT_USING_SFUD)
  41. #include "spi_flash_sfud.h"
  42. rt_spi_flash_device_t spi_device;
  43. int rt_hw_spi_flash_with_sfud_init(void)
  44. {
  45. DEBUG_PRINTF("%s -> %d\n", __FUNCTION__, __LINE__);
  46. spi_device = rt_sfud_flash_probe(SPI_FLASH_CHIP, SPI_FLASH_DEVICE_NAME);
  47. if (spi_device == NULL)
  48. {
  49. DEBUG_PRINTF("%s -> %d\n", __FUNCTION__, __LINE__);
  50. return RT_ERROR;
  51. };
  52. DEBUG_PRINTF("%s -> %d\n", __FUNCTION__, __LINE__);
  53. return RT_EOK;
  54. }
  55. INIT_PREV_EXPORT(rt_hw_spi_flash_with_sfud_init);
  56. #endif
  57. #endif