gd25qxx.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*!
  2. \file gd25qxx.h
  3. \brief the header file of SPI flash gd25qxx driver
  4. \version 2023-06-30, V2.1.6, firmware for GD32F30x
  5. */
  6. /*
  7. Copyright (c) 2023, GigaDevice Semiconductor Inc.
  8. Redistribution and use in source and binary forms, with or without modification,
  9. are permitted provided that the following conditions are met:
  10. 1. Redistributions of source code must retain the above copyright notice, this
  11. list of conditions and the following disclaimer.
  12. 2. Redistributions in binary form must reproduce the above copyright notice,
  13. this list of conditions and the following disclaimer in the documentation
  14. and/or other materials provided with the distribution.
  15. 3. Neither the name of the copyright holder nor the names of its contributors
  16. may be used to endorse or promote products derived from this software without
  17. specific prior written permission.
  18. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  19. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  21. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  22. INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  23. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  24. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  25. WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  26. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  27. OF SUCH DAMAGE.
  28. */
  29. #ifndef GD25QXX_H
  30. #define GD25QXX_H
  31. #include "gd32f30x.h"
  32. #define SPI_FLASH_PAGE_SIZE 0x100
  33. #define SPI_FLASH_CS_LOW() gpio_bit_reset(GPIOE, GPIO_PIN_3)
  34. #define SPI_FLASH_CS_HIGH() gpio_bit_set(GPIOE, GPIO_PIN_3)
  35. /* initialize SPI0 GPIO and parameter */
  36. void spi_flash_init(void);
  37. /* erase the specified flash sector */
  38. void spi_flash_sector_erase(uint32_t sector_addr);
  39. /* erase the entire flash */
  40. void spi_flash_bulk_erase(void);
  41. /* write more than one byte to the flash */
  42. void spi_flash_page_write(uint8_t* pbuffer,uint32_t write_addr,uint16_t num_byte_to_write);
  43. /* write block of data to the flash */
  44. void spi_flash_buffer_write(uint8_t* pbuffer,uint32_t write_addr,uint16_t num_byte_to_write);
  45. /* read a block of data from the flash */
  46. void spi_flash_buffer_read(uint8_t* pbuffer,uint32_t read_addr,uint16_t num_byte_to_read);
  47. /* read flash identification */
  48. uint32_t spi_flash_read_id(void);
  49. /* initiate a read data byte (read) sequence from the flash */
  50. void spi_flash_start_read_sequence(uint32_t read_addr);
  51. /* read a byte from the SPI flash */
  52. uint8_t spi_flash_read_byte(void);
  53. /* send a byte through the SPI interface and return the byte received from the SPI bus */
  54. uint8_t spi_flash_send_byte(uint8_t byte);
  55. /* send a half word through the SPI interface and return the half word received from the SPI bus */
  56. uint16_t spi_flash_send_halfword(uint16_t half_word);
  57. /* enable the write access to the flash */
  58. void spi_flash_write_enable(void);
  59. /* poll the status of the write in progress (wip) flag in the flash's status register */
  60. void spi_flash_wait_for_write_end(void);
  61. void spi_flash_block_erase(uint32_t block_addr);
  62. #endif /* GD25QXX_H */