mirror of
https://github.com/mytechnotalent/Embedded-Hacking.git
synced 2026-07-06 20:47:55 +02:00
Updated Drivers
This commit is contained in:
@@ -44,22 +44,44 @@
|
||||
#define FLASH_TARGET_OFFSET (FLASH_DRIVER_SIZE_BYTES - FLASH_DRIVER_SECTOR_SIZE)
|
||||
#define FLASH_WRITE_LEN FLASH_DRIVER_PAGE_SIZE
|
||||
|
||||
int main(void) {
|
||||
stdio_init_all();
|
||||
|
||||
/**
|
||||
* @brief Fill a write buffer with 0xFF and copy the demo string into it
|
||||
*
|
||||
* @param buf Destination buffer
|
||||
* @param buf_size Size of the buffer in bytes
|
||||
*/
|
||||
static void _prepare_write_buf(uint8_t *buf, size_t buf_size) {
|
||||
memset(buf, 0xFF, buf_size);
|
||||
const char *msg = "Embedded Hacking flash driver demo";
|
||||
memcpy(buf, msg, strlen(msg));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Write the demo string to flash and print the read-back result
|
||||
*/
|
||||
static void _write_and_verify(void) {
|
||||
static uint8_t write_buf[FLASH_WRITE_LEN];
|
||||
static uint8_t read_buf[FLASH_WRITE_LEN];
|
||||
|
||||
memset(write_buf, 0xFF, sizeof(write_buf));
|
||||
const char *msg = "Embedded Hacking flash driver demo";
|
||||
memcpy(write_buf, msg, strlen(msg));
|
||||
|
||||
_prepare_write_buf(write_buf, sizeof(write_buf));
|
||||
flash_driver_write(FLASH_TARGET_OFFSET, write_buf, FLASH_WRITE_LEN);
|
||||
flash_driver_read(FLASH_TARGET_OFFSET, read_buf, FLASH_WRITE_LEN);
|
||||
|
||||
printf("Flash readback: %s\r\n", read_buf);
|
||||
|
||||
while (true) {
|
||||
tight_loop_contents();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Application entry point for the on-chip flash demo
|
||||
*
|
||||
* Writes a demo string to the last flash sector, reads it back,
|
||||
* and prints the result over UART.
|
||||
*
|
||||
* @return int Does not return
|
||||
*/
|
||||
int main(void) {
|
||||
stdio_init_all();
|
||||
_write_and_verify();
|
||||
while (true)
|
||||
tight_loop_contents();
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ void flash_driver_write(uint32_t flash_offset, const uint8_t *data, uint32_t len
|
||||
restore_interrupts(ints);
|
||||
}
|
||||
|
||||
|
||||
void flash_driver_read(uint32_t flash_offset, uint8_t *out, uint32_t len) {
|
||||
const uint8_t *flash_target_contents = (const uint8_t *)(XIP_BASE + flash_offset);
|
||||
memcpy(out, flash_target_contents, len);
|
||||
|
||||
Reference in New Issue
Block a user