Is it possible to share the same port for SP1 and SP3 SCK?

Hi everyone,

I'm in the middle of a project and am starting to run out of available GPIOs.

To save a pin, I was wondering if it's possible to use a single GPIO (for example, P0.13) as the SCK for two different SPI master instances, like SPI1 and SPI3.

The two SPI peripherals would be used mutually exclusively, never at the same time. My thinking is that I could dynamically reconfigure the pin mapping in software between transactions. For instance:

  1. Initialize my device and map P0.13 to SPI1.SCK.

  2. Perform all necessary transactions on the SPI1 bus.

  3. When I need to switch, I would uninit the SPI1 peripheral, disconnect the pin, and then re-initialize it to be used by SPI3.SCK.

Has anyone tried this? I'm curious if this approach is feasible and if there are any significant drawbacks I should be aware of, like timing overhead or potential bus glitches during the reconfiguration.

Any advice or alternative solutions for managing pin shortages would be greatly appreciated!

Thanks in advance.

Oriol

  • Hello,

    In principle this should work. The problem though is that dynamic switching is not something zephyr is very fond of in general, the configuration in devicetree is considered static, and pins and peripherals are initialized during early init of the chip. So likely you need to hack it in some way if you want this to work, e.g. that spi1 use a different SCK pin by default (maybe one that is not connected at all). Else I fear this will be difficult due to the way zephyr works.

    Kenneth

Related