I'm trying to figure out how to configure SPI - e.g. CPOL and CPHA choice. I find references in the code to CPOL and CPHA, but I really don't see how to use it (for example #define SPI_CR1_CPOL). It would seem that those would be bits as members of CR1, but see my next comment below about cr1 not seeming to exist in the code.
Also on Play Embedded I see cr1 and cr2 referenced as members of SPIConfig ( https://www.playembedded.org/blog/lever ... lications/ ), but yet in the code and doxygen documentation I don't see those fields anywhere.
Could you please provide some assistance?
Thanks,
John
SPI configuration confusion
- Giovanni
- Site Admin
- Posts: 14893
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: SPI configuration confusion
Hi,
Those fields are registers initialization values, their documentation is in the STM32 reference manual. This is true for most drivers, configuration structures often contain fields named after the physical peripheral register names.
The HAL documentation is generic, it does not contain fields that are specific of a micro.
Giovanni
Those fields are registers initialization values, their documentation is in the STM32 reference manual. This is true for most drivers, configuration structures often contain fields named after the physical peripheral register names.
The HAL documentation is generic, it does not contain fields that are specific of a micro.
Giovanni
Re: SPI configuration confusion
One thing that had been confusing me was that cr1 and cr2 were not directly in the definition of struct hal_spi_config, but I now see that in some files called hal_spi_lld.h there is a #define spi_lld_config_fields which brings in cr1 and cr2 which are uint16_t's.
I assume now that if I apply the bit definitions such as SPI_CR1_CPOL to cr1, that this must effectively turn on the desired bits. I'm still figuring this out, but I think I'm seeing it a little bit better now.
Thanks,
John
I assume now that if I apply the bit definitions such as SPI_CR1_CPOL to cr1, that this must effectively turn on the desired bits. I'm still figuring this out, but I think I'm seeing it a little bit better now.
Thanks,
John
- Giovanni
- Site Admin
- Posts: 14893
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: SPI configuration confusion
Hi,
Correct, the LLDs export macros that add architecture-dependent fields to the "standard" structures.
The non-portability is encapsulated in those configuration structures, the rest of the HAL is portable cross-platform, it is possible to make applications running on different MCUs by simply putting the configuration data in a separate module.
Giovanni
Correct, the LLDs export macros that add architecture-dependent fields to the "standard" structures.
The non-portability is encapsulated in those configuration structures, the rest of the HAL is portable cross-platform, it is possible to make applications running on different MCUs by simply putting the configuration data in a separate module.
Giovanni