-
Notifications
You must be signed in to change notification settings - Fork 3k
feature-qspi: QSPI HAL addition #5429
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
Conversation
Adding new QSPI HAL header file. This should help to use memory-maped devices as memories, graphical displays. The API consist of few functions, most important are read/write/write_command functions. The command format is: ``` ---------------------------------------------- | Instruction | Address | Alt | Dummy | Data | ---------------------------------------------- ``` We define only synch API at the moment.
How does this fit in with #4229 ? |
The API proposed there is slighty different (more oriented to a file system like, program/erase). You can view the file for hal API here https://github.com/kl-cruz/mbed-os/blob/61a510a15af9b780d260b24fea33920229074144/hal/qspi_api.h. #4229 (comment) - I left there a comment regarding HAL. We can continue discussion around it here. @stevew817 you got any driver for QSPI or even an example for any target that I can have a look at? I could not find any in the codebase, but recall there was one of GG targets that should have QSPI peripheral. |
@0xc0170 Our QSPI HAL doc lives ere: http://devtools.silabs.com/dl/documentation/doxygen/5.3.2/efm32gg11/html/group__QSPI.html |
Thanks Steve, I checked the docs. The API there is similar to the one here, found some diferencies but mostly as it is structured differently (read/write data and config). The write/read config maps to our |
Fixing by adding NONE values for both
Updated (see 2 commits for details) |
hal/qspi_api.h
Outdated
* @param obj QSPI object | ||
* @param command QSPI command | ||
* @param data TX buffer | ||
* @param[in,out] in - length TX buffer length in bytes, out - number of bites written |
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.
bites->bytes
hal/qspi_api.h
Outdated
* @param obj QSPI object | ||
* @param command QSPI command | ||
* @param data RX buffer | ||
* @param[in,out] in - length RX buffer length in bytes, out - number of bites read |
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.
bites->bytes
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.
will fix asap
Looks good other than the two minor corrections of bites->bytes in the comments. |
This provides a way to return how many bytes have been written/read (as status codes are returned via func ret value)
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.
Looks good!
hal/qspi_api.h
Outdated
* @param sclk The clock pin | ||
* @param ssel The chip select pin | ||
* @param hz The bus frequency | ||
* @param mode SPI mode |
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.
Is this just the master/slave mode or are we referring to SPI modes 0,1,2,3? Would be nice to add a 1 line comment if it's either.
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.
Will add Clock polarity and phase mode (0 - 3)
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.
Fixed
QSPI_STATUS_ERROR = -1, /**< Generic error >*/ | ||
QSPI_STATUS_INVALID_PARAMETER = -2, /**< The parameter is invalid >*/ | ||
QSPI_STATUS_OK = 0, /**< Function executed sucessfully >*/ | ||
} qspi_status_t; |
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.
How about some specific error codes like peripheral init fail, read/write fail along with generic error and maybe we can add more as it matures (buffer issues, bus error etc)?
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 would expect this might get more errors once we get some implementations. As this error is per function, I find it sufficient for cases like peripheral fail (if init returns ERROR) init phase failed. Or if write() returns error, write failed. If we got something like transfer(read+write) then write/read error would make sense.
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.
Thanks @0xc0170 . OK with me!
SPI mode means Clock polarity and phase mode (0 - 3)
/morph build |
I triggered CI build to move forward with this. This goes to feature branch feature-qspi, feedback is still open anytime even if this gets integrated to the branch. |
Build : SUCCESSBuild number : 493 Triggering tests/morph test |
@0xc0170 this seems like a very manual API. Are there any plans for enabling memory mapped QSPI devices? For example, it would be useful to have an API for setting up an external QSPI flash chip as memory mapped internal flash. |
struct { | ||
qspi_bus_width_t bus_width; /**< Bus width for the address >*/ | ||
qspi_address_size_t size; /**< Address size >*/ | ||
uint32_t value; /**< Address value >*/ |
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.
For memory mapped flash devices, do we only use the "value" element from the command structure?
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.
Can you elaborate ? provide more details ?
Note: This so far does not support memory mapped QSPI. I am about to add a proposal below for it.
Test : SUCCESSBuild number : 311 |
Exporter Build : SUCCESSBuild number : 114 |
It looks good. But I looked in the ST HAL QSPI driver and there are other parameters that are used during QSPI peripheral initialization and I think not covered in this API.
So, how are we going to set them ? Add other parameters in the Same thing for the qspi command. We have many other parameters and I don't know how to manage them with the actual API:
|
@marcuschangarm Currently looking at memory mapped mode support (execute in place - XIP mode). There could be two methods that would enable/disable memory mapped mode. I'll propose a change via separate comment and what implications they have.
@bcostm Thanks for the review. |
The proposal for extending this to cover memory mapped QSPI (execute code in place - XIP) in HAL. From a driver perspective, all it needs to do is enable/disable memory-mapped mode. This is usually a register in QSPI peripheral that controls this. Based on this, plus QSPI section, it would use QSPI peripheral for read if its within the defined section and it's active.
Each target defines QSPI specific memory section. QSPI would be used if an access is done within this defined section and memory-mapped is active. Based on this proposal it can come as separate addition to this feature branch, or I'll add it here. Waiting for review! |
I'll send a new pull request with memory mapped support (the latest comment above). This is ready for merge to the feature-branch (comments are always appreciated) |
Destination branch: feature-qspi
Adding new QSPI HAL header file. This should help to use memory-maped devices
as memories, graphical displays.
The API consist of few functions, most important are read/write/write_command functions.
The command format is:
We define only synch API at the moment. This patch contains only a header file.
We will provide an implementation for a target.
@jeromecoutant @LMESTM @kl-cruz @stevew817 @mmahadevan108 @Archcady @TomoYamanaka @jessexm @jacobjohnson-ON please have a look, might be interested in this, any feedback welcome!
cc @maclobdell @screamerbg @MarceloSalazar @ashok-rao