Skip to content

Conversation

@anangl
Copy link
Member

@anangl anangl commented Aug 12, 2021

According to the nRF5340 PS, SPIM4 only supports 32 Mbps when the application core is running at 128 MHz. Drive configuration H0H1 must also be used for its pins for this speed.

Fixes #37221.

@anangl anangl added bug The issue is a bug, or the PR is fixing a bug area: Drivers area: SPI SPI bus platform: nRF Nordic nRFx labels Aug 12, 2021
@anangl anangl requested a review from tbursztyka as a code owner August 12, 2021 09:01
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if someone wants to use H1H0 on slower speeds?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do have this open #34854, but it may need to be updated to do the init at this location instead of at driver init.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if someone wants to use H1H0 on slower speeds?

It is not supported now by the driver, so I actually don't know what I could do about it in this PR. Do you have any suggestion?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Kconfig option works for me, alternatively this could check the status of the pins and force them to H1H0 if they are not H1H0 but if the speed is under 32MHz then it does not change the status to S1S0 and leaves it at what it is (either S1S0 or H1H0)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

somewhat related: #37572 (pinctrl could allow to set arbitrary pin settings from DT).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just realised that the HAL drivers already perform this configuration in nrfx_spim_init

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry that it took me so long to get back to this one. I reworked the PR to take advantage of the pin configuration performed by the nrfx driver. Please take a look once again.

According to the nRF5340 PS, SPIM4 only supports 32 Mbps when
the application core is running at 128 MHz. This patch adds
the corresponding check.

Signed-off-by: Andrzej Głąbek <[email protected]>
According to the nRF5340 PS, for 32 Mbps high-speed SPI using SPIM4,
drive configuration H0H1 must be used. The underlying nrfx_spim driver
does it properly in its initialization function, so change the shim to
(re)initialize the driver when the SPI configuration is to be changed
(only then the speed to use is known), to avoid the need of duplicating
the corresponding code in the shim itself.

Signed-off-by: Andrzej Głąbek <[email protected]>
@anangl anangl force-pushed the fix_max_spim_freq_on_nrf5340 branch from b618963 to 60e3d95 Compare September 9, 2021 12:01
@anangl
Copy link
Member Author

anangl commented Sep 9, 2021

Rebased.

@anangl anangl force-pushed the fix_max_spim_freq_on_nrf5340 branch from 60e3d95 to 73c8c5c Compare September 9, 2021 12:02
@anangl anangl requested a review from nika-nordic September 9, 2021 12:08
Apply the same changes as the previous commit made in the spi_nrfx_spim
shim, to keep these two shims aligned.

Signed-off-by: Andrzej Głąbek <[email protected]>
@anangl anangl force-pushed the fix_max_spim_freq_on_nrf5340 branch from 73c8c5c to 4e1cf36 Compare September 9, 2021 12:14
@carlescufi
Copy link
Member

@JordanYates could you please take another look?

@carlescufi
Copy link
Member

@gmarull can you approve if happy please?

Copy link
Member

@gmarull gmarull left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only have one comment regarding PM.

Comment on lines +342 to +344
/* No action needed at this point, nrfx_spim_init() will be
* called at configuration before the next transfer.
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PM hooks are no longer doing what is expected, ie, put the device into operational state when resume is called. Why is this change required?

Copy link
Member Author

@anangl anangl Sep 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, when resume was called, the device was brought to the state it was right after its initialization - it still needed to be reconfigured before the next transfer:

ret = init_spim(dev);
/* Force reconfiguration before next transfer */
data->ctx.config = NULL;

(at the device initialization, the nrfx driver was initialized with a default configuration, which was then altered accordingly when a transfer was requested). Now the difference is that the initialization of the device does not include the initialization of the nrfx driver - this is done when the device is configured right before a transfer is performed (only then we know the frequency, SPI mode, etc. that should be used), so there is no point in calling nrfx_spim_init() here and then, right before the next transfer, calling nrfx_spim_uninit() in order to be able to call nrfx_spim_init() again.
Alternatively, I would need to store the currently used nrfx driver configuration to be able to use it here in the call to nrfx_spim_init(). Then it would be not needed to reconfigure the device before the next transfer, provided that transfer would be requested with the same configuration as the last transfer before the device was suspended. But I'm not sure if it is worth spending more RAM just to achieve this possibility.

data->ctx.config = NULL;
/* No action needed at this point, nrfx_spi_init() will be
* called at configuration before the next transfer.
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as previous comment

@carlescufi
Copy link
Member

@JordanYates please take another look

@nashif nashif merged commit 36451e6 into zephyrproject-rtos:main Sep 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: Drivers area: SPI SPI bus bug The issue is a bug, or the PR is fixing a bug platform: nRF Nordic nRFx

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nRF5340: SPIM4 invalid clock frequency selection

8 participants