Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4824

General • Re: Reading and writing flash (W25Q128JVS)

$
0
0
Any ideas?
First, I'd suggest printing addresses, sizes and offsets in hex.

Second, make your code as simple as possible.

Finally, check you can write to some arbitrary 4KB block, then start moving the address upwards to see where it stops working.

This was my test for writing to flash -

Code:

#include <stdio.h>#include "pico/stdlib.h"#include <hardware/flash.h>#define ADDRESS 0x1009F000#define SIZE    4096unsigned char buffer[SIZE];int main() {    stdio_init_all();    for(int n=0; n < SIZE; n++) {      buffer[n] = (n + 1) & 0xFF;    }    buffer[0] = 'M';    buffer[1] = 'a';    buffer[2] = 'g';    buffer[3] = 'i';    buffer[4] = 'c';    buffer[5] = '!';    uint32_t ints = save_and_disable_interrupts();    flash_range_erase(ADDRESS - XIP_BASE, SIZE);    flash_range_program(ADDRESS - XIP_BASE, buffer, SIZE);    restore_interrupts(ints);    while (true) {        char a = (char) ((*(uint32_t *)(ADDRESS + 0)) >>  0) & 0xFF;        char b = (char) ((*(uint32_t *)(ADDRESS + 0)) >>  8) & 0xFF;        char c = (char) ((*(uint32_t *)(ADDRESS + 0)) >> 16) & 0xFF;        char d = (char) ((*(uint32_t *)(ADDRESS + 0)) >> 24) & 0xFF;        char e = (char) ((*(uint32_t *)(ADDRESS + 4)) >>  0) & 0xFF;        char f = (char) ((*(uint32_t *)(ADDRESS + 4)) >>  8) & 0xFF;        printf("%08x : %c%c%c%c%c%c\n", ADDRESS, a, b, c, d, e, f);        sleep_ms(1000);    }    return 0;}

Statistics: Posted by hippy — Tue Aug 13, 2024 5:50 pm



Viewing all articles
Browse latest Browse all 4824

Trending Articles