-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
stm32 / spiflash: Support defining exact flash chip(s) connected. #12722
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
01d336f
to
b3e145b
Compare
b3e145b
to
07c5c79
Compare
mp_soft_qspi_qread(self, len, dest); | ||
if (cmd == CMD_RD_SFDP) { | ||
// cmd, address and data on 1 line. | ||
// 3 addr bytes, 1 dummy byte (8 dummy cycles x 1 line) |
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.
This is a bit strange, the function here is read_cmd_qaddr_qdata
which explicitly asks for 4-lines of addr and data. But then this special case is using 1-line for addr and data.
So either:
- add a new function called
read_cmd_addr_data
which is used for commands like this one - change this function to be called
read_cmd_addr_data
and make it select the width of addr and data based on the cmd value, which is what you've done here
The first option feels more correct, because the bus shouldn't care about the values going over it, it should just do as instructed and write the data over the requested number of data lines.
The first option also means softqspi.c
and qspi.c
don't need to know about (or have a definition of) CMD_RD_SFDP
.
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 did start going down a path of passing in args to read_cmd_qaddr_qdata
to select the required settings... the problem I ran into was that it's not just the number of lines, it's also the dummy cycles. And if both those settings are exposed, the alternate-bytes should be as well arguably. And it all got quite messy and I reverted back to this.
If I ignore the other settings and just base the difference on the number of lines used, passing that in as a function arg is less code space use than duplicating the function and adding the extra entry to the mp_qspi_proto_t
.
To be fair these existing functions have dummy/AB settings all hard-coded apparently to suit the commands that just happen to be used by spiflash, so continuing down that path doesn't seem too bad until someone needs them to be more flexible for a new reason.
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.
Oh yeah, I also noticed last time that the new octospi driver in stm only support 1 and 2 line modes currently, auto-selected by which pins are defined...
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.
Yeah I agree it's not all consistent and could be more flexible. You're right that adding a new function takes up more code space, compared to reusing an existing one.
How about calling it read_cmd_addr_data()
and passing in the number of lines to use? It could just be an enum with only 2 options to start with, eg:
enum qspi_tranfer_mode {
QSPI_TRANSFER_CMD_ADDR_DATA,
QSPI_TRANSFER_CMD_QADDR_QDATA,
};
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'm just finishing up implementing it as an uint8_t lines
arg which gets passed 1
or 4
so far.... the enum approach gives better flexibility in future to make a labelled mode that changes different settings.
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.
The enum approach has been added and looks like it works well for me thanks.
drivers/memory/spiflash.c
Outdated
if (ret != 0 || sfdp[0] != *(uint32_t *)sfdp_header) { | ||
printf("mp_spiflash: sfdp not supported\n"); | ||
printf("Set MICROPY_HW_SPIFLASH_DEVICES or MICROPY_HW_BDEV_SPIFLASH_SIZE_BYTES"); | ||
printf("jedec ids: 0x%x 0x%x 0x%x\n", jedec_ids[0], jedec_ids[1], jedec_ids[2]); |
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.
This should use mp_printf(MICROPY_ERROR_PRINTER, ...)
.
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.
Sure, I did initially think that but saw printf
had already been used in this file. I'll change it everywhere to use the preferred approach.
f5bd1e3
to
8003704
Compare
860cfba
to
66c719d
Compare
66c719d
to
a4456ee
Compare
This is an automated heads-up that we've just merged a Pull Request See #13763 A search suggests this PR might apply the STATIC macro to some C code. If it Although this is an automated message, feel free to @-reply to me directly if |
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
Add some more details to the struct definition. Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
Fixes support for 4 line communication with chip, but maintains fallback to 2 or 1 line if hardware needs it. Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
The Serial Flash Discoverable Parameters (SFDP) is a jedec standard interface on (most/newer) spiflash chips that allows querying the flash size (amongst other things). Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
a4456ee
to
3033161
Compare
Different spiflash brands / models can require slightly different settings to use.
This PR allows a board profile to declare the model spiflash being used directly.
It's re-using a header of spiflash definitions already available in
drivers/memory/external_flash_device.h
, however new ones could be added inline in mpconfigboard.h if needed.This started as an additional commit in #12512 and also provides functionality first presented in #11932