Hey @Magneon,
thanks a lot for your most valuable input! I implemented it as well, but as you were sugesting, using SPI3 on PB3/4, which is definitely much easier than using the pins you are using. I also managed to use USART1 now for debugging purposes. The hardest part was finding out how to modify the software and I haven’t found a really nice way yet, but ok, it works. As far as SPI goes, I attached an AS5147 to it, used your code, enabled SPI3 on the alternate pins in variant_B_G431B_ESC1.h and I recieve “something”, which changes as I turn the motor shaft. The problem is that the position jumps back a lot when I turn the shaft (like a reset every few rad). Do you (or anybody) else have any ideas, what could be wrong? I reduced the baudrate already, but it did not help either. Also, is there documentation on using the sensor in SSI mode somewhere available? I could not find any.
For all others that might be interested, here the changes I implemented:
A) Disconnect USART2 and connect USART1
1. Remove R23 and R24 (on the daughter board, easiest to cut them in the middle and then desolder)
B) Connect USART1 if you intend to use the serial port 1:
1. Solder thin wires to the now free pins of R23/24 (the pads closer to U3, further away from the USB port)
2. Secure the wires with some hot glue.
3. Connect the wire from R23 to the pad for hall sensor 2.
4. Connect the wire from R24 to the pad for hall sensor 1.
C) Fixes required in arduino-STM32 (only if you intend to use the serial port 1)
1. In file …..\variants\STM32G4xx\G431C(6-8-B)U_G441CBU\variant_B_G431B_ESC1.h, change line 205ff:
#define SERIAL_UART_INSTANCE 1 //Connected to ST-Link
// Default pin used for 'Serial' instance (ex: ST-Link)
// Mandatory for Firmata
#ifndef PIN_SERIAL_RX
#define PIN_SERIAL_RX PB7 // PB4
#endif
#ifndef PIN_SERIAL_TX
#define PIN_SERIAL_TX PB6 // PB3
#endif
Save this explicitly!!! NOTE: You will need to revert this change if you want to use USART2 again for debugging!
2. In ……\variants\STM32G4xx\G431C(6-8-B)U_G441CBU\PeripheralPins_B_G431B_ESC1.c enable line 188 and 205.
Line 181ff:
#ifdef HAL_UART_MODULE_ENABLED
WEAK const PinMap PinMap_UART_TX[] = {
// {PA_2, LPUART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_LPUART1)},
// {PA_2_ALT1, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)},
// {PA_9, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART1)},
// {PA_14, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)},
{PB_3, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)},
{PB_6, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART1)},
// {PB_9, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART3)},
// {PB_10, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART3)},
// {PB_11, LPUART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_LPUART1)},
// {PC_4, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART1)},
// {PC_10, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART3)},
// {NC, NP, 0}
};
#ifdef HAL_UART_MODULE_ENABLED
WEAK const PinMap PinMap_UART_RX[] = {
// {PA_3, LPUART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_LPUART1)},
// {PA_3_ALT1, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)},
// {PA_10, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART1)},
// {PA_15, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)},
{PB_4, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)},
{PB_7, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART1)},
// {PB_8, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART3)},
// {PB_10, LPUART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_LPUART1)},
// {PB_11, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART3)},
// {PC_11, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART3)},
{NC, NP, 0}
};
#endif
Save this explicitly!!! -> Make sure you are not using HALL_1 or HALL_2 for sensors etc. in your code anymore now!
Best regards,
Chris