rp2040.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /**
  2. * @file rp2040.h
  3. * @brief RP2040-specific functions.
  4. *
  5. * This file is responsible for initialising and accessing
  6. * the SPI flash chip via RP2040 hardware.
  7. */
  8. #pragma once
  9. #include <stddef.h>
  10. #include <stdint.h>
  11. #include <stdbool.h>
  12. #define RP2040_CORE0_ADDR (0x01002927UL)
  13. #define RP2040_CORE1_ADDR (0x11002927UL)
  14. #define RP2040_RESCUE_ADDR (0xF1002927UL)
  15. #define RP2040_FAMILY_ID (0xE48BFF56UL)
  16. /**
  17. * @brief Initialise RP2040-specific hardware.
  18. *
  19. * @returns true on success, false otherwise.
  20. */
  21. bool rp2040_init(void);
  22. /**
  23. * @brief Read data from the SPI flash chip.
  24. *
  25. * @param[in] address target address within the flash address space.
  26. * @param[out] data pointer to the buffer to contain the data to be read.
  27. * @param[in] data_size size of the data to be read.
  28. * @returns true on success, false otherwise.
  29. */
  30. bool rp2040_flash_read_data(uint32_t address, void* data, size_t data_size);
  31. /**
  32. * @brief Erase one sector (4K) of the SPI flash chip.
  33. *
  34. * @param[in] address target address within the flash address space (must be sector-aligned).
  35. * @returns true on success, false otherwise.
  36. */
  37. bool rp2040_flash_erase_sector(uint32_t address);
  38. /**
  39. * @brief Program one page (256B) of the SPI flash chip.
  40. *
  41. * @param[in] address target address within the flash address space.
  42. * @param[in] data pointer to the buffer containing the data to be written.
  43. * @param[in] data_size size of the data to be written.
  44. * @returns true on success, false otherwise.
  45. */
  46. bool rp2040_flash_program_page(uint32_t address, const void* data, size_t data_size);