This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

usb device on stm32L151RD

I have designed system based on STM32L151. It uses usb for powering/charging and communicating to laptop. My system uses Embedded File System (SPI, 8MB) without RTX, USB(CDC Class), given by ST.
I have typical problem and did not find any answer on net and from ST. As long I do not any request from PC on USB to system, things are OK, i.e. I can store and send the file from system to laptop on USB. But if I send any request from Laptop like configuration/reading of file etc, sending file to PC does not work. While digging, I found that lower level fopen function generate hard fault exception, hinting wrong memory access (data address invalid). It happens only when there is req from host, else device can send file without any problem to host by system keypad operation.
I suspect that when EP_OUT is called, it is damaging the RAM area, which used by fopen function, like file information etc. I am new to USB, much can not do myself. I have 2K Stack and 1K heap, no of files opened at a time are 2.
Is anybody, faced problem like this, if yes, how they solved.
Is there any simple example to handle similar case, I do not need serial handling in system.
Thanks in advance.

Parents
  • > USB(CDC Class), given by ST

    Do you mean Virtual_COM_Port example on this ST library?

    STM32F10x and STM32L1xx USB full-speed device library v3.4.0
    www.st.com/.../stm32_usb-fs-device_lib.zip

    > I suspect that when EP_OUT is called, it is damaging the RAM area, which used by fopen function, like file information etc

    1) The USB packet memory appears on this address space, 0x4000 6000 - 0x4000 63FF
    In the map file, generated by compile/link, do you see any variable (array) in this address range?

    2) When the device receives a packet at the bulk out endpoint, EP3_OUT_Callback() (usb_endp.c) is called. In this routine, the packet is copied to USB_Rx_Buffer[] array. And USB_To_USART_Send_Data() is called with this array. Trace this process to find the RAM overwrite problem, if any.

    For example,
    a) USB_Rx_Buffer[] array may be too short to hold the packet.
    This array is declared in usb_endp.c,
    uint8_t USB_Rx_Buffer[VIRTUAL_COM_PORT_DATA_SIZE];

    And the VIRTUAL_COM_PORT_DATA_SIZE macro is defined in Virtual_COM_Port\inc\usb_desc.h
    #define VIRTUAL_COM_PORT_DATA_SIZE 64
    Did you change this value?

    b) Maybe, you've modified USB_To_USART_Send_Data() routine for your application.
    Is there any bug on this implementation?

    Tsuneo

Reply
  • > USB(CDC Class), given by ST

    Do you mean Virtual_COM_Port example on this ST library?

    STM32F10x and STM32L1xx USB full-speed device library v3.4.0
    www.st.com/.../stm32_usb-fs-device_lib.zip

    > I suspect that when EP_OUT is called, it is damaging the RAM area, which used by fopen function, like file information etc

    1) The USB packet memory appears on this address space, 0x4000 6000 - 0x4000 63FF
    In the map file, generated by compile/link, do you see any variable (array) in this address range?

    2) When the device receives a packet at the bulk out endpoint, EP3_OUT_Callback() (usb_endp.c) is called. In this routine, the packet is copied to USB_Rx_Buffer[] array. And USB_To_USART_Send_Data() is called with this array. Trace this process to find the RAM overwrite problem, if any.

    For example,
    a) USB_Rx_Buffer[] array may be too short to hold the packet.
    This array is declared in usb_endp.c,
    uint8_t USB_Rx_Buffer[VIRTUAL_COM_PORT_DATA_SIZE];

    And the VIRTUAL_COM_PORT_DATA_SIZE macro is defined in Virtual_COM_Port\inc\usb_desc.h
    #define VIRTUAL_COM_PORT_DATA_SIZE 64
    Did you change this value?

    b) Maybe, you've modified USB_To_USART_Send_Data() routine for your application.
    Is there any bug on this implementation?

    Tsuneo

Children