Usb on STM32F466RC

General discussion on mikroC PRO for ARM.
Post Reply
Author
Message
SteveH
Posts: 36
Joined: 13 Mar 2008 23:10
Location: UK

Usb on STM32F466RC

#1 Post by SteveH » 23 Oct 2022 18:54

Hi all,

I'm trying to get the mikro usb lib working on a STM32F446RC chip that is built into a custom pcb acting as a full speed peripheral, self powered.

I'm using MikroC Pro for arm v6.2.0

I setup a basic bit of test code to try this out on various chips, it works fine on the STM32F415 (M4 module) and on the STM32F407 (Clicker2 module) with no problems.

Unfortunately the usb won't run on the 446 chip but all the other parts of the test code works so I know the clocks are ok.

I can't locate the setting for the usb 48MHz clock source but I have set both of the sources (PLL_Q and PLLSAI_P) to give 48MHz so should work either way.

I've got the usual usb pins connected (mini B connector) - PA11 = DN, PA12 = DP and PA9 = usb 5v detector via a voltage divider (5v -> 3.3v)

My config settings are :

Internal high-speed clock enable = OFF

External high-speed clock enable = ON

External high-speed clock bypass = not bypassed

Clock security system enable = OFF

Main PLL (PLL) enable = PLL ON

PLLI2S enable = PLLI2S OFF

PLLSAI enable = PLLSAI ON

Division factor for the main PLL (PLL) and audio PLL (PLLI2S) = PLL_M = 25 (xtal)

Main PLL (PLL) multiplication factor for VCO = PLL_N = 336

Main PLL (PLL) division factor for main system clock = PLL_P = 2

Main PLL (PLL) and audio PLL (PLLI2S) entry clock source = HSE

Main PLL (PLL) division factor for USB OTG FS, SDIO = PLL_Q = 7 (gives 48MHz to usb)

Main PLL (PLL) division factor for I2Ss, SAIs, SYSTEM and SPDII = PLL_R = 2

System clock switch = PLL_R

Set and cleared by software to control the division factor = not divided

APB low speed prescaler (APB1) = 4

APB high speed prescaler (APB2) = 2

HSE division factor for RTC clock = no clock

Microcontroller clock output 1 = PLL

MCO1 prescaler = no division

MCO2PRE = no division

Microcontroller clock output 2 = SYSCLK

Voltage range = 2.7 to 3.6 V

PLLSAI multiplication factor for VCO = 96

PLLSAI divison factor for 48 MHz clock = PLLSAI_P = 2 (gives 48MHz to usb)

PLLSAI divison factor for SAI1 clock = PLLSAI_Q = 2

PLLSAI divison factor for LCD clock = PLLSAI_R = 2


So, does anyone know if the mikro usb lib should work on the 446 (mikro please ?) and if anyone has actually succeeded in getting it working could you give me your configuration settings ?

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: Usb on STM32F466RC

#2 Post by filip » 26 Oct 2022 08:19

Hi,

I think this is an issue with the clock settings, maybe you can take a look at our USB HID examples in the compiler to see how we set it ?

Regards,
Filip.

SteveH
Posts: 36
Joined: 13 Mar 2008 23:10
Location: UK

Re: Usb on STM32F466RC

#3 Post by SteveH » 27 Oct 2022 23:10

Hi filip

It is most likely something to do with the clock settings, I made a custom hid project in ST Cube IDE which ran ok on my hardware but I would prefer to continue with Arm Pro C as it's easier to see the wood for the trees.

I used the clock settings from Cube IDE project in the mikro edit project but no luck. I think there may be something wrong in the original STM32F446RC.mlk def file (I've since changed this to add a PLLSAI M divisor option but still no luck)

Steve

kostral
Posts: 1
Joined: 06 Jun 2023 09:48

Re: Usb on STM32F466RC

#4 Post by kostral » 06 Jun 2023 13:28

Hi Steve,

Do you have any updates on this? I am encountering a similar issue with the USB Library on the STM32F405RG.
The initialization code gets stuck on USBDev_GetDeviceState(), and it returns _USB_DEV_STATE_DETACHED.

Below the code I am using for the initialization:

Code: Select all

GPIO_Alternate_Function_Enable(&_GPIO_MODULE_OTG_FS_PA89_10_11_12);
// Initialize CDC Class
USBDev_CDCInit();
// Initialize USB device module
USBDev_Init();
// Enable USB device interrupt
NVIC_IntEnable(IVT_INT_OTG_FS);
// Wait for the USB to be configured.  
while(USBDev_GetDeviceState() != _USB_DEV_STATE_CONFIGURED)
     {
     Delay_10ms();
     }
// Set receive buffer where received data is stored
USBDev_CDCSetReceiveBuffer(usb_buffer);
1 - I have already double-checked the USB clock settings, which are configured to 48MHz. Specifically, I am using an external oscillator at 12MHz with PLLM = 12, PLLN = 336, PLLP = 2 and PLLQ = 7.
2 - As in your case, I created a custom project in ST Cube IDE, which ran successfully on my hardware.

Post Reply

Return to “mikroC PRO for ARM General”