cancel
Showing results for 
Search instead for 
Did you mean: 

nucleo-f439zi USB from Scratch falling into Hardfault

Stratosstratos
Associate

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 . 

1 ACCEPTED SOLUTION

Accepted Solutions
Stratosstratos
Associate

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

View solution in original post

6 REPLIES 6
Pavel A.
Evangelist III

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?

gbm
Lead III

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

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice

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

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.

I tried using your code from GitHub but I am having difficulties with a specific error, I already have opened an issue if you can check it out.

Stratosstratos
Associate

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