© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
DevHeads IoT Integration ServerDIIS
DevHeads IoT Integration Server•17mo ago
Sterling

Hard Fault When Using STM32 Nucleo-F446RE with Wiznet W5500 via SPI

I am using an STM32 Nucleo-F446RE with the Ethernet Wiznet W5500 via SPI. The SPI is configured as Master, CPOL = Low, CPHA = 1st Edge, 8-bit data, BaudRatePrescaler = 16. I see correct SPI waveforms on the oscilloscope, but I encounter a hard fault when debugging.

I have disabled other SPI modules to avoid conflicts. Here is the relevant initialization code:

// SPI and W5500 Initialization
void MX_SPI1_Init(void)
{
    hspi1.Instance = SPI1;
    hspi1.Init.Mode = SPI_MODE_MASTER;
    hspi1.Init.Direction = SPI_DIRECTION_2LINES;
    hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
    hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
    hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
    hspi1.Init.NSS = SPI_NSS_SOFT;
    hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16;
    if (HAL_SPI_Init(&hspi1) != HAL_OK)
    {
        Error_Handler();
    }
}

void W5500_Init(void)
{
    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_RESET); // Reset W5500
    HAL_Delay(1);
    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_SET);
    HAL_Delay(1);

    uint8_t reg = 0x01; uint8_t value = 0xF0;
    HAL_SPI_Transmit(&hspi1, &reg, 1, HAL_MAX_DELAY);
    HAL_SPI_Transmit(&hspi1, &value, 1, HAL_MAX_DELAY);
}
// SPI and W5500 Initialization
void MX_SPI1_Init(void)
{
    hspi1.Instance = SPI1;
    hspi1.Init.Mode = SPI_MODE_MASTER;
    hspi1.Init.Direction = SPI_DIRECTION_2LINES;
    hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
    hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
    hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
    hspi1.Init.NSS = SPI_NSS_SOFT;
    hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16;
    if (HAL_SPI_Init(&hspi1) != HAL_OK)
    {
        Error_Handler();
    }
}

void W5500_Init(void)
{
    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_RESET); // Reset W5500
    HAL_Delay(1);
    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_SET);
    HAL_Delay(1);

    uint8_t reg = 0x01; uint8_t value = 0xF0;
    HAL_SPI_Transmit(&hspi1, &reg, 1, HAL_MAX_DELAY);
    HAL_SPI_Transmit(&hspi1, &value, 1, HAL_MAX_DELAY);
}


Fault registers when the crash occurs:
- CFSR:
0x00000002
0x00000002
(Data bus error)
- HFSR:
0x40000000
0x40000000
(Forced hard fault)
- BFAR:
0x20001000
0x20001000
(Faulty memory access)

I am using STM32CubeIDE. Below is my HardFault handler:

void HardFault_Handler(void)
{
    while (1) {}
}
void HardFault_Handler(void)
{
    while (1) {}
}


Could someone please help me resolve this issue? 🙏🏽.
DevHeads IoT Integration Server banner
DevHeads IoT Integration ServerJoin
The DevHeads IoT Integration Server accelerates technology engineering by helping pro devs learn, share and collaborate.
2,984Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Configuring USB CDC Rx Interrupt for STM32-F446RE (Nucleo)
DevHeads IoT Integration ServerDIISDevHeads IoT Integration Server / 🪲-firmware-and-baremetal
2y ago
Issues with Viewing PRINTF Output on STM32 Nucleo L476RG with X-Nucleo IDB05A1
DevHeads IoT Integration ServerDIISDevHeads IoT Integration Server / 🪲-firmware-and-baremetal
17mo ago
can somebody help me with my STM32 Nucleo H743ZI2 ?
DevHeads IoT Integration ServerDIISDevHeads IoT Integration Server / 🪲-firmware-and-baremetal
2y ago
Why does enabling SPI peripheral in STM32 Nucleo L476RG change the master bit to 0?
DevHeads IoT Integration ServerDIISDevHeads IoT Integration Server / 🪲-firmware-and-baremetal
2y ago