From F429ZI to G431 porting software


I’m working on a project where I need to port my code from the F429ZI wich I used to be conform with DWM1000 example provided by Decawave. The twr example (5b and 5a) is working fine.

Now for my application I’m using an STM32G431 but I have troubles while porting.

A little context:
I use STM32cubeide and my MCU is mounted on the nucleo32 for g431.

What I did to port my example is create an IOC file with SPI1 and CS, RESET, IRQ pins named in the same way as it is on F429. Because I’m lazy I compiled to find were to replace halF4xx librairies by halG4xx (and also the usart port). A few moment later I have a good compiling project.

I solved also a few issue linked to clock (I rebuilt settings as it were in F429).

When I entered in debug mode it seems to wait for and SPI event but the init didn’t failed. At that time I thought that it is link to the nucleo that require some hardware modification to make the pin alone on the connector(jumper SB2 and SB3 present) then I moved the SPI port from 1 to 2. I had to rename all the spi port but refactor is there :slight_smile:

But now the behaviour is changing I have a message on serial “INIT FAILED” linked to an issue while reading the DEVID, this conclusion comes from a step into debug and I’m not sure this is the good conclusion du to the procedure.

Does any one succeed on porting from F4 to G4 series?
Did I miss something?
I don’t understand why the behaviour is different between the two SPI, any idea?

I still have some ideas to test:
I did a lot of fixes, I’m not sure that i did all at the same time, I should retry on a clean project.
I should comeback to SPI1 as the behaviour looked a bit better and investigate the source of the locked behaviour and try to solve it.

If it is missing something please tell me.


Hello every body, I investigated a bit more.

I rebuilt the project with the following fixes:
Clock at 36MHz to mitigated my poor dupond wiring
SPI1 port as it is showing better results
F4xx replaced everywhere by G4xx
No special warning.

When I run my code the code is blocked in the function stack as follow.

int readfromspi(uint16_t headerLength,
            const uint8_t *headerBuffer,
            uint32_t readlength,
            uint8_t *readBuffer)

int i;
decaIrqStatus_t stat ;
stat = decamutexon() ;
/* Blocking: Check whether previous transfer has been finished */
while (HAL_SPI_GetState(&hspi1) != HAL_SPI_STATE_READY);

HAL_GPIO_WritePin(DW_NSS_GPIO_Port, DW_NSS_Pin, GPIO_PIN_RESET); /**< Put chip select line low */

/* Send header */
for(i=0; i<headerLength; i++)
    HAL_SPI_Transmit(&hspi1, (uint8_t *)&headerBuffer[i], 1, HAL_MAX_DELAY); //No timeout

/* for the data buffer use LL functions directly as the HAL SPI read function
 * has issue reading single bytes */
while(readlength-- > 0)
    /* Wait until TXE flag is set to send data */
    while(__HAL_SPI_GET_FLAG(&hspi1, SPI_FLAG_TXE) == RESET)

It seems that I’m waiting for for some data in the MOSI buffer but I don’t understand why…

Just one precision:
To get there I tried something with the interrupts has it was blocking my code:
indent preformatted text by 4 spaces
void setup_DW1000RSTnIRQ(int enable)
GPIO_InitTypeDef GPIO_InitStruct;

    // Enable GPIO used as DECA RESET for interrupt
    GPIO_InitStruct.Pin = DW_RESET_Pin;
    GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    HAL_GPIO_Init(DW_RESET_GPIO_Port, &GPIO_InitStruct);

HAL_NVIC_EnableIRQ(EXTI15_10_IRQn); //pin #0 → EXTI #0
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 5, 0);
//todo modification of IRQ from EXTI0 to EXTI15_10_IRQn
HAL_NVIC_DisableIRQ(EXTI15_10_IRQn); //pin #0 → EXTI #0

    //put the pin back to tri-state ... as
    //output open-drain (not active)
    GPIO_InitStruct.Pin = DW_RESET_Pin;
    GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
    HAL_GPIO_Init(DW_RESET_GPIO_Port, &GPIO_InitStruct);


This was done in the port.c file based on the fact that I met some failure in this function and observing that the macro in port.h is doing so modification on the IRQ.

#if !(EXTI9_5_IRQn)
#define DECAIRQ_EXTI_IRQn (23)

#if !(EXTI0_IRQn)
#define EXTI0_IRQn (6)

Do you have any idea about my problem?