-
Notifications
You must be signed in to change notification settings - Fork 2
initial SPI flash #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
👋 Hello antmak, we appreciate your contribution to this project! Click to see more instructions ...
Review and merge process you can expect ...
|
Just a comment regarding SPI flash functions: at least on newer chips (S3/C3 and later), I would recommend calling the newer esp_flash driver instead of the legacy ROM functions. There are several advantages:
Depending on the specific chip, esp_flash ROM driver requires some patches, but it's easy to find what needs to be patched by looking at the ROM patches in esp-idf. For older chips, perhaps bundling the entire esp_flash driver into the stub is not such a bad option, need to check the code size... |
f2b9b85
to
09816f4
Compare
ac58159
to
887f7f0
Compare
src/esp32/src/flash.c
Outdated
uint32_t strapping = REG_READ(GPIO_STRAP_REG); | ||
/* If GPIO1 (U0TXD) is pulled low and flash pin configuration is not set in efuse, assume | ||
* HSPI flash mode (same as normal boot) */ | ||
if (spiconfig == 0 && (strapping & 0x1c) == 0x08) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know we are copying this lines somewhere else, but it would be nice to know what is this magic numbers meaning? 0x1c, 0x8.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, strap stuff is something that will still need putting order. It was just moved from the original stub
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated in target_flash.c, please let me know if it is not clear
c67a222
to
6327072
Compare
Looks like a good idea. As far as I see implementation of https://github.com/espressif/openocd-esp32/blob/master/contrib/loaders/flash/espressif/esp32c3/stub_flasher_chip.c#L346 is almost equal to esp_flash_read_encrypted. So
To simplify development I'd implement base simple flash functionality (read, write, erase, w/o encryption) with ROM functions at first. After we have it working and all related tests passed we can try to switch to esp_flash driver. Base API for the driver and ROM functions are very similar: // ROM funcs
esp_rom_spiflash_result_t esp_rom_spiflash_erase_chip(void);
esp_rom_spiflash_result_t esp_rom_spiflash_erase_area(uint32_t start_addr, uint32_t area_len);
esp_rom_spiflash_result_t esp_rom_spiflash_read(uint32_t src_addr, uint32_t *dest, int32_t len);
esp_rom_spiflash_result_t esp_rom_spiflash_write(uint32_t dest_addr, const uint32_t *src, int32_t len);
// flash driver
esp_err_t esp_flash_erase_chip(esp_flash_t *chip);
esp_err_t esp_flash_erase_region(esp_flash_t *chip, uint32_t start, uint32_t len);
esp_err_t esp_flash_read(esp_flash_t *chip, void *buffer, uint32_t address, uint32_t length);
esp_err_t esp_flash_write(esp_flash_t *chip, const void *buffer, uint32_t address, uint32_t length); So migration at that point seems to be smooth. We can switch to the driver for ESP32 (the oldest chip) and evaluate difference in size. Of course, that will the diff for base API only. @erhankur WDYT? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @erhankur suggestion to implement functionality enough for OpenOCD command flash info
(or special test command) for each target and print size, manufacturer id or something useful.
Also do cleanups and re-organize identical code to be reusable.
src/esp32/src/flash.c
Outdated
extern uint32_t ets_efuse_get_spiconfig(void); | ||
extern void esp_rom_spiflash_attach(uint32_t ishspi, bool legacy); | ||
extern esp_rom_spiflash_chip_t g_rom_flashchip; | ||
extern uint8_t g_rom_spiflash_dummy_len_plus[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These definitions are used for all chips. So seems to be reasonable t move them to one header file like it is done in IDF.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made the common code a bit different way, ptal
src/esp32c6/src/flash.c
Outdated
#define g_rom_flashchip (rom_spiflash_legacy_data->chip) | ||
#define g_rom_spiflash_dummy_len_plus (rom_spiflash_legacy_data->dummy_len_plus) | ||
|
||
__attribute__((unused)) static inline uint32_t device_id_from_spi_rdid() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have the same implementation for C3. Can be moved to common file
__attribute__((unused)) static inline uint32_t device_id_from_spi_rdid()
{
WRITE_PERI_REG(SPI_MEM_W0_REG(1), 0);
WRITE_PERI_REG(SPI_MEM_CMD_REG(1), SPI_MEM_FLASH_RDID);
while (READ_PERI_REG(SPI_MEM_CMD_REG(1)) != 0)
;
uint32_t rdid = READ_PERI_REG(SPI_MEM_W0_REG(1)) & 0xffffff;
return ((rdid & 0xff) << 16) | (rdid & 0xff00) | ((rdid & 0xff0000) >> 16);;
}
__attribute__((unused)) static inline uint32_t device_id_from_rom()
{
// Sets the correct g_rom_flashchip.device_id from SPI_MEM_FLASH_RDID in ROM code
esp_rom_spi_flash_update_id();
return g_rom_flashchip.device_id;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, fixed it according to the design
@gerekon As we discussed internally, it may be best to write |
8efb577
to
6b45958
Compare
#define PERIPHS_SPI_FLASH_BITS_RDID SPI_MEM_FLASH_RDID | ||
|
||
// If we have many defines here, we'll move the common code to common/soc_impl_xxx.h, | ||
// then include it here |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: comply the design, make a couple of common headers
@antmak now this PR looks big enough to review carefully. How can we split it to smaller parts? For example; And I would like to discuss structure change reason in one PR. (Maybe in seperate one or in the PR you really need that changes) |
(Proposes the design for discussion.)