Skip to content

Commit

Permalink
Merge pull request #314 from dgarske/stm32
Browse files Browse the repository at this point in the history
Add support for overriding the PORT/PIN for the STM32 Cube HAL
  • Loading branch information
embhorn authored Dec 8, 2023
2 parents 233bd33 + 09e3550 commit 60f86ed
Showing 1 changed file with 10 additions and 4 deletions.
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

0 comments on commit 60f86ed

Please sign in to comment.