Skip to content

Commit

Permalink
Merge pull request #181 from adafruit/fix-pico-jedec
Browse files Browse the repository at this point in the history
correctly get jedec for pico
  • Loading branch information
hathach authored Nov 11, 2024
2 parents 641327b + 6271024 commit 0739c83
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
16 changes: 13 additions & 3 deletions examples/flash_info/flash_info.ino
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,24 @@ void setup() {
// Using a flash device not already listed? Start the flash memory by passing
// it the array of device settings defined above, and the number of elements
// in the array.

// flash.begin(my_flash_devices, flashDevices);

uint32_t jedec_id = flash.getJEDECID();
Serial.print("JEDEC ID: 0x");
Serial.println(flash.getJEDECID(), HEX);
Serial.print("Flash size: ");
Serial.println(jedec_id, HEX);
Serial.print("Flash size (usable): ");
Serial.print(flash.size() / 1024);
Serial.println(" KB");

#ifdef ARDUINO_ARCH_RP2040
// For rp2 since flash device is also used for storing code, the flash.size()
// only return usable flash size for data which is dictated by e.g Menu->Flash
// Size -> 2MB (Sketch 1920KB, FS 64KB) --> size = 64KB For reference purpose,
// we only try to find and print actual flash device size using JEDEC here
Serial.print("Flash size (raw): ");
Serial.print(1 << ((jedec_id & 0xff) - 10));
Serial.println(" KB");
#endif
}

void loop() {
Expand Down
9 changes: 1 addition & 8 deletions src/rp2040/Adafruit_FlashTransport_RP2040.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ Adafruit_FlashTransport_RP2040::Adafruit_FlashTransport_RP2040(
void Adafruit_FlashTransport_RP2040::begin(void) {
_flash_dev.total_size = _size;

#if 0
// Read the RDID register only for JEDEC ID
uint8_t const cmd[] = {
0x9f,
Expand All @@ -96,20 +95,14 @@ void Adafruit_FlashTransport_RP2040::begin(void) {
};
uint8_t data[4];
fl_lock(_idle_other_core_on_write);
flash_do_cmd(cmd, data, 5);
flash_do_cmd(cmd, data, 4);
fl_unlock(_idle_other_core_on_write);

uint8_t *jedec_ids = data + 1;

_flash_dev.manufacturer_id = jedec_ids[0];
_flash_dev.memory_type = jedec_ids[1];
_flash_dev.capacity = jedec_ids[2];
#else
// skip JEDEC ID
_flash_dev.manufacturer_id = 0xad;
_flash_dev.memory_type = 0xaf;
_flash_dev.capacity = 0x00;
#endif
}

void Adafruit_FlashTransport_RP2040::end(void) {
Expand Down

0 comments on commit 0739c83

Please sign in to comment.