/** * @brief Config UART for Camera Communication * @param * @param * @retval */ void UART_CAM_Config(void) { UART_Config(CAM_COMM, 115200); /* Ring Buff */ RINGBUF_Init(&uartCAM_RxRingBuff, uartCAM_RxBuff, sizeof(uartCAM_RxBuff)); }
/** * Description: This function performs all necessary initializations on the UART. * Arguments : baud_rate The desired baud rate for the UART * Returns : None */ void UART_Init (void) { int i; //initialisation des tableaux for(i=0; i<CIRCULAR_BUFFER_SIZE-1; i++) { Uart_Rx_Circular_Buffer[i] = 0; } UART_Config(BSP_BAUD_RATE); UART_IntEn(); //Concerne la transmission uart UART_Transmit_InitDma(); UART_Transmit_InitialiseFrame(); }
/******************************************************************************* Function name: Decription: Input: None Output: None *******************************************************************************/ void SIM900_Init(uint32_t baud) { GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE); #ifdef SIM_USE_KEY RCC_APB2PeriphClockCmd(SIM_KEY_RCC, ENABLE); GPIO_InitStructure.GPIO_Pin = SIM_KEY_Pin; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(SIM_KEY_Port, &GPIO_InitStructure); #endif #ifdef SIM_USE_RST RCC_APB2PeriphClockCmd(SIM_RST_RCC, ENABLE); GPIO_InitStructure.GPIO_Pin = SIM_RST_Pin; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(SIM_RST_Port, &GPIO_InitStructure); #endif #ifdef SIM_USE_RI RCC_APB2PeriphClockCmd(SIM_RI_RCC, ENABLE); GPIO_InitStructure.GPIO_Pin = SIM_RI_Pin; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(SIM_RI_Port, &GPIO_InitStructure); #endif #ifdef SIM_USE_STT RCC_APB2PeriphClockCmd(SIM_STT_RCC, ENABLE); GPIO_InitStructure.GPIO_Pin = SIM_STT_Pin; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(SIM_STT_Port, &GPIO_InitStructure); #endif SIM_RST_HIGH; // Config UART UART_Config(SIM_COMM, baud); /*Ring Buff*/ RINGBUF_Init(&UART1_RxRingBuff, UART1_RxBuff, sizeof(UART1_RxBuff)); }
/* * See the serial2.h header file. */ xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength ) { xComPortHandle xReturn; /* Create the queues used to hold Rx and Tx characters. */ xRxedChars = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed char ) ); xCharsForTx = xQueueCreate( uxQueueLength + 1, ( unsigned portBASE_TYPE ) sizeof( signed char ) ); /* If the queues were created correctly then setup the serial port hardware. */ if( ( xRxedChars != serINVALID_QUEUE ) && ( xCharsForTx != serINVALID_QUEUE ) ) { portENTER_CRITICAL(); { /* Setup the UART port pins. */ GPIO_Config( GPIO0, UART0_Tx_Pin, GPIO_AF_PP ); GPIO_Config( GPIO0, UART0_Rx_Pin, GPIO_IN_TRI_CMOS ); /* Configure the UART. */ UART_OnOffConfig( UART0, ENABLE ); UART_FifoConfig( UART0, DISABLE ); UART_FifoReset( UART0, UART_RxFIFO ); UART_FifoReset( UART0, UART_TxFIFO ); UART_LoopBackConfig(UART0, DISABLE ); UART_Config( UART0, ulWantedBaud, UART_NO_PARITY, UART_1_StopBits, UARTM_8D ); UART_RxConfig( UART0, ENABLE ); /* Configure the IEC for the UART interrupts. */ EIC_IRQChannelPriorityConfig( UART0_IRQChannel, 1 ); EIC_IRQChannelConfig( UART0_IRQChannel, ENABLE ); EIC_IRQConfig( ENABLE ); UART_ItConfig( UART0, UART_RxBufFull, ENABLE ); } portEXIT_CRITICAL(); } else { xReturn = ( xComPortHandle ) 0; } /* This demo file only supports a single port but we have to return something to comply with the standard demo header file. */ return xReturn; }
/** * @brief Main program. * @param None * @retval None */ void main(void) { static u16 i=0; CLK_Config(); UART_Config(); TIM2_Config(); enableInterrupts(); printF("TIM2_Config finish !\n",FALSE,0); /* Infinite loop */ while (1) { _Delay(100); printF("LOG MSG (%4d) !\n",TRUE,i++); } }
/** * @brief Main program. * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f0xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f0xx.c file */ RCC_Config(); NVIC_Config(); GPIO_Config(); UART_Config(); while (1) { //USART_SendByte('0'); asm("nop"); } }
/*********************************************************************//** * @brief Initial System Init using Port and Peripheral * @param[in] None * @return None **********************************************************************/ void System_Init(void) { LPC_WDT->WDMOD &= ~WDT_WDMOD_WDEN; // Disable Watchdog SystemInit(); // Initialize system and update core clock Port_Init(); // Port Initialization SYSTICK_Config(); // Systick Initialization led_delay = 1000; // Heart Beat rate of 1Sec toggle NVIC_SetPriority(SysTick_IRQn, 0); // Set SysTick as Highest Priority UART_Config(LPC_UART0, 115200); // Uart0 Initialize at 9600 Baud Rate SSP_Config (LPC_SSP1); // Initialize SPI I2C_Config (LPC_I2C0); // Initialize I2C0 GLCD_Init(); // Initialize GLCD GPIO_IntCmd(2,_BIT(7),1); // Enable GPIO Interrupt at P0.19 Falling Edge NVIC_EnableIRQ(EINT3_IRQn); // NVIC Interrupt EINT3_IRQn for GPIO NVIC_SetPriority(EINT3_IRQn, 4); // Set any lower Priority than SysTick TSC2004_Cal_Init(&cmatrix); }
int main(void) { RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); Delay_Config(); GPIO_Config(); UART_Config(); ENC_Config(); USART_Cmd(USART1, ENABLE); TIM_Cmd(TIM3, ENABLE); uint16_t count = 0; TIM3->CNT = 0; count = TIM3->CNT; while(1) { //if(count != TIM3->CNT) { USART_putc(USART1, count&0x00FF); USART_putc(USART1, (count&0xFF00)>>8); USART_putc(USART1, '\n'); count = TIM3->CNT; } GPIO_ToggleBits(GPIOC, GPIO_Pin_13|GPIO_Pin_9); delay_ms(50); /* //Delay(0x7FFFFF); GPIO_ResetBits(GPIOC, GPIO_Pin_13|GPIO_Pin_9); //Delay(0x7FFFFF); delay_ms(500); USART_putc(USART1, TIM3->CNT); USART_putc(USART1, '\n'); */ } }
int main(void) { HAL_Init(); SystemClock_Config(); RCC_Config(); GPIO_Config(); UART_Config(); if (SysTick_Config(SystemCoreClock / 1000)) { error_handler(); } log_init(LOGLEVEL_INFO); log_info("PROJECT STERTED"); while (1) { led_toggle(LED_BLUE); log_info("Hello! :)"); HAL_Delay(DELAY); } }
int main(void) { //uint16_t kezdet, vege; vSemaphoreCreateBinary(xADCSemaphore); RCC_Config(); IO_Init(); UART_Config(); PWM_Config(); DMA_Config(); I2C_Config(); NVIC_Config(); DebugTimerInit(); xTaskCreate(prvInitTask,(signed char*)"INIT", configMINIMAL_STACK_SIZE,NULL,TASK_INIT_PRIORITY,NULL); vTaskStartScheduler(); while (1) { } }
/** * @brief Main program * @param None * @retval None */ int main(void) { /* STM32F103xG HAL library initialization: - Configure the Flash prefetch - Systick timer is configured by default as source of time base, but user can eventually implement his proper time base source (a general purpose timer for example or other time source), keeping in mind that Time base duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and handled in milliseconds basis. - Set NVIC Group Priority to 4 - Low Level Initialization */ HAL_Init(); /* Configure the system clock to 72 MHz */ SystemClock_Config(); /* Initialize LEDs *************************/ BSP_LED_Init(LED1); BSP_LED_Init(LED2); BSP_LED_Init(LED3); BSP_LED_Init(LED4); #if defined(HAL_UART_MODULE_ENABLED) UART_Config(); #endif /* HAL_UART_MODULE_ENABLED */ SC_State SCState = SC_POWER_OFF; /* Configure Smartcard Interface GPIO pins */ SC_IOConfig(); /*-------------------------------- Idle task ---------------------------------*/ while(1) { #if defined(HAL_UART_MODULE_ENABLED) printf("-- Waiting for card insertion -- (LED1 blinking) \n\r"); #endif /* HAL_UART_MODULE_ENABLED */ /* Loop while no Smartcard is detected */ while(CardInserted == 0) { BSP_LED_Toggle(LED1); HAL_Delay(200); } BSP_LED_On(LED1); /* Start SC Demo ---------------------------------------------------------*/ #if defined(HAL_UART_MODULE_ENABLED) printf("-- Card inserted -- (All LEDs On) \n\r"); #endif /* HAL_UART_MODULE_ENABLED */ /* Wait A2R --------------------------------------------------------------*/ SCState = SC_POWER_ON; SC_ADPU.Header.CLA = 0x00; SC_ADPU.Header.INS = SC_GET_A2R; SC_ADPU.Header.P1 = 0x00; SC_ADPU.Header.P2 = 0x00; SC_ADPU.Body.LC = 0x00; while(SCState != SC_ACTIVE_ON_T0) { SC_Handler(&SCState, &SC_ADPU, &SC_Response); } #if defined(HAL_UART_MODULE_ENABLED) printf("-- Card powered ON : ATR received -- \n\r"); #endif /* HAL_UART_MODULE_ENABLED */ /* Apply the Procedure Type Selection (PTS) */ SC_PTSConfig(); #if defined(HAL_UART_MODULE_ENABLED) printf("-- PTS procedure performed -- \n\r"); #endif /* HAL_UART_MODULE_ENABLED */ /* Inserts delay(400ms) for Smartcard clock resynchronisation */ HAL_Delay(400); /* Select MF -------------------------------------------------------------*/ SC_ADPU.Header.CLA = SC_CLA_GSM11; SC_ADPU.Header.INS = SC_SELECT_FILE; SC_ADPU.Header.P1 = 0x00; SC_ADPU.Header.P2 = 0x00; SC_ADPU.Body.LC = 0x02; for(i = 0; i < SC_ADPU.Body.LC; i++) { SC_ADPU.Body.Data[i] = MasterRoot[i]; } while(i < LC_MAX) { SC_ADPU.Body.Data[i++] = 0; } SC_ADPU.Body.LE = 0; SC_Handler(&SCState, &SC_ADPU, &SC_Response); #if defined(HAL_UART_MODULE_ENABLED) printf("-- ### SELECT MF ### \n\r"); #endif /* HAL_UART_MODULE_ENABLED */ /* Get Response on MF ----------------------------------------------------*/ if(SC_Response.SW1 == SC_DF_SELECTED) { SC_ADPU.Header.CLA = SC_CLA_GSM11; SC_ADPU.Header.INS = SC_GET_RESPONCE; SC_ADPU.Header.P1 = 0x00; SC_ADPU.Header.P2 = 0x00; SC_ADPU.Body.LC = 0x00; SC_ADPU.Body.LE = SC_Response.SW2; SC_Handler(&SCState, &SC_ADPU, &SC_Response); } #if defined(HAL_UART_MODULE_ENABLED) printf("-- ### GET RESPONSE ### \n\r"); #endif /* HAL_UART_MODULE_ENABLED */ /* Select ICCID ----------------------------------------------------------*/ if(((SC_Response.SW1 << 8) | (SC_Response.SW2)) == SC_OP_TERMINATED) { /* Check if the CHV1 is enabled */ if((SC_Response.Data[13] & 0x80) == 0x00) { CHV1Status = 0x01; #if defined(HAL_UART_MODULE_ENABLED) printf("-- CHV1 is enabled -- \n\r"); #endif /* HAL_UART_MODULE_ENABLED */ } else { #if defined(HAL_UART_MODULE_ENABLED) printf("-- CHV1 is disabled -- \n\r"); #endif /* HAL_UART_MODULE_ENABLED */ } /* Send APDU Command for ICCID selection */ SC_ADPU.Header.CLA = SC_CLA_GSM11; SC_ADPU.Header.INS = SC_SELECT_FILE; SC_ADPU.Header.P1 = 0x00; SC_ADPU.Header.P2 = 0x00; SC_ADPU.Body.LC = 0x02; for(i = 0; i < SC_ADPU.Body.LC; i++) { SC_ADPU.Body.Data[i] = ICCID[i]; } while(i < LC_MAX) { SC_ADPU.Body.Data[i++] = 0; } SC_ADPU.Body.LE = 0; SC_Handler(&SCState, &SC_ADPU, &SC_Response); #if defined(HAL_UART_MODULE_ENABLED) printf("-- ### SELECT EF ICCID ### \n\r"); #endif /* HAL_UART_MODULE_ENABLED */ } /* Read Binary in ICCID --------------------------------------------------*/ if(SC_Response.SW1 == SC_EF_SELECTED) { SC_ADPU.Header.CLA = SC_CLA_GSM11; SC_ADPU.Header.INS = SC_READ_BINARY; SC_ADPU.Header.P1 = 0x00; SC_ADPU.Header.P2 = 0x00; SC_ADPU.Body.LC = 0x00; SC_ADPU.Body.LE = 10; SC_Handler(&SCState, &SC_ADPU, &SC_Response); } #if defined(HAL_UART_MODULE_ENABLED) printf("-- ### READ BINARY (ICCID) ### \n\r"); #endif /* HAL_UART_MODULE_ENABLED */ /* Select GSMDir ---------------------------------------------------------*/ if(((SC_Response.SW1 << 8) | (SC_Response.SW2)) == SC_OP_TERMINATED) { /* Copy the ICCID File content into ICCID_Content buffer */ for(i = 0; i < SC_ADPU.Body.LE; i++) { ICCID_Content[i] = SC_Response.Data[i]; } #if defined(HAL_UART_MODULE_ENABLED) printf("-- ICCID Value = "); for(i = 0; i < SC_ADPU.Body.LE; i++) { printf("%x ",ICCID_Content[i]); } printf("\n\r"); #endif /* HAL_UART_MODULE_ENABLED */ /* Send APDU Command for GSMDir selection */ SC_ADPU.Header.CLA = SC_CLA_GSM11; SC_ADPU.Header.INS = SC_SELECT_FILE; SC_ADPU.Header.P1 = 0x00; SC_ADPU.Header.P2 = 0x00; SC_ADPU.Body.LC = 0x02; for(i = 0; i < SC_ADPU.Body.LC; i++) { SC_ADPU.Body.Data[i] = GSMDir[i]; } while(i < LC_MAX) { SC_ADPU.Body.Data[i++] = 0; } SC_ADPU.Body.LE = 0; SC_Handler(&SCState, &SC_ADPU, &SC_Response); #if defined(HAL_UART_MODULE_ENABLED) printf("-- ### SELECT DF GSM ### \n\r"); #endif /* HAL_UART_MODULE_ENABLED */ } /* Select IMSI -----------------------------------------------------------*/ if(SC_Response.SW1 == SC_DF_SELECTED) { SC_ADPU.Header.CLA = SC_CLA_GSM11; SC_ADPU.Header.INS = SC_SELECT_FILE; SC_ADPU.Header.P1 = 0x00; SC_ADPU.Header.P2 = 0x00; SC_ADPU.Body.LC = 0x02; for(i = 0; i < SC_ADPU.Body.LC; i++) { SC_ADPU.Body.Data[i] = IMSI[i]; } while(i < LC_MAX) { SC_ADPU.Body.Data[i++] = 0; } SC_ADPU.Body.LE = 0; SC_Handler(&SCState, &SC_ADPU, &SC_Response); #if defined(HAL_UART_MODULE_ENABLED) printf("-- ### SELECT EF IMSI ### \n\r"); #endif /* HAL_UART_MODULE_ENABLED */ } /* Get Response on IMSI File ---------------------------------------------*/ if(SC_Response.SW1 == SC_EF_SELECTED) { SC_ADPU.Header.CLA = SC_CLA_GSM11; SC_ADPU.Header.INS = SC_GET_RESPONCE; SC_ADPU.Header.P1 = 0x00; SC_ADPU.Header.P2 = 0x00; SC_ADPU.Body.LC = 0x00; SC_ADPU.Body.LE = SC_Response.SW2; SC_Handler(&SCState, &SC_ADPU, &SC_Response); } /* Read Binary in IMSI ---------------------------------------------------*/ if(CHV1Status == 0x00) { if(((SC_Response.SW1 << 8) | (SC_Response.SW2)) == SC_OP_TERMINATED) { /* Enable CHV1 (PIN1) ------------------------------------------------*/ /* CHV1 enabling should be done using proper value of used card CHV1 */ /* Please fill corresponding value in CHV1[array] . Current value is set to "00000000". */ /* SC_ADPU.Header.CLA = SC_CLA_GSM11; SC_ADPU.Header.INS = SC_ENABLE; SC_ADPU.Header.P1 = 0x00; SC_ADPU.Header.P2 = 0x01; SC_ADPU.Body.LC = 0x04; for(i = 0; i < SC_ADPU.Body.LC; i++) { SC_ADPU.Body.Data[i] = CHV1[i]; } while(i < LC_MAX) { SC_ADPU.Body.Data[i++] = 0; } SC_ADPU.Body.LE = 0; SC_Handler(&SCState, &SC_ADPU, &SC_Response); */ #if defined(HAL_UART_MODULE_ENABLED) /* printf("-- ### CHV1 ENABLE ### \n\r"); */ #endif /* HAL_UART_MODULE_ENABLED */ } } else { if(((SC_Response.SW1 << 8) | (SC_Response.SW2)) == SC_OP_TERMINATED) { /* Verify CHV1 (PIN1) ------------------------------------------------*/ /* CHV1 enabling should be done using proper value of used card CHV1 */ /* Please fill corresponding value in CHV1[array] . Current value is set to "00000000". */ SC_ADPU.Header.CLA = SC_CLA_GSM11; SC_ADPU.Header.INS = SC_VERIFY; SC_ADPU.Header.P1 = 0x00; SC_ADPU.Header.P2 = 0x01; SC_ADPU.Body.LC = 0x08; for(i = 0; i < SC_ADPU.Body.LC; i++) { SC_ADPU.Body.Data[i] = CHV1[i]; } while(i < LC_MAX) { SC_ADPU.Body.Data[i++] = 0; } SC_ADPU.Body.LE = 0; SC_Handler(&SCState, &SC_ADPU, &SC_Response); #if defined(HAL_UART_MODULE_ENABLED) printf("-- ### CHV1 VERIFY ### \n\r"); #endif /* HAL_UART_MODULE_ENABLED */ } } /* Read Binary in IMSI ---------------------------------------------------*/ if(((SC_Response.SW1 << 8) | (SC_Response.SW2)) == SC_OP_TERMINATED) { #if defined(HAL_UART_MODULE_ENABLED) printf("-- ### CHV1 Operation successfull ### \n\r"); #endif /* HAL_UART_MODULE_ENABLED */ SC_ADPU.Header.CLA = SC_CLA_GSM11; SC_ADPU.Header.INS = SC_READ_BINARY; SC_ADPU.Header.P1 = 0x00; SC_ADPU.Header.P2 = 0x00; SC_ADPU.Body.LC = 0x00; SC_ADPU.Body.LE = 9; SC_Handler(&SCState, &SC_ADPU, &SC_Response); } else { #if defined(HAL_UART_MODULE_ENABLED) printf("-- ### CHV1 Operation unsuccessfull : SW1/SW2=0x%4x ### \n\r", ((SC_Response.SW1 << 8) | (SC_Response.SW2))); #endif /* HAL_UART_MODULE_ENABLED */ } #if defined(HAL_UART_MODULE_ENABLED) printf("-- ### READ BINARY (IMSI) ### \n\r"); #endif /* HAL_UART_MODULE_ENABLED */ if(((SC_Response.SW1 << 8) | (SC_Response.SW2)) == SC_OP_TERMINATED) { /* Copy the IMSI File content into IMSI_Content buffer */ for(i = 0; i < SC_ADPU.Body.LE; i++) { IMSI_Content[i] = SC_Response.Data[i]; } } #if defined(HAL_UART_MODULE_ENABLED) printf("-- IMSI Value = "); for(i = 0; i < SC_ADPU.Body.LE; i++) { printf("%x ",IMSI_Content[i]); } printf("\n\r"); #endif /* HAL_UART_MODULE_ENABLED */ /* Disable the Smartcard interface */ SCState = SC_POWER_OFF; SC_Handler(&SCState, &SC_ADPU, &SC_Response); #if defined(HAL_UART_MODULE_ENABLED) printf("-- Card powered OFF -- \n\r"); #endif /* HAL_UART_MODULE_ENABLED */ #if defined(HAL_UART_MODULE_ENABLED) printf("-- Waiting for card removal -- (LED1 blinking) \n\r"); #endif /* HAL_UART_MODULE_ENABLED */ /* Loop while a Smartcard is detected */ while(CardInserted == 1) { BSP_LED_Toggle(LED1); HAL_Delay(200); } BSP_LED_Off(LED1); } }
sio_fd_t sio_open_new( u8_t devnr, u32_t baudrate, u8_t databits, sio_stop_t stopbits, sio_parity_t parity ) { int i; err_t error = ERR_OK; serdev_t *dev; UARTParity_TypeDef eUARTParity = UART_NO_PARITY; UARTMode_TypeDef eUARTMode = UARTM_8D; UARTStopBits_TypeDef eUARTStopBits; if( !initialized ) { for( i = 0; i < UART_DEVICES_MAX; i++ ) { SIO_RESET_STATE( &devices[i] ); } initialized = 1; } /* Check if devicename is valid and not in use. */ if( ( devnr < UART_DEVICES_MAX ) && ( devices[devnr].ready == 0 ) ) { dev = ( serdev_t * ) & devices[devnr]; switch ( parity ) { case SIO_PAR_EVEN: eUARTParity = UART_EVEN_PARITY; break; case SIO_PAR_ODD: eUARTParity = UART_ODD_PARITY; break; case SIO_PAR_NONE: eUARTParity = UART_NO_PARITY; break; default: error = ERR_VAL; } switch ( databits ) { case 7: if( parity != SIO_PAR_NONE ) { eUARTMode = UARTM_7D_P; } break; case 8: eUARTMode = parity == SIO_PAR_NONE ? UARTM_8D : UARTM_8D_P; break; default: error = ERR_VAL; } switch ( stopbits ) { case SIO_STOP_0_5: eUARTStopBits = UART_0_5_StopBits; break; case SIO_STOP_1: eUARTStopBits = UART_1_StopBits; break; case SIO_STOP_1_5: eUARTStopBits = UART_1_5_StopBits; break; case SIO_STOP_2: eUARTStopBits = UART_2_StopBits; break; default: error = ERR_VAL; } if( error == ERR_OK ) { SIO_RESET_STATE( dev ); vSemaphoreCreateBinary( dev->rx_sem ); vSemaphoreCreateBinary( dev->tx_sem ); vPortEnterCritical( ); if( ( error = sio_open_low_level( devnr, dev ) ) != ERR_OK ) { /* Hardware interface does not exist. */ } else if( dev->tx_sem == ( xSemaphoreHandle ) 0 ) { error = ERR_MEM; } else if( dev->rx_sem == ( xSemaphoreHandle ) 0 ) { error = ERR_MEM; } else { /* UART parameter correct and hardware device available. */ UART_OnOffConfig( dev->UARTx, ENABLE ); UART_FifoConfig( dev->UARTx, ENABLE ); UART_FifoReset( dev->UARTx, UART_RxFIFO ); UART_FifoReset( dev->UARTx, UART_TxFIFO ); UART_LoopBackConfig( dev->UARTx, DISABLE ); UART_Config( dev->UARTx, baudrate, eUARTParity, eUARTStopBits, eUARTMode ); UART_TimeOutPeriodConfig( dev->UARTx, 0xFF ); UART_ItConfig( dev->UARTx, UART_RxBufFull, ENABLE ); UART_RxConfig( dev->UARTx, ENABLE ); /* Device is now ready for use. */ dev->ready = 1; } if( error != ERR_OK ) { sio_close( dev ); } vPortExitCritical( ); } } else { error = ERR_VAL; } return error == ERR_OK ? ( void * )dev : SIO_FD_NULL; }
BOOL xMBPortSerialInit( UCHAR ucPort, ULONG ulBaudRate, UCHAR ucDataBits, eMBParity eParity ) { BOOL xResult = TRUE; UARTParity_TypeDef eUARTParity; UARTMode_TypeDef eUARTMode; (void)ucPort; switch ( eParity ) { case MB_PAR_EVEN: eUARTParity = UART_EVEN_PARITY; break; case MB_PAR_ODD: eUARTParity = UART_ODD_PARITY; break; case MB_PAR_NONE: eUARTParity = UART_NO_PARITY; break; } switch ( ucDataBits ) { case 7: if( eParity == MB_PAR_NONE ) { /* not supported by our hardware. */ xResult = FALSE; } else { eUARTMode = UARTM_7D_P; } break; case 8: if( eParity == MB_PAR_NONE ) { eUARTMode = UARTM_8D; } else { eUARTMode = UARTM_8D_P; } break; default: xResult = FALSE; } if( xResult != FALSE ) { /* Setup the UART port pins. */ GPIO_Config( MB_UART_TX_PORT, 1 << MB_UART_TX_PIN, GPIO_AF_PP ); GPIO_Config( MB_UART_RX_PORT, 1 << MB_UART_RX_PIN, GPIO_IN_TRI_CMOS ); /* Configure the UART. */ UART_OnOffConfig( MB_UART_DEV, ENABLE ); UART_FifoConfig( MB_UART_DEV, DISABLE ); UART_FifoReset( MB_UART_DEV, UART_RxFIFO ); UART_FifoReset( MB_UART_DEV, UART_TxFIFO ); UART_LoopBackConfig( MB_UART_DEV, DISABLE ); UART_Config( MB_UART_DEV, ulBaudRate, eUARTParity, UART_1_StopBits, eUARTMode ); UART_RxConfig( UART0, ENABLE ); vMBPortSerialEnable( FALSE, FALSE ); /* Configure the IEC for the UART interrupts. */ EIC_IRQChannelPriorityConfig( MB_UART_IRQ_CH, MB_IRQ_PRIORITY ); EIC_IRQChannelConfig( MB_UART_IRQ_CH, ENABLE ); } return xResult; }
void UART_Init (void) { UART_Config(BSP_BAUD_RATE); UART_IntEn(); }
int main( void ) { uart_config_t uart0; gpio_config_t key1; i2c_config_t i2c0; i2c_command_t command; spi_config_t spi0; spi_command_t spi_cmd; adc_config_t adc5; dac_config_t dac0; error_code_t error; uart0.baudrate = B115200; uart0.block_type = NON_BLOCKING; uart0.buffer = 0; uart0.irqhandler = 0; uart0.parity = UART_PARITY_NONE; uart0.uart_port = COM0; uart0.wordlen = UART_WORDLEN8; uart0.stopbit = STOP_BIT_1_BIT; key1.Direction = INPUT; key1.Initial_Value = LO; key1.Interrupt_Type = INTERRUPT_ENABLED_BOTH; key1.Pin = PIN11; key1.Port= PORT2; key1.Pin_Mode = PULLUP_PULLDOWN_DISABLED; key1.Pin_Mode_OD = PIN_MODE_OPEN_DRAIN_NORMAL; key1.Pin_Typedef = 0; key1.irqhandler = 0; i2c0.i2c_port = I2C0; i2c0.i2c_mode = MASTER; i2c0.datarate = STANDARD; i2c0.buffer = 0; i2c0.irqhandler = 0; spi0.bits = SPI_8_BITS; spi0.buffer = 0; spi0.clk_phase = SPI_PHASE_INPHASE; spi0.clk_polarity = SPI_CLK_RISING; spi0.freq = 5e6; spi0.irqhandler = 0; spi0.lsbf = MSB_FIRST; spi0.mode = SPI_MASTER; spi0.port = SPI0; spi0.dummyData = 0x00; adc5.channel = ADC_CHANNEL5; adc5.rate = 200e3; adc5.trigger_mode = BURST; adc5.irqhandler = 0; dac0.sampling_rate = 32e3; if ( (error = GPIO_Config(&key1)) != NO_ERROR ) { while (1); } signal_level_t trigger_mode; GPIO_GetLevel(&key1, &trigger_mode); if (trigger_mode == HI) { adc5.trigger_mode = BURST; } else { adc5.trigger_mode = MANUAL; } if ( (error = UART_Config(&uart0)) != NO_ERROR) { while (1); } SetDebug_Port(COM0); if ( (error = I2C_Config(&i2c0)) != NO_ERROR ) { while (1); } if ( (error = SPI_Config(&spi0)) != NO_ERROR ) { while (1); } if ( (error = ADC_Config(&adc5)) != NO_ERROR ) { while (1); } if ( (error = DAC_Config(&dac0)) != NO_ERROR ) { while (1); } uc_printf ("HardWare Initialized\n\r"); /* READ ID USING READ-ID */ //Write Register. spi_cmd.writeReg = 0x90; spi_cmd.writeRegValid = 1; uint16_t write_data[] = {0x00, 0x00, 0x00 }; spi_cmd.writeBuffer = write_data; spi_cmd.writeDataSize = sizeof(write_data); //Read Register. uint16_t read_data[4]; spi_cmd.readReg = 0x00; spi_cmd.readRegValid = 0; spi_cmd.readBuffer = read_data; spi_cmd.readDataSize = sizeof(read_data); spi_cmd.operation = SPI_WRITE | SPI_READ; //back to back. error = SPI_Write(SPI0, &spi_cmd); if (error != NO_ERROR) { while (1); } uc_printf ("SPI Flash Device ID(READ-ID) %d %d %d %d\n\r", read_data[0], read_data[1], read_data[2], read_data[3]); /* READ ID USING JEDEC READ */ uint16_t read_data_jedec[4]; spi_cmd.readReg = 0x9F; spi_cmd.readRegValid = 1; spi_cmd.readBuffer = read_data_jedec; spi_cmd.readDataSize = sizeof(read_data_jedec); error = SPI_Read(SPI0, &spi_cmd); if (error != NO_ERROR) { while (1); } uc_printf ("SPI Flash Device ID(Jedec) %d %d %d %d\n\r", read_data_jedec[0], read_data_jedec[1], read_data_jedec[2], read_data_jedec[3]); int size = 18; char fw_version[18] = "PowerAvrVersion5.5"; char fw_version_read[18] = { 0 }; command.address = 0x50; command.data = fw_version; command.operation = WRITE; command.reg = 0x00; command.size = 1; //11; int i, j, k; for (j=0; j<1; j++) { for (i=0; i<size;i++) { //UART_PutChars(COM0,"Writing", 9); command.reg = 0x00 + i; command.size = 1; command.data = &(fw_version[i]); error = I2C_Write(I2C0, &command); if (error != NO_ERROR) { break; } //This is to cause a delay after write. This should be replaced with the wait in the I2C_Write Operation. for (k=0; k<16; k++) { uc_printf("."); uc_printf("\b"); } } if (error != NO_ERROR) { while (1); } } uc_printf("I2C Write Done\n\r"); command.operation = READ; command.data = fw_version_read; command.size = 1 ; for (j=0; j<1; j++) { for (i=0; i<size;i++) { fw_version_read[i] = 'X'; } for (i=0; i<size;i++) { command.reg = 0x00 + i; command.size = 1; command.data = &(fw_version_read[i]); error = I2C_Read(I2C0, &command); if (error != NO_ERROR) { break; } } if (error != NO_ERROR) { while (1); } } uc_printf("I2C Read Done\n\r"); for (i=0; i<size; i++) { uc_printf("%c",fw_version_read[i]); } uc_printf("\n\r"); pin_interrupt_type_t key1_status; float vol=0; int timeout = 0; while (1) { error = GPIO_GetIRQ(&key1, &key1_status); if (error != NO_ERROR) { while (1); } if (key1_status == INTERRUPT_ENABLED_FALLING) { uc_printf ("Falling Edge\n\r"); error = GPIO_ClrIRQ(&key1); if (error != NO_ERROR) { while (1); } if ( (error = ADC_Read(&adc5)) != NO_ERROR ) { while (1); } } else if (key1_status == INTERRUPT_ENABLED_RISING) { uc_printf ("Rising Edge\n\r"); error = GPIO_ClrIRQ(&key1); if (error != NO_ERROR) { while (1); } } //#if (DISPLAY_ADC == 1) //if (adc5.trigger_mode == BURST) { if (timeout == 20000) { ADC_Read(&adc5); timeout = 0; } else { timeout++; } //} if (adc5.done) { vol =0 ; int i=0; int result = adc5.result; for (i=0; i<4096; i+=256) { vol++; if (result >= i && result <= (i + 256) ) { break; } } /* for (i=0; i<adc5.result/33; i++) { uc_printf("*"); } uc_printf("\r"); */ //uc_printf ("%d\n\r", adc5.result); adc5.done = 0; } //#endif //#if (PLAY_PIANO == 1) if (vol == 0) { vol = 1; } else if (vol > 1) { //vol = vol ; //1 + (vol - 1)*0.2; } Play_Piano(&dac0, vol ); //#endif } #if (UART_TEST == 1) char rx_data; char tx_data[] = "This is x nnnnn\n\r"; while (1) { //if ( UART_GetChar(COM0, &rx_data) != FIFO_EMPTY ) { tx_data[8] = 'a'; //UART_PutChar(COM0, rx_data); UART_PutChars(COM0, tx_data, 17 ); int i; tx_data[8] = 'b'; for (i=0; i<17; i++) { UART_PutChar(COM0, tx_data[i]); } //} } #endif return 0; }
/********************************************************************* * @brief Initializes the UART peripheral. * @param None * @retval None * @date 20141205 ***********************************************************************/ void UARTx_Init(void) { UART_GPIO_Init(); UART_Config(); NVIC_Configuration(); }
int main(int argc, char* argv[]) { volatile FATFS fatfs = {0}; volatile FRESULT result; uint8_t fifo_command = 0; uint8_t file_index = 0; ResetRCC(); RCC_SetClockFrequency(PLLM_macro, PLLN_macro, PLLQ_macro, PLLP_macro); // Enable clocks for the peripherals /* * GPIOA - NEC_CONTROLLER, TIM1 PWM, DAC * GPIOB - SPI2 * GPIOC - HD44780 Led Display * GPIOD - LED diodes, USART2(Log) */ RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN | RCC_AHB1ENR_GPIOBEN | RCC_AHB1ENR_GPIOCEN | RCC_AHB1ENR_GPIODEN; RCC->APB2ENR |= RCC_APB2ENR_TIM1EN; RCC->APB1ENR |= RCC_APB1ENR_TIM7EN | RCC_APB1ENR_SPI2EN | RCC_APB1ENR_USART2EN | RCC_APB1ENR_DACEN; /*< Configure board's leds to signal states */ GPIO_OutputConfigure(GPIOD, PIN_12 | PIN_13 | PIN_14 | PIN_15, gpio_otyper_push_pull, gpio_speed_high, gpio_pupd_pull_down); /*< Configure NVIC Interrupt controller */ // Set two bits (out of four) as the main priority. The rest bits are used for preemptive priorities NVIC_SetPriorityGrouping(NVIC_PriorityGroup_2); NVIC_Enable_Interrupts(); /*< Configure USART2 module to create program log */ UART_Config(USART2, USART_CR1_UE | USART_CR1_TE, 19200,false); GPIO_AlternateFunctionPrepare(GPIOD, PIN_5, gpio_otyper_push_pull, gpio_speed_medium, gpio_pupd_pull_up); GPIO_AlternateFunctionSet(GPIOD,PIN_5, AF7); Log_Uart("##### LOG START #####\n\r"); /*< MCO2 Pin configuration to watch the CPU Clock signal with an oscilloscope*/ Log_Uart("Clock output pin configuration in progress...\n\r"); RCC->CFGR |= RCC_CFGR_MCO2PRE_2 | RCC_CFGR_MCO2PRE_1; RCC->CFGR &= ~RCC_CFGR_MCO2; GPIO_AlternateFunctionPrepare(GPIOC, PIN_9, gpio_otyper_push_pull, gpio_speed_fast, gpio_pupd_no_pull); GPIO_AlternateFunctionSet(GPIOC,PIN_9, AF0); /*< SysTick configuration */ Log_Uart("SysTick configuration in progress...\n\r"); SysTick_Config(SYSTICK_CLK_DIVIDER); // Configure SysTick to make a tick every 1 us SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK); /*< PWM signal configuration */ Log_Uart("PWM generation module configuration in progress...\n\r"); GPIO_AlternateFunctionPrepare(GPIOA, PIN_8, gpio_otyper_push_pull, gpio_speed_fast, gpio_pupd_pull_down); GPIO_AlternateFunctionSet(GPIOA, PIN_8, AF1); // Pin for PWM signal TIM_PWMConfigure(TIM1, 168, 5000, 4000, TIM_Channel_1); TIM_Start(TIM1); /*< HD44780 display configuration */ LCD_Config(); /*< Remote controller receiver initialization */ Log_Uart("IR remote controller configuration in progress...\n\r"); NEC_Remote_Init(); TIM_Start(TIM6); /*< SPI Module configuration. It is used to communicate with the SD card */ Log_Uart("SPI module configuration in progress...\n\r"); SPI_Master_Init(SPI2, SPI_FREQ_PCLK_DIV_256, SPI_CPOL0_CPHA0, SPI_BIT_ORDER_MSB_FIRST, true); /*< DAC configuration */ DAC_Init(dac_dual_channel_simultanous, dac_trigger_tim7, true); /*< Timer 7 used to trigger the DAC config */ TIM_Basic_Continuous_Counting(TIM7, 12); /*< Remote Controller command fifo configuration */ Log_Uart("FIFO configuration in progress...\n\r"); Fifo_Init(&remote_command_fifo, remote_command_queue, sizeof(remote_command_queue)); TIM6->CR1 |= TIM_CR1_CEN; /*< Continuously ticking timer, used in NEC IR remote */ Log_Uart("Configuration OK!\n\r"); TCHAR disk[] = "0"; UINT byte_number; result = f_mount(&fatfs, disk, 1); uint16_t bytes; /* result = SD_Find_File_Name_Containing("/", "*.wav"); result = SD_Get_File_List("/"); result = f_open(&sd_current_file, &sd_files_list[3], FA_READ); result = Wav_Get_File_Header(&sd_current_file); */ // Initially, get the files list state = STATE_GET_FILES_LIST; while(1) { switch(state) { /* case STATE_WAIT: break;*/ case STATE_GET_FILES_LIST: { result = SD_Find_File_Name_Containing("/", "*.wav"); if(result == FR_NO_FILE) { LCD_WriteText("Brak plikow .wav"); // Go to sleep in this case while(1) { __WFI(); } } else { LCD_WriteText(sd_files_list[0]); } state = STATE_EXECUTE_USER_REQUESTS; break; } case STATE_READ_SAMPLES: { // If we didn't get to the end of file yet... if(!f_eof(&sd_current_file)) // ... Then read next sample chunk f_read(&sd_current_file, empty_data_buf_ptr, 512, &read_data_byte_counter); else // ... Else set the end of file flag wav_eof = true; state = STATE_EXECUTE_USER_REQUESTS; break; } case STATE_EXECUTE_USER_REQUESTS: { do { Fifo_Get(&remote_command_fifo, &fifo_command); switch(fifo_command) { case NEC_CH_PLUS: { // Disable when the wav_file is currently played if(!wav_file_playing) { wav_file_chosen = false; if(file_index < sd_number_of_files_in_dir-1) file_index++; LCD_WriteText(sd_files_list[file_index]); } break; } case NEC_CH_MINUS: { // Disable when the wav_file is currently played if(!wav_file_playing) { wav_file_chosen = false; if(file_index > 0) file_index--; LCD_WriteText(sd_files_list[file_index]); } break; } case NEC_CH: { // Disable when the wav_file is currently played if(!wav_file_chosen) { // If the file is already opened then close it if(sd_current_file.fs != 0) f_close(&sd_current_file); // ...Open the chosen file f_open(&sd_current_file, sd_files_list[file_index], FA_READ); // Get the chosen files header WAV_Get_File_Header(&sd_current_file); // Prepare the triggering timer frequency // WAV_Set_Trigger_Frequency(TIM7); TIM_Set_Timer_Max_Count(TIM7, (uint16_t)(TIM7_FREQ/current_wave_header.byte_field.sample_rate)); // Get the rest audio file info //f_read(&sd_current_file, sd_data_buffer, current_wave_header.byte_field.subchunk_2_size, &read_data_byte_counter); // Get the first portion of data // Set the wav_file_chosen flag wav_file_chosen = true; // Clear the wav_eof flag wav_eof = false; } break; } case NEC_PLAY_PAUSE: { if(!wav_file_playing && wav_file_chosen) { // Clear the timer's counter TIM_Clear(TIM7); TIM7->DIER |= TIM_DIER_UIE; empty_data_buf_ptr = sd_data_buffer; f_read(&sd_current_file, sd_data_buffer, sizeof(sd_data_buffer), &read_data_byte_counter); f_read(&sd_current_file, sd_data_buffer_additional, sizeof(sd_data_buffer_additional), &read_data_byte_counter); // Start the DAC triggering timer TIM_Start(TIM7); // Set the wav_file_playing_flag wav_file_playing = true; } else { // Stop the DAC triggering timer TIM_Stop(TIM7); // Clear the wav_file_playing_ flag wav_file_playing = false; } break; } default: break; } fifo_command = 0; }while(!Fifo_Empty(&remote_command_fifo)); break; } } } }