SPI1 not working on STM32H723VEH6 #2813
-
Hi, I'm a bit new to working with STM32s but I cannot for the life of me get SPI to work on this chip. The issueHere is an example sketch that doesnt work for me: #include <Arduino.h>
#include <SPI.h>
void setup()
{
Serial.setTx(PB6_ALT2);
Serial.setRx(PB7_ALT1);
Serial.begin(115200);
SPIClass spi(PD7 /* MOSI */, PB4 /* MISO */, PB3 /* SCK */, PA15 /* CS */);
spi.begin();
Serial.print("test");
digitalWrite(PA15, LOW);
spi.transfer(0xAA);
digitalWrite(PA15, HIGH);
Serial.print("test");
}
void loop() {} The program simply hangs and never prints out the second test. Troubleshooting:I found that it end up hanging during this function from /**
* @brief This function is implemented by user to send/receive data over
* SPI interface
* @param obj : pointer to spi_t structure
* @param tx_buffer : tx data to send before reception
* @param rx_buffer : rx data to receive if not numm
* @param len : length in byte of the data to send and receive
* @retval status of the send operation (0) in case of error
*/
spi_status_e spi_transfer(spi_t *obj, const uint8_t *tx_buffer, uint8_t *rx_buffer,
uint16_t len)
{
spi_status_e ret = SPI_OK;
uint32_t tickstart, size = len;
SPI_TypeDef *_SPI = obj->handle.Instance;
uint8_t *tx_buf = (uint8_t *)tx_buffer;
if (len == 0) {
ret = SPI_ERROR;
} else {
tickstart = HAL_GetTick();
#if defined(SPI_CR2_TSIZE)
/* Start transfer */
LL_SPI_SetTransferSize(_SPI, size);
LL_SPI_Enable(_SPI);
LL_SPI_StartMasterTransfer(_SPI);
#endif
while (size--) {
#if defined(SPI_SR_TXP)
while (!LL_SPI_IsActiveFlag_TXP(_SPI));
#else
while (!LL_SPI_IsActiveFlag_TXE(_SPI));
#endif
LL_SPI_TransmitData8(_SPI, tx_buf ? *tx_buf++ : 0XFF);
#if defined(SPI_SR_RXP)
while (!LL_SPI_IsActiveFlag_RXP(_SPI));
#else
while (!LL_SPI_IsActiveFlag_RXNE(_SPI));
#endif
if (rx_buffer) {
*rx_buffer++ = LL_SPI_ReceiveData8(_SPI);
} else {
LL_SPI_ReceiveData8(_SPI);
}
if ((SPI_TRANSFER_TIMEOUT != HAL_MAX_DELAY) &&
(HAL_GetTick() - tickstart >= SPI_TRANSFER_TIMEOUT)) {
ret = SPI_TIMEOUT;
break;
}
}
#if defined(SPI_IFCR_EOTC)
// Add a delay before disabling SPI otherwise last-bit/last-clock may be truncated
// See https://github.com/stm32duino/Arduino_Core_STM32/issues/1294
// Computed delay is half SPI clock
delayMicroseconds(obj->disable_delay);
/* Close transfer */
/* Clear flags */
LL_SPI_ClearFlag_EOT(_SPI);
LL_SPI_ClearFlag_TXTF(_SPI);
/* Disable SPI peripheral */
LL_SPI_Disable(_SPI);
#else
/* Wait for end of transfer */
while (LL_SPI_IsActiveFlag_BSY(_SPI));
#endif
}
return ret;
}
#ifdef __cplusplus
} At the I am way too far out of my depth to really understand what that means, but after some more research I believe it might be related to the SCK pin I'm using (PB3) also being a jtag pin, and not being allowed to be used for SCK because JTAG takes preference. I don't use JTAG and use a 6 pin ST-Link connection to program/debug the board. Can someone help me understand what the problem might be? I'm not sure if it's a HW issue or a software issue, but a lot of the 'fixes' that involved disabling jtag had no effect (or I didn't implement them properly because idk what I'm doing). I also tried I should also mention I'm using Platformio Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Hi @DrewBrandt - SPIClass spi(PD7 /* MOSI */, PB4 /* MISO */, PB3 /* SCK */, PA15 /* CS */);
+ SPIClass spi(PD7 /* MOSI */, PB4 /* MISO */, PB3 /* SCK */); and do not forget to init the CS pin: |
Beta Was this translation helpful? Give feedback.
-
@fpistm #include <Arduino.h>
#include <SPI.h>
void setup()
{
Serial.setTx(PB6_ALT2);
Serial.setRx(PB7_ALT1);
Serial.begin(115200);
pinMode(PA15, OUTPUT);
// digitalWrite(PA15, HIGH);
SPIClass spi(PD7 /* MOSI */, PB4 /* MISO */, PB3 /* SCK */);
spi.begin();
Serial.print("test");
digitalWrite(PA15, LOW);
spi.transfer(0xAA);
digitalWrite(PA15, HIGH);
Serial.print("test");
}
void loop() {} Same result, never prints the second "test". I tried it with and without setting PA15 to high. Unfortunately I did not include any test points on this PCB so that I could verify clock signals or anything like that, as I havent had an issue like this before. My only way to verify if a signal is being sent is to either see it working or strip off the solder mask :( |
Beta Was this translation helpful? Give feedback.
-
I figured it out! For some reason when I made this variant, I only did the linker script and didn't mess with the clock settings at all... Probably because I didn't really understand them. But after following this issue and this variant guide, it's all working :D. Idk if it was the right thing to do, but I went into MX, set all the peripherals I was using (I2C1, SPI1, USART1) and then let it auto configure the clocks. |
Beta Was this translation helpful? Give feedback.
I figured it out! For some reason when I made this variant, I only did the linker script and didn't mess with the clock settings at all... Probably because I didn't really understand them. But after following this issue and this variant guide, it's all working :D. Idk if it was the right thing to do, but I went into MX, set all the peripherals I was using (I2C1, SPI1, USART1) and then let it auto configure the clocks.