Good news, I have a full fledged SPI3 running on the B-G431B-ESC1 board. It takes away the ability to perform BEMF measurement, but that’s not supported by SimpleFOC anyway. Also, you cannot attach hall sensors anymore, but at least I don’t need them if I have the SPI interface now. I tested with an AS5147 sensor on a broken board only (unfortunately I have a few of them…) so far, but I see no reason, why it should not work on a functional board too, however, that’s yet to be proven. Here is how it works:
Follow the instructions from the previous posts to use SPI3 in SSI mode. Next, you need to solder a wire connecting the BEMF sensing pin of the CPU to your sensor’s MOSI pin. I attached it to the cathode of D15. It is a very small pad to solder, but well accessible at the edge of the board. I first fixed the wire with some hot glue near the pad and then soldered it under a microscope (my hands are everything but steady). It took me some attempts, but worked.
In the code you will have to enable the pin as SPI_MOSI in …\variants\STM32G4xx\G431C(6-8-B)U_G441CBU\PeripheralPins_B_G431B_ESC1.c.In my case it looks like this (starting round line 240):
#ifdef HAL_SPI_MODULE_ENABLED
WEAK const PinMap PinMap_SPI_MOSI[] = {
// {PA_7, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI1)},
// {PA_11, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)},
// {PB_5, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI1)},
// {PB_5_ALT1, SPI3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF6_SPI3)},
{PB_5, SPI3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF6_SPI3)},
// {PB_15, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)},
{NC, NP, 0}
};
#endif
Note that I copied the PB_5_ALT1 line and renamed the pin to PB_5, since otherwise I ran into problems.
Now we still have the issue, that the BEMF sensing circuitry is still attached to PB5. This should not matter, if you pull all the BEMF control outputs low, before using SPI somewhere in your code:
// BEMF outputs
pinMode(A_BEMF1, OUTPUT);
pinMode(PB0, OUTPUT);
pinMode(A_BEMF3, OUTPUT);
digitalWrite(A_BEMF1, LOW);
digitalWrite(PB0, LOW);
digitalWrite(A_BEMF3, LOW);
That’s it! All together well doable. Tomorow I’ll try with my last fully functioning board and a motor attached.
Cheers,
Chris