Skip to content

Commit

Permalink
fix(spi_nand_flash): fix memory alignment issue occurring on esp32c3
Browse files Browse the repository at this point in the history
  • Loading branch information
RathiSonika committed Mar 3, 2025
1 parent 4eac7a4 commit 749a430
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions spi_nand_flash/src/nand_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,12 @@ esp_err_t nand_is_bad(spi_nand_flash_device_t *handle, uint32_t block, bool *is_
ESP_GOTO_ON_ERROR(read_page_and_wait(handle, first_block_page, NULL), fail, TAG, "");

// Read the first 2 bytes on the OOB of the first page in the block. This should be 0xFFFF for a good block
ESP_GOTO_ON_ERROR(spi_nand_read(handle->config.device_handle, (uint8_t *) &bad_block_indicator, handle->chip.page_size, 2),
ESP_GOTO_ON_ERROR(spi_nand_read(handle->config.device_handle, (uint8_t *) handle->read_buffer, handle->chip.page_size, 2),
fail, TAG, "");

bad_block_indicator = *(uint16_t *)handle->read_buffer;
ESP_LOGD(TAG, "is_bad, block=%"PRIu32", page=%"PRIu32",indicator = %04x", block, first_block_page, bad_block_indicator);
if (bad_block_indicator == 0xFFFF) {
*is_bad_status = false;
} else {
*is_bad_status = true;
}
*is_bad_status = (bad_block_indicator != 0xFFFF);
return ret;

fail:
Expand Down Expand Up @@ -232,16 +229,13 @@ esp_err_t nand_is_free(spi_nand_flash_device_t *handle, uint32_t page, bool *is_
uint16_t used_marker;

ESP_GOTO_ON_ERROR(read_page_and_wait(handle, page, NULL), fail, TAG, "");
ESP_GOTO_ON_ERROR(spi_nand_read(handle->config.device_handle, (uint8_t *)&used_marker,
ESP_GOTO_ON_ERROR(spi_nand_read(handle->config.device_handle, (uint8_t *)handle->read_buffer,
handle->chip.page_size + 2, 2),
fail, TAG, "");

used_marker = *(uint16_t *)handle->read_buffer;
ESP_LOGD(TAG, "is free, page=%"PRIu32", used_marker=%04x,", page, used_marker);
if (used_marker == 0xFFFF) {
*is_free_status = true;
} else {
*is_free_status = false;
}
*is_free_status = (used_marker == 0xFFFF);
return ret;
fail:
ESP_LOGE(TAG, "Error in nand_is_free %d", ret);
Expand Down

0 comments on commit 749a430

Please sign in to comment.