Skip to content
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

Add support for overriding the PORT/PIN for the STM32 Cube HAL #314

Merged
merged 1 commit into from
Dec 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions hal/tpm_io_st.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@

#else /* STM32 CubeMX Hal SPI */
#define STM32_CUBEMX_SPI_TIMEOUT 250
#ifndef USE_SPI_CS_PORT
#define USE_SPI_CS_PORT GPIOA
#endif
#ifndef USE_SPI_CS_PIN
#define USE_SPI_CS_PIN 15
#endif
int TPM2_IoCb_STCubeMX_SPI(TPM2_CTX* ctx, const byte* txBuf, byte* rxBuf,
word16 xferSz, void* userCtx)
{
Expand All @@ -158,7 +164,7 @@

__HAL_SPI_ENABLE(hspi);
#ifndef USE_HW_SPI_CS
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_RESET); /* active low */
HAL_GPIO_WritePin(USE_SPI_CS_PORT, USE_SPI_CS_PIN, GPIO_PIN_RESET); /* active low */
#endif

#ifdef WOLFTPM_CHECK_WAIT_STATE
Expand All @@ -167,7 +173,7 @@
TPM_TIS_HEADER_SZ, STM32_CUBEMX_SPI_TIMEOUT);
if (status != HAL_OK) {
#ifndef USE_HW_SPI_CS
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_SET);
HAL_GPIO_WritePin(USE_SPI_CS_PORT, USE_SPI_CS_PIN, GPIO_PIN_SET);
#endif
__HAL_SPI_DISABLE(hspi);
return TPM_RC_FAILURE;
Expand All @@ -187,7 +193,7 @@
#endif
if (timeout <= 0) {
#ifndef USE_HW_SPI_CS
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_SET);
HAL_GPIO_WritePin(USE_SPI_CS_PORT, USE_SPI_CS_PIN, GPIO_PIN_SET);
#endif
__HAL_SPI_DISABLE(hspi);
return TPM_RC_FAILURE;
Expand All @@ -206,7 +212,7 @@
#endif /* WOLFTPM_CHECK_WAIT_STATE */

#ifndef USE_HW_SPI_CS
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_SET);
HAL_GPIO_WritePin(USE_SPI_CS_PORT, USE_SPI_CS_PIN, GPIO_PIN_SET);
#endif
__HAL_SPI_DISABLE(hspi);

Expand Down