2013-10-23 08:22 AM
Hi all
I've a little problem. I use the USB driver from st to communicate with my STM32F4-Discovery. This works realy good. But I've would make a streaming protocol with a camera sensor. For this I have to use the MCO1. The parts works but in combination it won't do anything. So I searched for a reason. Then I've found something special in the driver library: The SOF overwrites the MCO1 configuration from PA8, but this pin isn't used for anything. If I remove the PA8 configuration for SOF output, the usb doesn't work correctly. So for what is this pin used? Is ist also used internal for something? Best regards Patrick2013-10-23 09:10 AM
It's connected internally to TIM2
Which VCP example are you using? Neither of these need to be defined USB_OTG_HS_SOF_OUTPUT_ENABLED USB_OTG_FS_SOF_OUTPUT_ENABLED > OTG_FS_GCCFG - SOFOUTEN Are you saying the GPIO_PinAFConfig(GPIOA, GPIO_PinSource8, GPIO_AF_MCO) setting doesn't stop SOF emanating from PA8?2013-10-23 09:31 AM
I can't say which example it is. I know the author: MCD application team.
The output-enalbe isn't defined so normaly there wouldn't be any output. But in the usb_bsp.c with the Port init function the SOF pin is configured as GPIO_AF_OTG1_FS.if
(DCMI_OV9655Config()){
// Enable DMA transfer
DMA_Cmd(DMA2_Stream1, ENABLE);
// Enable DCMI interface
DCMI_Cmd(ENABLE);
Delay_ms(100);
// Start Image capture
DCMI_CaptureCmd(ENABLE);
STM_EVAL_LEDOn(LED3);
}
USBD_Init(&USB_OTG_dev,
// OTG core handle
USB_OTG_FS_CORE_ID,
// OTG core id
&USR_desc,
// USB descriptors
&USBD_CDC_cb,
// CDC callback
&USR_cb);
// User callback
/* Configure SOF VBUS ID DM DP Pins */
/*
* Configure USB Pins
* SOF PA8 Start of frame
* VBUS_FS PA9 Vbus
* OTG_FS_ID PA10 ID
* OTG_FS_DM PA11 DM
* OTG_FS_DP PA12 DP
*
*/
GPIO_InitStructure.GPIO_Pin =
/*GPIO_Pin_8 | */
GPIO_Pin_9 | GPIO_Pin_11 | GPIO_Pin_12;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
GPIO_Init(GPIOA, &GPIO_InitStructure);
// GPIO_PinAFConfig(GPIOA,GPIO_PinSource8,GPIO_AF_OTG1_FS) ;
GPIO_PinAFConfig(GPIOA,GPIO_PinSource9,GPIO_AF_OTG1_FS) ;
GPIO_PinAFConfig(GPIOA,GPIO_PinSource11,GPIO_AF_OTG1_FS) ;
GPIO_PinAFConfig(GPIOA,GPIO_PinSource12,GPIO_AF_OTG1_FS) ;
/* this for ID line debug */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOA,GPIO_PinSource10,GPIO_AF_OTG1_FS) ;
The PA8 configuration for MCO1 output in DCMI init is overwritten from USB init, but the dont work together.
USB GPIO Init part: Uncomment PA8 configuration and the driver doesn't work
2013-10-23 10:12 AM
Seem to be able to emit 8 MHz via PA1/MCO1 without issue on my VCP build based on STM32_USB-Host-Device_Lib_V2.1.0\Project\USB_Device_Examples\VCP
2013-10-24 09:41 AM
I've found something spetial:
After the camera init (dcmi with dma) a hard-fault exception occours. But only if both are used (camera and vcp). Then I've checked core registers:r0 536950144
r1 536909696
r2 10
r3 58
r12 276959362
lr 0
pc 134220219
psr 134220184
The programm counter is locatet nearly USB_OTG_IsDeviceMode in usb_core.c (the address doesn't exist in my disassebly window). But there is something else:
The lr is 0. How could thes be?
2013-10-24 09:54 AM
The lr is 0. How could this be?
The DMA transfer nuked the stack?2013-10-24 10:56 AM
What could be the reason? Is the dma using the stack? And for what?
2013-10-24 11:53 AM
I know as much about your software as you've told me.
The DMA operates autonomously of the processor, if your video signal is being written over the stack, you could see odd values in registers, including LR. Why would you point it at the stack? Perhaps you don't think you are, but then again the data you are requesting is also very large and it's not inconceivable you could overwrite things if your buffers are too small, or programmed incorrectly into the DMA controller. Is your stack adequately sized? Again if you mess up the stack the processor context could well get fouled up.2013-10-25 08:25 AM
Here is the camera initialization:
volatile uint16_t DCMI_Buffer[160 * 120] = {0};
void DCMI_Config(void)
{
DCMI_InitTypeDef DCMI_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
DMA_InitTypeDef DMA_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
/* Enable DCMI GPIOs clocks */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB |
RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOE, ENABLE);
/* Connect DCMI pins to AF13 ************************************************/
GPIO_PinAFConfig(GPIOA, GPIO_PinSource4, GPIO_AF_DCMI);
// DCMI_HSYNC
GPIO_PinAFConfig(GPIOA, GPIO_PinSource6, GPIO_AF_DCMI);
// DCMI_PIXCK
GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_DCMI);
// DCMI_VSYNC
GPIO_PinAFConfig(GPIOC, GPIO_PinSource6, GPIO_AF_DCMI);
// DCMI_D0
GPIO_PinAFConfig(GPIOC, GPIO_PinSource7, GPIO_AF_DCMI);
// DCMI_D1
GPIO_PinAFConfig(GPIOC, GPIO_PinSource8, GPIO_AF_DCMI);
// DCMI_D2
GPIO_PinAFConfig(GPIOC, GPIO_PinSource9, GPIO_AF_DCMI);
// DCMI_D3
GPIO_PinAFConfig(GPIOC, GPIO_PinSource11, GPIO_AF_DCMI);
// DCMI_D4
GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_DCMI);
// DCMI_D5
GPIO_PinAFConfig(GPIOE, GPIO_PinSource5, GPIO_AF_DCMI);
// DCMI_D6
GPIO_PinAFConfig(GPIOE, GPIO_PinSource6, GPIO_AF_DCMI);
// DCMI_D7
/* DCMI GPIO configuration **************************************************/
/* HSYNC(PA4), PCLK(PA6) */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* VSYNC(PB7), D5(PB6) */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* D0(PC6), D1(PC7), D2(PC8), D3(PC9), D4(PC11) */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8
| GPIO_Pin_9 | GPIO_Pin_11;
GPIO_Init(GPIOC, &GPIO_InitStructure);
/* D6(PE5), D7(PE6) */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6;
GPIO_Init(GPIOE, &GPIO_InitStructure);
/* DCMI configuration *******************************************************/
/* Enable DCMI clock */
RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_DCMI, ENABLE);
// Reinitialize
DCMI_DeInit();
DCMI_InitStructure.DCMI_CaptureMode = DCMI_CaptureMode_Continuous;
DCMI_InitStructure.DCMI_SynchroMode = DCMI_SynchroMode_Hardware;
DCMI_InitStructure.DCMI_PCKPolarity = DCMI_PCKPolarity_Falling;
DCMI_InitStructure.DCMI_VSPolarity = DCMI_VSPolarity_High;
DCMI_InitStructure.DCMI_HSPolarity = DCMI_HSPolarity_High;
DCMI_InitStructure.DCMI_CaptureRate = DCMI_CaptureRate_All_Frame;
DCMI_InitStructure.DCMI_ExtendedDataMode = DCMI_ExtendedDataMode_8b;
DCMI_Init(&DCMI_InitStructure);
/* DCMI Interrupts config ***************************************************/
// DCMI_ITConfig(DCMI_IT_VSYNC, ENABLE);
// DCMI_ITConfig(DCMI_IT_LINE, ENABLE);
DCMI_ITConfig(DCMI_IT_FRAME, ENABLE);
// DCMI_ITConfig(DCMI_IT_ERR, ENABLE);
// DCMI_ITConfig(DCMI_IT_OVF, ENABLE);
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
NVIC_InitStructure.NVIC_IRQChannel = DCMI_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* Configures the DMA2 to transfer Data from DCMI to the LCD ****************/
/* Enable DMA2 clock */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE);
/* DMA2 Stream1 Configuration */
DMA_Cmd(DMA2_Stream1, DISABLE);
DMA_DeInit(DMA2_Stream1);
while
(DMA_GetCmdStatus(DMA2_Stream1) != DISABLE);
// Check if the DMA Stream is disabled before enabling it.
DMA_InitStructure.DMA_Channel = DMA_Channel_1;
DMA_InitStructure.DMA_PeripheralBaseAddr = DCMI_DR_ADDRESS;
DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)DCMI_Buffer;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
DMA_InitStructure.DMA_BufferSize = (160 * 120);
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Enable;
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_Full;
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
DMA_Init(DMA2_Stream1, &DMA_InitStructure);
}
void MCO1_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
// Enable GPIOs clocks
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
// Configure MCO (PA8)
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStructure);
RCC_MCO1Config(RCC_MCO1Source_HSI, RCC_MCO1Div_1);
}
the stack size is defined as following:
#define STACK_SIZE 0x00002000 /*!< Stack size (in Words)
I have no idea where the dma crashes the stack...
2013-10-25 08:26 AM
Could there be a problem with the usb interrupts or something else?