Skip to main content
Graduate
December 16, 2024
Solved

nucleo-f439zi USB from Scratch falling into Hardfault

  • December 16, 2024
  • 3 replies
  • 1222 views

Moved from MPUs forum as STM32F4 is an MCU.


Hello, 
Im trying to write the USB code from scratch. 
I have written the code that enables and initializes the usb OTG and I can confirm that it receives SETUP packets in the RX FIFO. 

I am receiving the GET_DESCRIPTOR request and i am trying to respond to it but I am unable to write in the TX FIFO in order to respond to the packages.

I have followed and executed the steps in page 1368 ( IN data transfers , packet write). When i try to write to the FIFO using the memcyp command i am unable to confirm that the packet is indeed written in my FIFO and there is no change in the USB behavior ( appears as :Device Descriptor Request Failed in device manager after 10-30 seconds). 

If i try to manually write the FIFO in 32 or 64 bits at a time, it doesn't work at all and i get to the Hard Fault Handler.

The addresses i have tried to write packages to are 0x50001000 , 0x50002000 and 50001040 , nothing worked . 

    This topic has been closed for replies.
    Best answer by Stratosstratos

    I was getting to the HardFault_Handler () due to a pointer misuse .

    3 replies

    Super User
    December 16, 2024

    If i try to manually write the FIFO in 32 or 64 bits at a time, it doesn't work at all and i get to the Hard Fault Handler.

    Have you tried in 16 bits?

    Graduate
    December 17, 2024

    Just tried it , does NOT work , with 16 bits even then OUT packet cant be read.

    Graduate
    December 16, 2024

    You may check my USB code - link below. You need to read/write FIFO write data in 32-bit units, so no memcpy.

    Graduate
    December 17, 2024

    I tried not using memcpy and accessing the FIFO only in 32 bits but i get to the HardFault_Handler after trying to write to the FIFO. FYI for some reason reading the FIFO with memcpy ( , ,4) works fine. I tried reading it without memcpy in case it crashed the FIFO but the behavior remained the same. Thanks for the GitHub link.

    StratosstratosAuthorAnswer
    Graduate
    December 19, 2024

    I was getting to the HardFault_Handler () due to a pointer misuse .