Skip to main content
Graduate
March 2, 2024
Question

STM32F373 USB prgram

  • March 2, 2024
  • 10 replies
  • 4107 views

Hi, two questions:

1.- What config must set to PA11/PA12 pins? I set ALTERNATE FUNCTION (0x10) in MODER register, but what AF option must set? In STM32F373 manual there is no AF defined.

2.- I configure USB device (clocks/gpio) and i can access to USB registers as ADDR,... but EPs seems inhibed? you know the reason why?

 

Thanks a lot 

    This topic has been closed for replies.

    10 replies

    Super User
    March 2, 2024

    Hi,

    Why dont you use CubeMX and set USB -> device ...etc. there ?

    Even if you prefer to just write bare metal to registers yourself, look at the generated code and you see, what you need to do.

    JordiLAuthor
    Graduate
    March 2, 2024

    I did but have same result, 

    MX_USB_PCD_Init();

    HAL_PCD_EP_Open(&hpcd_USB_FS, 0, 64, EP_TYPE_CTRL);

    but EP0 no change values. EP0 -> 0x00.

    I write bare metal and use debug (CUBEide) and i can't modify the Eps

    Super User
    March 2, 2024

    You didnt tell which  board , usb hardware tested and working etc. -- so..?

    +

    Did you setup with cube usb-> device -> ??

    JordiLAuthor
    Graduate
    March 3, 2024

    Use STM32373-Eval board in order to develope a USB driver.

    If generate code with CUBEmx i have the same problem as if i write my own code.

    Super User
    March 2, 2024

    1.

    Based on Cube, AF14

    @Imen.D, this information is missing from the 'F373 DS Alternate functions for port PA table, can it please be fixed?

    2.

    > i can access to USB registers as ADDR,... but EPs seems inhibed? 

    How do you know?

    JW

    JordiLAuthor
    Graduate
    March 3, 2024

    1- Set PA12/PA11 -> Alternate function / High Speed / AF14

    GPIOA->MODER = GPIOA->MODER | 0x02800000;

    GPIOA->OSPEEDR = GPIOA->OSPEEDR | 0x03C00000; //Pins PA12-PA11 -> High speed

    GPIOA->AFR[1] = GPIOA->AFR[1] | 0x000EE000; //Pins PA12-PA11 -> AF14 USB pins !!!!!

    2- Set USB clock enable

    RCC->APB1ENR = RCC->APB1ENR | 0x00800000; // enable USB clock

    3- Clean USB Registers

    USB_REG->CNTR = USB_REG->CNTR & 0xFFFD; // Clear PWND bit

    //wait 1uS

    HAL_Delay(1);

    USB_REG->CNTR = USB_REG->CNTR & 0xFFFE; // Clear FRES bit

    USB_REG->ISTR = 0x0000; // Clear spourious interrupts

    4- Set USB->ADDR = USB->ADDR | 0x80; //Enable device

    Theorically, now USB is ready to accept configure the EPns. But when i try to do it i can't change them.

    JordiL_0-1709460883369.png

    Use same code with STM32F042 (but not config PA12/PA11 as alternate) and run properly.

    Any Idea?

     

    Explorer
    March 2, 2024
    Super User
    March 3, 2024

    > i can't change them [USB registers]

    Usually that means, that you don't have all the needed clocks running.

    JW

    JordiLAuthor
    Graduate
    March 3, 2024

    Thinks the same but theorically all clocks run as well

    JordiL_0-1709462482655.png

     

    Super User
    March 4, 2024

    What revision of the 'F373 do you have on the EVAL board?

    How do you clock it, exactly?

    Do you have some other hardware with the 'F373?

    Does the DFU bootloader work?

    JW

    JordiLAuthor
    Graduate
    March 4, 2024

    1-STM32F373VCT6

    2-External clock 8.0Mhz

    I create a project CubeIDE by board STM32373C-EVAL and usin default hardware config of the board and get same problem. Eps seems inhibed, can't not change with debug  (CubeIde) after MX_USB_PCD_Init function.

    Super User
    March 4, 2024

    I have no more ideas, sorry.

    You may want to contact ST directly, through FAE or the web support form, perhaps there giving link to this thread too.

    JW

    JordiLAuthor
    Graduate
    March 4, 2024

    Thnaks a lot

    Technical Moderator
    March 5, 2024

    Hello @JordiL 

    Could you please provide me with a light code, so I can reproduce this behavior. This will be helpful in identifying issues. 

    JordiLAuthor
    Graduate
    March 5, 2024

    Use STM32373C-EVAL board.

    Create New STM32 project with this board in CUBEIde.

    The CubeIDE then create a main.c code with all the Initializations.

    Set a Breakpoint in While(1) line in order to stop program and access to USB registers. 

    Normally after initialization of USB all registers are accessible. Via Debugg can modify ADDR but EPnRs can't modify.

    This code is directly generate by CUBEIDE, I only stop in while(1) line (in main() function) and check the USB registers.

     

    #include "main.h"

    ADC_HandleTypeDef hadc1;

    COMP_HandleTypeDef hcomp2;

    CEC_HandleTypeDef hcec;

    I2C_HandleTypeDef hi2c1;
    SMBUS_HandleTypeDef hsmbus2;

    I2S_HandleTypeDef hi2s1;

    SDADC_HandleTypeDef hsdadc1;
    SDADC_HandleTypeDef hsdadc2;

    SPI_HandleTypeDef hspi3;

    TSC_HandleTypeDef htsc;

    UART_HandleTypeDef huart2;

    PCD_HandleTypeDef hpcd_USB_FS;

    uint8_t cec_receive_buffer[16];

    int main(void)
    {

    SystemClock_Config();

    /* Initialize all configured peripherals */
    MX_GPIO_Init();
    MX_ADC1_Init();
    MX_COMP2_Init();
    MX_HDMI_CEC_Init();
    MX_I2C1_Init();
    MX_I2C2_SMBUS_Init();
    MX_I2S1_Init();
    MX_SDADC1_Init();
    MX_SDADC2_Init();
    MX_SPI3_Init();
    MX_TSC_Init();
    MX_USART2_UART_Init();
    MX_USB_PCD_Init();
    while (1)
    {

    }
    }

    Technical Moderator
    March 12, 2024

    Hi @JordiL 

    I'm sorry for not coming back sooner.

    USB buffer descriptors should start from 0x4000 6000 USB SRAM to access packet buffer memory.

    Could you access via memory view USB_EPnR region starting from 0x4000 5C00 and see if there is any signal of life?

    Super User
    March 12, 2024

    Hi @FBL ,

    Could you access via memory view USB_EPnR region starting from 0x4000 5C00 and see if there is any signal of life?

    As@JordiL wrote above, apparently no:

    Theorically, now USB is ready to accept configure the EPns. But when i try to do it i can't change them.

    Could the last remark - about the need of USB cable to be connected - indicate, that the PHY has to be powered externally?

    JW