RAK3172 SPI HardFault

Good day,

When porting SPI NOR-Flash and FRAM implementation from another project on RAK3172, the MCU hits HardFault when simple accessing SPI functions.
Reduced all the code to the minimum:

    SPI.beginTransaction (SPISettings (8000000, MSBFIRST, SPI_MODE0));
    SPI.transfer(&txBuf[0], &rxBuf[0], 5);
    SPI.endTransaction();

where txBuf and rxBuf are global variables. This piece of code executed in “setup” function.

Backtrace:

Version RUI3 - 4.1.1

Found copy-paste mistake in “uhal_spimst_setup_mode”, CPHA compared with CPOL value:

void uhal_spimst_setup_mode(udrv_spimst_port port, ENUM_SPI_MST_CPHA_T CPHA, ENUM_SPI_MST_CPOL_T CPOL) {
    if (CPHA == SPI_MST_CPOL_0)
        hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
    else if (CPHA == SPI_MST_CPOL_1)
        hspi1.Init.CLKPhase = SPI_PHASE_2EDGE;
    if (CPOL == SPI_MST_CPOL_0)
        hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
    else if (CPOL == SPI_MST_CPOL_1) 
        hspi1.Init.CLKPolarity = SPI_POLARITY_HIGH;
}

think correct variant :

void uhal_spimst_setup_mode(udrv_spimst_port port, ENUM_SPI_MST_CPHA_T CPHA, ENUM_SPI_MST_CPOL_T CPOL) {
    if (CPHA == SPI_MST_CPHA_0)
        hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
    else if (CPHA == SPI_MST_CPHA_1)
        hspi1.Init.CLKPhase = SPI_PHASE_2EDGE;
    if (CPOL == SPI_MST_CPOL_0)
        hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
    else if (CPOL == SPI_MST_CPOL_1) 
        hspi1.Init.CLKPolarity = SPI_POLARITY_HIGH;
}

Hello @croman13n3c

Thank you for reporting this problem. I sent it to our R&D team to fix it.