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
EOS S3 Hal i2c and wishbone bus #4
base: master
Are you sure you want to change the base?
Conversation
Hi, thanks for your contribution! There are several things that I'd like to see change in the commit history. IMO it should roughly follow this pattern:
I'd also like to see changes to commit messages, i.e. it should have information about:
Here's a template:
Commits with fixes do not need to follow this pattern (because they are your own contribution), but commit message is still needed. One additional thing that I'd also want is a PR to Zephyr main repository that uses these changes. Without that, there's no real of testing your contribution in a automated way. |
Thanks for the initial review @fkokosinski ! I will try to follow your suggested flow and add all of that info. Will ping again when this is ready. For now - opened this zephyrproject-rtos/zephyr#59905 as a draft, as requested so you have a visibility of where these changes would be used. |
This commit introduces HAL for EOS S3 from Quicklogic for the I2C driver. Origin: QuickLogic-Corp/qorc-sdk URL: https://github.com/QuickLogic-Corp/qorc-sdk Version: v1.10.0 Purpose: Starting point for the I2C HAL for EOS S3 License: Apache 2.0 Maintained-by: QuickLogic Corporation I2C HAL: Add working I2C HAL for zephyr. Signed-off-by: Szymon Duchniewicz <szduchniewicz@gmail.com>
f8a2c93
to
d75acc6
Compare
Hi @fkokosinski , Updated as requested, ready for further review. Had issues with Line endings when adding the unedited file, as the files in this repo seem to have CRLFs rather than LFs as EOL. (In short - didn't realise git allows you to have different EOL in index vs in working directory) is it okay for me to amend all file endings to LF in this repo to avoid future issues? |
That IMO sounds more like a configuration issue (text editor, environment) on your end, not a problem with how files in this repo are formatted ;) As for individual commits:
|
* Remove FreeRTOS dependency imports * Remove commented code * Remove FFE clock enabling (Now done in EOS S3 SoC setup). Signed-off-by: Szymon Duchniewicz <szduchniewicz@gmail.com>
Signed-off-by: Szymon Duchniewicz <szduchniewicz@gmail.com>
* Update CMakeLists.txt. * Update Copyright. * Fix imports. * Clean up comments. Signed-off-by: Szymon Duchniewicz <szduchniewicz@gmail.com>
Yeah was a config issue, simply that in the git index for this repo some files are stored with file endings of CRLF, some of LF, whereas in the main zephyr repo only some binary files or svgs are stored as CRLF in the index - no code files are stored as CRLF. Not a very big issue, but sometimes can prove to be a nuisance. Im ok to leave it as is as well, just wanted to point it out.
💯
Now
I am not sure how this could be moved to the Zephyr driver exactly as it introduces checks for FFE CSR register whether it is busy or not interleaved in between other function calls ( https://www.quicklogic.com/wp-content/uploads/2020/06/QL-S3-Technical-Reference-Manual-Vol-1.pdf#page=254 ). The only way I could think of for now was to completely rewrite the entire HAL and move all of this upstream - there is no dependancy on any binary blobs after all so this is possible, simply would take some time. For now porting the HAL seemed like the easiest and most efficient way to add I2C support.
Updated the commit message to better reflect the changes - it is a CMakeLists.txt update plus some smaller refactors such as comment removals, import fixes and copyright attribution (all now described in the commit message) @fkokosinski Let me know if there are any further changes required |
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.
Hi, sorry for the late response!
zephyr_sources(eoss3_hal_i2c.c) | ||
zephyr_sources(eoss3_hal_wb.c) |
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 two lines should be conditionally compiled when CONFIG_I2C_EOS_S3
is defined, not when CONFIG_GPIO_EOS_S3
is.
HAL/src/eoss3_hal_wb.c
Outdated
@@ -148,8 +125,6 @@ HAL_StatusTypeDef HAL_WB_Init(UINT8_t ucSlaveSel) | |||
|
|||
HAL_PAD_Config(&padcfg); | |||
|
|||
//dbg_str_hex32("MOSI - pad6 =", IO_MUX->PAD_6_CTRL); | |||
|
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.
Please reduce the changes in the original file to a minimum, even if it means leaving commented out lines.
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, what is the specific reason for keeping the commented out code? Is it to keep the HAL as aligned to original as possible, or something else?
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 it to keep the HAL as aligned to original as possible
Exactly
HAL/src/eoss3_hal_wb.c
Outdated
@@ -161,7 +136,6 @@ HAL_StatusTypeDef HAL_WB_Init(UINT8_t ucSlaveSel) | |||
padcfg.ucSmtTrg = PAD_SMT_TRIG_DIS; | |||
|
|||
HAL_PAD_Config(&padcfg); | |||
//dbg_str_hex32("MISO - pad8", IO_MUX->PAD_8_CTRL); |
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.
Ditto
HAL/src/eoss3_hal_wb.c
Outdated
@@ -174,7 +148,6 @@ HAL_StatusTypeDef HAL_WB_Init(UINT8_t ucSlaveSel) | |||
padcfg.ucSmtTrg = PAD_SMT_TRIG_DIS; | |||
|
|||
HAL_PAD_Config(&padcfg); | |||
//dbg_str_hex32("CLK - pad10", IO_MUX->PAD_10_CTRL); |
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.
Ditto
HAL/src/eoss3_hal_wb.c
Outdated
@@ -188,7 +161,6 @@ HAL_StatusTypeDef HAL_WB_Init(UINT8_t ucSlaveSel) | |||
|
|||
HAL_PAD_Config(&padcfg); | |||
|
|||
//dbg_str_hex32("CS - pad9", IO_MUX->PAD_9_CTRL); |
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.
Ditto
HAL/src/eoss3_hal_i2c.c
Outdated
#include "Fw_global_config.h" | ||
|
||
#include <stdio.h> | ||
#include <stdint.h> | ||
#include <string.h> | ||
#include <stddef.h> | ||
#include <eoss3_dev.h> | ||
#include <eoss3_hal_def.h> | ||
#include <s3x_clock_hal.h> | ||
//#include <eoss3_hal_rcc.h> | ||
#include <eoss3_hal_i2c.h> | ||
#include <eoss3_hal_pad_config.h> | ||
#include "test_types.h" | ||
#include <eoss3_hal_wb.h> | ||
//#include "eoss3_hal_power.h" | ||
#include "Fw_global_config.h" |
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.
Please remove FreeRTOS-dependent includes only.
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.
To clarify - I should remove all FreeRTOS includes, but keep the commented out hal includes?
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.
Yes
* default it is not) | ||
* #define OSC_GET_FREQ_INC() (((AIP->OSC_CTRL_1 & 0xFFF) + 3) * 32768) | ||
*/ | ||
uiClock = (((AIP->OSC_CTRL_1 & 0xFFF) + 3) * 32768)/4/6; // TODO: Find a programatic way to get the dividor (6) from CLK_CTRL_C_0, supposedly done here: https://github.com/QuickLogic-Corp/qorc-sdk/blob/d61d064146c0ee927aa12b088b3bbbce60615f4d/Libraries/Power/src/s3x_clock.c#L685 |
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.
Not a fan of this change directly in the HAL tbh. It looks like HAL_I2C_SetClockFreq
is only called by HAL_I2C_Init
. Can we move this configuration to the Zephyr I2C driver after it calls the HAL_I2C_Init
function?
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, do you suggest then removing the entire HAL_I2C_SetClockFreq function, and rewriting it in the Zephyr I2C driver then? I'm happy to move it, if that's the case.
FYI, after adding this clock frequency configuration to the Zephyr I2C driver, its not possible to keep the HAL_I2C_SetClockFreq
functionbefore my changes as it relies on many FreeRTOS elements, so I would remove it in its entirety from this file.
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.
Yup, sounds good! Thanks for the continued effort
@@ -230,6 +237,7 @@ HAL_StatusTypeDef HAL_I2C_Write(UINT8_t ucDevAddress, UINT8_t ucAddress, UINT8_t | |||
eI2CState = I2C_READY; | |||
return HAL_ERROR; | |||
} | |||
waitFFEReady(MAX_CYCLES_FFE); |
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.
So how does the original code from qorc-sdk work, if they are not checking the FFE CSR 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.
When running it on the Quick Thing Plus board, it did not work with qorc-sdk samples either - I2C transmissions were failing. However, I will try and reflash the board with the original qorc-sdk code without my changes to confirm this and will share my findings. If indeed it is broken, I might also suggest this change to qorc-sdk.
without doing these checks however, the transmission failed every time on Zehyr as well. My suspicion are:
- this is broken on qorc-sdk as well, and if it is working then there is some delay introduced by other threads, which is not present on Zephyr (hence for stability, this wait is required)
- this is working on qorc-sdk and I misconfigured the I2C for qorc-sdk when testing it for QuickThing Plus with qorc-sdk. In this case, maybe the clock speed configured here https://github.com/zephyrproject-rtos/hal_quicklogic/pull/4/files/7f2916b388e26ee4bace4779da0ce5c2695aafca..e348ffd18778fc1aa212f830bd2b97b61a6cbcc4#diff-87abd87ab59fba2c37f505e3cb82a2aefdefdcd07126f4391195a971889dc29eR137 is incorrect, and if I reconfigure it properly, the issue will go away?
This particular issue is slightly beyond my knowledge of the underlying hardware, but I will try my best to give you a better answer, and test results
HAL/src/eoss3_hal_i2c.c
Outdated
#include <eoss3_dev.h> | ||
#include <eoss3_hal_def.h> | ||
#include <eoss3_hal_i2c.h> | ||
#include <eoss3_hal_pad_config.h> | ||
#include "eoss3_dev.h" | ||
#include "eoss3_hal_def.h" | ||
#include "eoss3_hal_i2c.h" | ||
#include "eoss3_hal_pad_config.h" | ||
#include "test_types.h" | ||
#include <eoss3_hal_wb.h> | ||
#include "eoss3_hal_wb.h" |
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.
Please don't refactor the original code - we want to keep it as similar to the original code as possible.
Any updates on this? Am working on a project that needs the I2C interface, and I'd prefer not to have to switch to FreeRTOS at this stage. |
Hi @MicroTransactionsMatterToo - I didn't have time to continue this over summer but picking this back up along with @JDuchniewicz. at the moment my fork and the driver in : zephyrproject-rtos/zephyr#59905 work, but are not up to the standard of the repos yet. (And I just saw I need to rebase the PR to the main zephyr repo as well) |
We will rebase later this week and try to close the PRs by the end of the month. @MicroTransactionsMatterToo |
That'd be great, in the meantime I pulled it into my local copy of the zephyr source, and it works just fine. If I find the time, I'll try getting the clocks configurable on Zephyr as well. I need that functionality to be able to provide hardware clocking to FPGA IPs. |
This PR adds HAL definitions for I2C driver which uses the WIshbone bus onboard the EOS S3 SoC, used in the QuickFeather board (https://docs.zephyrproject.org/latest/boards/arm/quick_feather/doc/index.html) and the QuickThing+ board (https://github.com/sparkfun/QuickLogic_Thing_Plus).
it is based on the EOS S3 HAL for FreeRTOS: https://github.com/antmicro/eos-s3-hal
There is a small fix I need to introduce (currently hardcoded Clock dividor value), which needs to be read and calculated from the proper register at runtime.
Opening this PR as I am currently at EOSS and want to get initial feedback, also will be opening a PR to main zephyr repo that will require this module to be updated before it can be merged in (I2C Zephyr driver for EOS S3 SoC)