Hard fault on LPC1788 when reading a byte

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • Hard fault on LPC1788 when reading a byte

    We’re getting a hard fault on our LPC1788 processor when executing an SVC #3 instruction after trying to read a character from the USB port after enumerating in CDC mode. The hard fault has only the Forced bit set. The SVC exception has a priority of 0 (the highest), and the processor is not in an exception when the hard fault occurs.

    If enumeration is the only thing done, the firmware keeps running normally after the connection. But once an attempt is made to read a character from the USB port (I’m using the USB_CDC_ReceiveTimed function), the first SVC instruction encountered causes a hard fault. There is no data at the USB port when we call the read function.

    I’ve traced through the function call to see what I/O was done in the USB device and came up with the following list:

    0x00040500 -> 0x2008C210 Command | Read 1 byte from EP 4 -> USB Command Code
    0x00000010 <- 0x2008C200 Read device interrupt status
    0x00000010 -> 0x2008C208 CCEMPTY -> USB device interrupt clear
    0x00000020 -> 0x2008C208 CDFULL -> USB device interrupt clear
    0x00040200 -> 0x2008C210 Read -> USB command code
    0x00000031 <- 0x2008C200 Read device interrupt status
    0x00000010 -> 0x2008C208 CCEMPTY -> USB device interrupt clear
    0x00000021 <- 0x2008C200 Read device interrupt status
    0x00000000 <- 0x2008C214 USB command data

    Testing shows that no USB interrupts occur after enumeration and during or after the read.

    The post was edited 1 time, last by jorick ().

  • Found it. Can't do a SVC call with interrupts disabled.

    The documentation says that the OS layer wants a couple of functions that disable and enable interrupts. This doesn't work with SafeRTOS. I used portENTER_CRITICAL and portEXIT_CRITICAL instead. This leaves interrupts enabled but ensures that task switching doesn't occur within the critical section.