-
Notifications
You must be signed in to change notification settings - Fork 2k
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
drivers/sdcard_spi: make usec ztimer optional #17233
base: master
Are you sure you want to change the base?
drivers/sdcard_spi: make usec ztimer optional #17233
Conversation
Can you provide some test output here? |
drivers/include/periph/spi.h
Outdated
@@ -329,7 +329,7 @@ typedef struct { | |||
* @retval 0 success | |||
* @retval <0 error | |||
*/ | |||
int spi_init_with_gpio_mode(spi_t bus, spi_gpio_mode_t mode); | |||
int spi_init_with_gpio_mode(spi_t bus, const spi_gpio_mode_t* 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.
Are you sneaking in an API change 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.
Ehh true that should be split
@fjmolinas This one needs a rebase |
2ddacec
to
8436d78
Compare
@bergzand I have split out and merged all the dependencies, this is now only about making |
Maybe @benpicco can take a look at this one as well? |
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.
Still works on same54-xpro
which provides periph_spi_gpio_mode
but no ZTIMER_MSEC
drivers/sdcard_spi/sdcard_spi.c
Outdated
(gpio_init(card->params.miso, GPIO_IN_PU) == 0) && | ||
((!gpio_is_valid(card->params.power)) || | ||
(gpio_init(card->params.power, GPIO_OUT) == 0))) { | ||
|
||
DEBUG("gpio_init(): [OK]\n"); | ||
/* use soft-spi to perform init command to allow use of internal pull-ups on miso */ | ||
_dyn_spi_rxtx_byte = &_sw_spi_rxtx_byte; |
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.
_dyn_spi_rxtx_byte = &_sw_spi_rxtx_byte; | |
_dyn_spi_rxtx_byte = _sw_spi_rxtx_byte; |
will work as well
drivers/sdcard_spi/sdcard_spi.c
Outdated
(gpio_init(card->params.power, GPIO_OUT) == 0))) { | ||
DEBUG("gpio_init(): [OK]\n"); | ||
/* always use hw-spi */ | ||
_dyn_spi_rxtx_byte = &_hw_spi_rxtx_byte; |
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.
might as well
#define _dyn_spi_rxtx_byte _hw_spi_rxtx_byte
in that case then?
drivers/sdcard_spi/sdcard_spi.c
Outdated
for (int i = 0; i < SD_POWERSEQUENCE_CLOCK_COUNT; i += 1) { | ||
gpio_set(card->params.clk); | ||
ztimer_sleep(ZTIMER_USEC, SD_CARD_PREINIT_CLOCK_PERIOD_US / 2); | ||
gpio_clear(card->params.clk); | ||
ztimer_sleep(ZTIMER_USEC, SD_CARD_PREINIT_CLOCK_PERIOD_US / 2); | ||
_dyn_spi_rxtx_byte(card, SD_CARD_DUMMY_BYTE, &dummy); | ||
} |
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 used to send SD_POWERSEQUENCE_CLOCK_COUNT
bits, now it sends SD_POWERSEQUENCE_CLOCK_COUNT
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.
Ah true... will devide by 8
I'm currently trying the following:
|
Thanks for testing, are you running the |
I'm using a variant of this with an additional But |
Indeed seems like something has gone wrong here. |
I found some issues, but it also seems like sending 0xFF does not works on all hardware for the init sequence... |
Most delays are in ms units, only a couple are < 1ms an in those cases its for timeout in cases of retries erros, paying the price of waiting x10 more before failing can be worth the price of avoiding the use of ztimer_usec.
333a42d
to
7d63208
Compare
This needs a rebase. |
Contribution description
This PR does a couple of things:
sdcard_spi
to ztimer ( this was done simply running the coccinelle scipt)Testing procedure
I tested on a
samr21-xpro
with theperiph_spi_gpio_mode
feature enabled and disabled, reading and writing to the spi-card worked in all cases.