My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

W25Qxx.h 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #pragma once
  23. #include <stdint.h>
  24. #include HAL_PATH(../HAL, MarlinSPI.h)
  25. #define W25X_WriteEnable 0x06
  26. #define W25X_WriteDisable 0x04
  27. #define W25X_ReadStatusReg 0x05
  28. #define W25X_WriteStatusReg 0x01
  29. #define W25X_ReadData 0x03
  30. #define W25X_FastReadData 0x0B
  31. #define W25X_FastReadDual 0x3B
  32. #define W25X_PageProgram 0x02
  33. #define W25X_BlockErase 0xD8
  34. #define W25X_SectorErase 0x20
  35. #define W25X_ChipErase 0xC7
  36. #define W25X_PowerDown 0xB9
  37. #define W25X_ReleasePowerDown 0xAB
  38. #define W25X_DeviceID 0xAB
  39. #define W25X_ManufactDeviceID 0x90
  40. #define W25X_JedecDeviceID 0x9F
  41. #define WIP_Flag 0x01 /* Write In Progress (WIP) flag */
  42. #define Dummy_Byte 0xA5
  43. #define SPI_FLASH_SectorSize 4096
  44. #define SPI_FLASH_PageSize 256
  45. #define SPI_FLASH_PerWritePageSize 256
  46. class W25QXXFlash {
  47. private:
  48. static MarlinSPI mySPI;
  49. public:
  50. void init(uint8_t spiRate);
  51. static uint8_t spi_flash_Rec();
  52. static uint8_t spi_flash_read_write_byte(uint8_t data);
  53. static void spi_flash_Read(uint8_t *buf, uint16_t nbyte);
  54. static void spi_flash_Send(uint8_t b);
  55. static void spi_flash_SendBlock(uint8_t token, const uint8_t *buf);
  56. static uint16_t W25QXX_ReadID(void);
  57. static void SPI_FLASH_WriteEnable();
  58. static void SPI_FLASH_WaitForWriteEnd();
  59. static void SPI_FLASH_SectorErase(uint32_t SectorAddr);
  60. static void SPI_FLASH_BlockErase(uint32_t BlockAddr);
  61. static void SPI_FLASH_BulkErase();
  62. static void SPI_FLASH_PageWrite(uint8_t *pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite);
  63. static void SPI_FLASH_BufferWrite(uint8_t *pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite);
  64. static void SPI_FLASH_BufferRead(uint8_t *pBuffer, uint32_t ReadAddr, uint16_t NumByteToRead);
  65. };
  66. extern W25QXXFlash W25QXX;