I have been trying to get a usb cdc example app up and running on the
stm32f103. My attempt has been adapted from the example at:


https://github.com/libopencm3/libopencm3-examples/blob/master/examples/stm32/f3/stm32f3-discovery/usb_cdcacm/cdcacm.c

with appropriate changes for the f103 initialization.

The problem is that it hangs very early in the usbd_init() routine. I
copied the libopencm3 file usb_f107.c into my local project directory and
instrumented it with some blink(x) calls to find the point of the hang:

/** Initialize the USB device controller hardware of the STM32. */
static usbd_device *stm32f107_usbd_init(void)
{
        rcc_periph_clock_enable(RCC_OTGFS);
        /* Control gets to here ok.. */
        blink(2);
        /* And then hangs here.. */
        OTG_FS_GUSBCFG |= OTG_GUSBCFG_PHYSEL;
        blink(3);
        /* Wait for AHB idle. */
        while (!(OTG_FS_GRSTCTL & OTG_GRSTCTL_AHBIDL));

The program starts up ok, and initializes a number of things before calling
usbd_init(). I get as far as the blink(2) call (above), but it hangs
thereafter. If I comment out the OTG_GUSBCFG_PHYSEL statement, it simply
hangs at the "Wait for AHB idle" loop.

I did a lot of guesswork for clock setup etc. so there is likely a lot more
here than is necessary:

int
main(void) {
        int x;
        usbd_device *usbd_dev;

        rcc_clock_setup_in_hse_8mhz_out_72mhz();
        rcc_set_usbpre(RCC_CFGR_USBPRE_PLL_CLK_DIV1_5); // 48 MHz

        rcc_periph_clock_enable(RCC_GPIOA);
        rcc_periph_clock_enable(RCC_GPIOC);
        rcc_periph_clock_enable(RCC_APB1ENR);           // Needed?
        rcc_periph_clock_enable(RCC_APB2ENR);           // Needed?
        rcc_periph_clock_enable(RCC_APB2ENR_AFIOEN);    // Needed?
        rcc_periph_clock_enable(RCC_AHBENR_OTGFSEN);
        rcc_periph_clock_enable(RCC_AHBENR_CRCEN);

        rcc_periph_clock_enable(RCC_CRC);
        rcc_periph_clock_enable(RCC_USB);

        gpio_set_mode(GPIOA
,GPIO_MODE_OUTPUT_50_MHZ,GPIO_CNF_OUTPUT_PUSHPULL,GPIO11);

gpio_set_mode(GPIOA,GPIO_MODE_OUTPUT_50_MHZ,GPIO_CNF_OUTPUT_PUSHPULL,GPIO12
);


gpio_set_mode(GPIOC,GPIO_MODE_OUTPUT_2_MHZ,GPIO_CNF_OUTPUT_PUSHPULL,GPIO13);
// LED

        blink(5);
        led(1); /* ok so far.. */

        usbd_dev = usbd_init(&stm32f107_usb_driver,&dev,&config,
                usb_strings,3,
                usbd_control_buffer,sizeof(usbd_control_buffer));

        /* Control never comes back here.. */
        blink(3);

The fact that it hangs suggests maybe that I am leaving a clock disabled.

The few examples that I did find did barely performed any setup and purport
to have a working example (or at least for that time). Hopefully someone
can point out some obvious problem. I'm running out of ideas.

The full source code is here:

   https://github.com/ve3wwg/stm32f103c8t6

in subdirectory rtos/usb1.  While this project is built as a FreeRTOS
program, it is not using any task scheduling etc. at this time.

Just type "make" at the ./rtos/usb1 level to build it (it does however
require that the libopencm3 project be available and built at top-level
./libopencm3 however).

Thanks, Warren
------------------------------------------------------------------------------
Announcing the Oxford Dictionaries API! The API offers world-renowned
dictionary content that is easy and intuitive to access. Sign up for an
account today to start using our lexical data to power your apps and
projects. Get started today and enter our developer competition.
http://sdm.link/oxford
_______________________________________________
libopencm3-devel mailing list
libopencm3-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libopencm3-devel

Reply via email to