/** * @brief Configures the CEC peripheral. * @param None * @retval None */ static void CEC_Config(void) { CEC_InitTypeDef CEC_InitStruct; NVIC_InitTypeDef NVIC_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; /* DeInitialize CEC to reinitialize from scratch */ CEC_DeInit(); /* Enable CEC clocks */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_CEC, ENABLE); /* Enable CEC_LINE_GPIO clocks */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB,ENABLE); /* Configure CEC_LINE_GPIO as Output open drain */ GPIO_PinAFConfig(GPIOB, GPIO_PinSource6 , GPIO_AF3_CEC); GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_OD; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 ; GPIO_Init(GPIOB, &GPIO_InitStructure); /* Enable the CEC global Interrupt (with higher priority) */ NVIC_InitStructure.NVIC_IRQChannel = CEC_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /* Configure CEC */ CEC_InitStruct.CEC_SignalFreeTime = CEC_SignalFreeTime_Standard; CEC_InitStruct.CEC_RxTolerance = CEC_RxTolerance_Standard; CEC_InitStruct.CEC_StopReception = CEC_StopReception_Off; CEC_InitStruct.CEC_BitRisingError = CEC_BitRisingError_Off; CEC_InitStruct.CEC_LongBitPeriodError = CEC_LongBitPeriodError_Off; CEC_InitStruct.CEC_BRDNoGen = CEC_BRDNoGen_On; CEC_InitStruct.CEC_SFTOption = CEC_SFTOption_Off; CEC_Init(& CEC_InitStruct); /* Configure Own Address */ CEC_OwnAddressConfig(MyOwnAddress); /* Enable Listen Mode */ CEC_ListenModeCmd(ENABLE); /* Activate CEC interrupts associated to the set of TX flags */ CEC_ITConfig(CEC_IT_TXEND|CEC_IT_TXBR,ENABLE); /* Activate CEC interrupts associated to the set of RX flags */ CEC_ITConfig(CEC_IT_RXEND|CEC_IT_RXBR,ENABLE); /* Activate CEC interrupts associated to the set of TX error */ CEC_ITConfig(CEC_IT_TXACKE|CEC_IT_TXERR|CEC_IT_ARBLST,ENABLE); /* Activate CEC interrupts associated to the set of RX error */ CEC_ITConfig(CEC_IT_RXACKE|CEC_IT_LBPE|CEC_IT_SBPE|CEC_IT_BRE,ENABLE); /* Enable CEC */ CEC_Cmd(ENABLE); }
/** * @brief Configures the CEC peripheral. * @param None * @retval None */ static void CEC_Config(void) { CEC_InitTypeDef CEC_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; /* Enable CEC clocks */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_CEC , ENABLE); /* Enable CEC_LINE_GPIO clocks */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE); /* Configure CEC_LINE_GPIO as Output open drain */ #ifdef USE_STM320518_EVAL GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; #else GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; #endif /* USE_STM320518_EVAL */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_OD; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ; GPIO_Init(GPIOB, &GPIO_InitStructure); /* Enable the CEC global Interrupt (with higher priority) */ #ifdef USE_STM320518_EVAL NVIC_InitStructure.NVIC_IRQChannel = CEC_IRQn; #else NVIC_InitStructure.NVIC_IRQChannel = CEC_CAN_IRQn; #endif /* USE_STM320518_EVAL */ NVIC_InitStructure.NVIC_IRQChannelPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /* Configure CEC */ CEC_InitStructure.CEC_SignalFreeTime = CEC_SignalFreeTime_Standard; CEC_InitStructure.CEC_RxTolerance = CEC_RxTolerance_Standard; CEC_InitStructure.CEC_StopReception = CEC_StopReception_Off; CEC_InitStructure.CEC_BitRisingError = CEC_BitRisingError_Off; CEC_InitStructure.CEC_LongBitPeriodError = CEC_LongBitPeriodError_Off; CEC_InitStructure.CEC_BRDNoGen = CEC_BRDNoGen_Off; CEC_InitStructure.CEC_SFTOption = CEC_SFTOption_Off; CEC_Init(&CEC_InitStructure); /* Set the CEC initiator address */ CEC_OwnAddressConfig(MyLogicalAddress1); #if defined (DEVICE_3) /* Enable the listen mode for the Spy device */ CEC_ListenModeCmd(ENABLE); #endif /* DEVICE_3 */ /* Activate CEC interrupts associated to the set of TX flags */ CEC_ITConfig(CEC_IT_TXEND|CEC_IT_TXBR,ENABLE); /* Activate CEC interrupts associated to the set of RX flags */ CEC_ITConfig(CEC_IT_RXEND|CEC_IT_RXBR,ENABLE); /* Activate CEC interrupts associated to the set of TX error */ CEC_ITConfig(CEC_IT_TXACKE|CEC_IT_TXERR|CEC_IT_TXUDR|CEC_IT_ARBLST,ENABLE); /* Activate CEC interrupts associated to the set of RX error */ CEC_ITConfig(CEC_IT_RXACKE|CEC_IT_LBPE|CEC_IT_SBPE|CEC_IT_BRE|CEC_IT_RXOVR,ENABLE); /* Enable CEC */ CEC_Cmd(ENABLE); }