2016-12-16 05:23 AM
I've modified the DFU_Standalone application from the STM32Cube STM32746G-Discovery source and added support for external flash and ported it to our STM32F769I-Discovery board. It works fine if I use the USB_HS connector and configure it to use USB_OTG_HS.
On our target hardware I have only DATA-/+ available, so I have connected the DATA pins from the usb cable to the PA11 and PA12 pins and connected GND. Then configured the app to use
USB_OTG_FS with no VBUS sensing:
void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd)
{
GPIO_InitTypeDef GPIO_InitStruct;
if(hpcd->Instance == USB_OTG_FS)
{
/* Configure USB FS GPIOs */
__HAL_RCC_GPIOA_CLK_ENABLE();
/* Configure DM DP Pins */
GPIO_InitStruct.Pin = (GPIO_PIN_11 | GPIO_PIN_12);
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/* Enable USB FS Clock */
__HAL_RCC_USB_OTG_FS_CLK_ENABLE();
/* Set USBFS Interrupt priority */
HAL_NVIC_SetPriority(OTG_FS_IRQn, 7, 0);
/* Enable USBFS Interrupt */
HAL_NVIC_EnableIRQ(OTG_FS_IRQn);
}
}
USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev)
{
&sharpifdef USE_USB_FS
/* Set LL Driver parameters */
hpcd.Instance = USB_OTG_FS;
hpcd.Init.dev_endpoints = 6;
hpcd.Init.speed = PCD_SPEED_FULL;
hpcd.Init.dma_enable = DISABLE;
hpcd.Init.ep0_mps = DEP0CTL_MPS_64;
hpcd.Init.phy_itface = PCD_PHY_EMBEDDED;
hpcd.Init.Sof_enable = DISABLE;
hpcd.Init.low_power_enable = DISABLE;
hpcd.Init.lpm_enable = DISABLE;
hpcd.Init.vbus_sensing_enable = DISABLE;
hpcd.Init.use_dedicated_ep1 = DISABLE;
/* Link The driver to the stack */
hpcd.pData = pdev;
pdev->pData = &hpcd;
/* Initialize LL Driver */
if (HAL_PCD_Init(&hpcd) != HAL_OK)
{
extern void Error_Handler();
Error_Handler();
}
HAL_PCDEx_SetRxFiFo(&hpcd, 0x80);
HAL_PCDEx_SetTxFiFo(&hpcd, 0, 0x40);
HAL_PCDEx_SetTxFiFo(&hpcd, 1, 0x80);
&sharpendif
return USBD_OK;
}
But HAL_PCD_SetupStageCallback() is never called and my device just registers in Windows as 'Unknown Device'.
Any hints to what I might have missed?
Thanks!
/Thomas
#usb-dfu #usbdfubootloader #vbus #stm32f72016-12-16 06:36 AM
Coming from a STM32L4 world - PA1 looked a little unusual....Same in your part world.
PA12 maybe - Hopefully you just made a typo here
Outside of that, you might reveal if your target board is BUS POWERED or SELF POWERED
My guess would be SELF POWER because you say when you plug in, the PC says UnKnown Device so
my next guess would be you have the DP (or DM line for some reason) pulled up at that time. So PC sees SOMETHING.
Presumably PC tried to talk to it but didn't get an acceptable reply ?
USB device clock config?
2016-12-17 02:04 PM
Sorry, PA1 was a typo. It's PA11 and PA12 as in the code.
Right now I'm testing on a
STM32F769I-Discovery board so it's self powered. Both pins are configured as no-pull and and from the board schematics the pins are connected directly to the Arduino connectors with no pull ups.
void SystemClock_Config(void)
{
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
/* Enable HSE Oscillator and activate PLL with HSE as source */
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.HSIState = RCC_HSI_OFF;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLM = 25;
RCC_OscInitStruct.PLL.PLLN = 432;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
RCC_OscInitStruct.PLL.PLLQ = 9;
if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/* Activate the OverDrive to reach the 216 Mhz Frequency */
if(HAL_PWREx_EnableOverDrive() != HAL_OK)
{
Error_Handler();
}
/* Select PLLSAI output as USB clock source */
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_CLK48;
PeriphClkInitStruct.Clk48ClockSelection = RCC_CLK48SOURCE_PLLSAIP;
PeriphClkInitStruct.PLLSAI.PLLSAIN = 384;
PeriphClkInitStruct.PLLSAI.PLLSAIQ = 7;
PeriphClkInitStruct.PLLSAI.PLLSAIP = RCC_PLLSAIP_DIV8;
if(HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
{
Error_Handler();
}
/* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
clocks dividers */
RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
if(HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_7) != HAL_OK)
{
Error_Handler();
}
}
The
DFU_Standalone application is
using the STM32_USB_Device_Library. I get the HAL_PCD_ResetCallback which should mean that the speed negotiation was successful, but I don't get theHAL_PCD_SetupStageCallback.
Using the USB HS configuration from the DFU_Standalone app and HS connector on the Discovery board I get both.
Thanks!
2016-12-19 08:24 AM
I've came at this through an L4 door so some things are different with your micro. The clock tree being one of them and MAN are they different:
I'm guessing:
1. You have a 1Mhz HSE source?
2. Your Maxpacketsize has been set to the FS size? (64 - I've seem to remember seeing this complaint here in the forums before)
Thomas I'm pretty new to this family and the USB workings as well but I'm going to dump what I *think* I know out here and maybe it will help.
You say:
1. You ARE self powered
2. You are configured with NO ITERNAL PULL-UPS on the USB lines.
3. You have NO PULL UP'S on the PCB
4. You are not using Vbus sensing.
5. The PC notices *SOMETHING* plugged in and says Unknown device?' ( NO Pull ups so I ask HOW?)
Why do I ask HOW - ?
Things that I think l know.
1. The PC recognizes a USB device is plugged in by which USB line gets PULLED UP.
D+ = FULL SPEED / D- = LOW SPEED.
[ You have NEITHER of those according to the configuration details UNLESS your micro runs and pulls one of those lines up?]
2. Unless notified otherwise, your micro detects whether or not it is plugged into a HOST device (PC here) by either
a. BUS powered - As soon as it wakes up from boot and gathers its marbles, it yanks one of the USB line up. PC then recognizes there is SOMETHING there and tries to talk to it.
b. SELF POWERED - Your micro uses either the built in capability of Vbus sensing or some other method to detect a voltage arriving from the USB HOST source.
[ How does your micro know it got plugged into something - to presumably PULL UP a line? ]
Sorry it's ME adding questions but maybe something will pop out that's helpful.
2016-12-20 06:21 AM
The data +/- lines were switched. It's working now.
Thanks!
2016-12-20 06:23 AM
And then there's THAT... That would do it to :)
(BTDT)
Glad its working!