本文整理汇总了C++中HAL_Delay函数的典型用法代码示例。如果您正苦于以下问题:C++ HAL_Delay函数的具体用法?C++ HAL_Delay怎么用?C++ HAL_Delay使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了HAL_Delay函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
/**
* @brief Main program
* @param None
* @retval None
*/
int main(void)
{
/* STM32F4xx HAL library initialization:
- Configure the Flash prefetch, instruction and Data caches
- Configure the Systick to generate an interrupt each 1 msec
- Set NVIC Group Priority to 4
- Global MSP (MCU Support Package) initialization
*/
HAL_Init();
/* Configure the system clock to 168 MHz */
SystemClock_Config();
/* Configure LED1, LED2, LED3 and LED4 */
BSP_LED_Init(LED1);
BSP_LED_Init(LED2);
BSP_LED_Init(LED3);
BSP_LED_Init(LED4);
/* Configure Key Button */
BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_GPIO);
/*##-1- Configure the CAN peripheral #######################################*/
CAN_Config();
/*##-2- Start the Reception process and enable reception interrupt #########*/
if(HAL_CAN_Receive_IT(&CanHandle, CAN_FIFO0) != HAL_OK)
{
/* Reception Error */
Error_Handler();
}
/* Infinite loop */
while(1)
{
while(BSP_PB_GetState(BUTTON_KEY) == KEY_PRESSED)
{
if(ubKeyNumber == 0x4)
{
ubKeyNumber = 0x00;
}
else
{
LED_Display(++ubKeyNumber);
/* Set the data to be transmitted */
CanHandle.pTxMsg->Data[0] = ubKeyNumber;
CanHandle.pTxMsg->Data[1] = 0xAD;
/*##-3- Start the Transmission process ###############################*/
if(HAL_CAN_Transmit(&CanHandle, 10) != HAL_OK)
{
/* Transmission Error */
Error_Handler();
}
HAL_Delay(10);
while(BSP_PB_GetState(BUTTON_KEY) != KEY_NOT_PRESSED)
{
}
}
}
}
}
示例2: main
/**
* @brief Main program
* @param None
* @retval None
*/
int main(void)
{
/* STM32F4xx HAL library initialization:
- Configure the Flash prefetch, instruction and Data caches
- Configure the Systick to generate an interrupt each 1 msec
- Set NVIC Group Priority to 4
- Global MSP (MCU Support Package) initialization
*/
HAL_Init();
/* Configure LED1, LED2, LED3 and LED4 */
BSP_LED_Init(LED1);
BSP_LED_Init(LED2);
BSP_LED_Init(LED3);
BSP_LED_Init(LED4);
/* Configure Key Button, used to trigger an interrupt each time it's pressed.
In the ISR the PLL source will be changed from HSE to HSI, and vice versa. */
BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_EXTI);
/* Enable Power Control clock */
__HAL_RCC_PWR_CLK_ENABLE();
/* The voltage scaling allows optimizing the power consumption when the device is
clocked below the maximum system frequency, to update the voltage scaling value
regarding system frequency refer to product datasheet. */
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
/* Enable HSE oscillator and configure the PLL to reach the max system frequency (180MHz)
when using HSE oscillator as PLL clock source. */
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLM = 25;
RCC_OscInitStruct.PLL.PLLN = 360;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
RCC_OscInitStruct.PLL.PLLQ = 7;
if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
/* Initialization Error */
Error_Handler();
}
/* Activate the Over Drive feature (available only for STM32F42xxx/43xxx devices)*/
if(HAL_PWREx_EnableOverDrive() != HAL_OK)
{
/* Initialization Error */
Error_Handler();
}
/* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clocks dividers.
The SysTick 1 msec interrupt is required for the HAL process (Timeout management); by default
the configuration is done using the HAL_Init() API, and when the system clock configuration
is updated the SysTick configuration will be adjusted by the HAL_RCC_ClockConfig() API. */
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_5) != HAL_OK)
{
/* Initialization Error */
Error_Handler();
}
/* Output SYSCLK divided by 2 on MCO2 pin(PC9) */
HAL_RCC_MCOConfig(RCC_MCO2, RCC_MCO2SOURCE_SYSCLK, RCC_MCODIV_2);
/* Toggle some LEDs in an infinite loop */
while (1)
{
/* Toggle LED1 */
BSP_LED_Toggle(LED1);
HAL_Delay(100);
/* Toggle LED2 */
BSP_LED_Toggle(LED2);
HAL_Delay(100);
/* Toggle LED4 */
BSP_LED_Toggle(LED4);
HAL_Delay(100);
}
}
示例3: HAL_GPIO_EXTI_Callback
/**
* @brief GPIO EXTI Callback function
* Handle remote-wakeup through key button
* @param GPIO_Pin
* @retval None
*/
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
if (GPIO_Pin == KEY_BUTTON_PIN)
{
#if (USBD_LPM_ENABLED == 1)
if(hpcd.lpm_active)
{
if(hpcd.LPM_State == LPM_L1)
{
if ((&hpcd)->Init.low_power_enable)
{
/* Reset SLEEPDEEP bit of Cortex System Control Register */
SCB->SCR &= (uint32_t)~((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk));
SystemClockConfig_STOP();
}
/* Ungate PHY clock */
__HAL_PCD_UNGATE_PHYCLOCK((&hpcd));
/* Activate Remote wakeup */
HAL_PCD_ActivateRemoteWakeup((&hpcd));
/* Remote wakeup delay */
HAL_Delay(10);
/* Disable Remote wakeup */
HAL_PCD_DeActivateRemoteWakeup((&hpcd));
/* change state to configured */
((USBD_HandleTypeDef *)hpcd.pData)->dev_state = USBD_STATE_CONFIGURED;
/* clear L1 flag */
hpcd.LPM_State = LPM_L0;
}
else
#endif
if ((((USBD_HandleTypeDef *)hpcd.pData)->dev_remote_wakeup == 1)&&
(((USBD_HandleTypeDef *)hpcd.pData)->dev_state == USBD_STATE_SUSPENDED))
{
if ((&hpcd)->Init.low_power_enable)
{
/* Reset SLEEPDEEP bit of Cortex System Control Register */
SCB->SCR &= (uint32_t)~((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk));
SystemClockConfig_STOP();
}
/* Ungate PHY clock */
__HAL_PCD_UNGATE_PHYCLOCK((&hpcd));
/* Activate Remote wakeup */
HAL_PCD_ActivateRemoteWakeup((&hpcd));
/* Remote wakeup delay */
HAL_Delay(10);
/* Disable Remote wakeup */
HAL_PCD_DeActivateRemoteWakeup((&hpcd));
/* change state to configured */
((USBD_HandleTypeDef *)hpcd.pData)->dev_state = USBD_STATE_CONFIGURED;
/* Change remote_wakeup feature to 0*/
((USBD_HandleTypeDef *)hpcd.pData)->dev_remote_wakeup=0;
}
}
}
}
示例4: USBH_Delay
/**
* @brief Delay routine for the USB Host Library
* @param Delay: Delay in ms
* @retval None
*/
void USBH_Delay(uint32_t Delay)
{
HAL_Delay(Delay);
}
示例5: HAL_DAC_ConfigChannel
/**
* @brief Configures the selected DAC channel.
* @param hdac: pointer to a DAC_HandleTypeDef structure that contains
* the configuration information for the specified DAC.
* @param sConfig: DAC configuration structure.
* @param Channel: The selected DAC channel.
* This parameter can be one of the following values:
* @arg DAC_CHANNEL_1: DAC Channel1 selected
* @arg DAC_CHANNEL_2: DAC Channel2 selected
* @retval HAL status
*/
HAL_StatusTypeDef HAL_DAC_ConfigChannel(DAC_HandleTypeDef* hdac, DAC_ChannelConfTypeDef* sConfig, uint32_t Channel)
{
uint32_t tmpreg1 = 0, tmpreg2 = 0;
uint32_t tickstart = 0;
/* Check the DAC parameters */
assert_param(IS_DAC_TRIGGER(sConfig->DAC_Trigger));
assert_param(IS_DAC_OUTPUT_BUFFER_STATE(sConfig->DAC_OutputBuffer));
assert_param(IS_DAC_CHIP_CONNECTION(sConfig->DAC_ConnectOnChipPeripheral));
assert_param(IS_DAC_TRIMMING(sConfig->DAC_UserTrimming));
if ((sConfig->DAC_UserTrimming) == DAC_TRIMMING_USER)
{
assert_param(IS_DAC_TRIMMINGVALUE(sConfig->DAC_TrimmingValue));
}
assert_param(IS_DAC_SAMPLEANDHOLD(sConfig->DAC_SampleAndHold));
if ((sConfig->DAC_SampleAndHold) == DAC_SAMPLEANDHOLD_ENABLE)
{
assert_param(IS_DAC_SAMPLETIME(sConfig->DAC_SampleAndHoldConfig.DAC_SampleTime));
assert_param(IS_DAC_HOLDTIME(sConfig->DAC_SampleAndHoldConfig.DAC_HoldTime));
assert_param(IS_DAC_REFRESHTIME(sConfig->DAC_SampleAndHoldConfig.DAC_RefreshTime));
}
assert_param(IS_DAC_CHANNEL(Channel));
/* Process locked */
__HAL_LOCK(hdac);
/* Change DAC state */
hdac->State = HAL_DAC_STATE_BUSY;
if(sConfig->DAC_SampleAndHold == DAC_SAMPLEANDHOLD_ENABLE)
/* Sample on old configuration */
{
/* SampleTime */
if (Channel == DAC_CHANNEL_1)
{
/* Get timeout */
tickstart = HAL_GetTick();
/* SHSR1 can be written when BWST1 equals RESET */
while (((hdac->Instance->SR) & DAC_SR_BWST1)!= RESET)
{
/* Check for the Timeout */
if((HAL_GetTick() - tickstart) > TIMEOUT_DAC_CALIBCONFIG)
{
/* Update error code */
SET_BIT(hdac->ErrorCode, HAL_DAC_ERROR_TIMEOUT);
/* Change the DMA state */
hdac->State = HAL_DAC_STATE_TIMEOUT;
return HAL_TIMEOUT;
}
}
HAL_Delay(1);
hdac->Instance->SHSR1 = sConfig->DAC_SampleAndHoldConfig.DAC_SampleTime;
}
else /* Channel 2 */
{
/* SHSR2 can be written when BWST2 equals RESET */
while (((hdac->Instance->SR) & DAC_SR_BWST2)!= RESET)
{
/* Check for the Timeout */
if((HAL_GetTick() - tickstart) > TIMEOUT_DAC_CALIBCONFIG)
{
/* Update error code */
SET_BIT(hdac->ErrorCode, HAL_DAC_ERROR_TIMEOUT);
/* Change the DMA state */
hdac->State = HAL_DAC_STATE_TIMEOUT;
return HAL_TIMEOUT;
}
}
HAL_Delay(1);
hdac->Instance->SHSR2 = sConfig->DAC_SampleAndHoldConfig.DAC_SampleTime;
}
/* HoldTime */
hdac->Instance->SHHR = (sConfig->DAC_SampleAndHoldConfig.DAC_HoldTime)<<Channel;
/* RefreshTime */
hdac->Instance->SHRR = (sConfig->DAC_SampleAndHoldConfig.DAC_RefreshTime)<<Channel;
}
if(sConfig->DAC_UserTrimming == DAC_TRIMMING_USER)
/* USER TRIMMING */
{
/* Get the DAC CCR value */
tmpreg1 = hdac->Instance->CCR;
/* Clear trimming value */
//.........这里部分代码省略.........
示例6: main
/**
* @brief Main program
* @param None
* @retval None
*/
int main(void)
{
/* STM32F4xx HAL library initialization:
- Configure the Flash prefetch, instruction and Data caches
- Configure the Systick to generate an interrupt each 1 msec
- Set NVIC Group Priority to 4
- Global MSP (MCU Support Package) initialization
*/
HAL_Init();
/* Configure LED3, LED4, LED5 and LED6 */
BSP_LED_Init(LED3);
BSP_LED_Init(LED4);
BSP_LED_Init(LED5);
BSP_LED_Init(LED6);
/* Configure the system clock to 84 MHz */
SystemClock_Config();
/*##-1- Configure the UART peripheral ######################################*/
/* Put the USART peripheral in the Asynchronous mode (UART Mode) */
/* UART1 configured as follow:
- Word Length = 8 Bits
- Stop Bit = One Stop bit
- Parity = None
- BaudRate = 9600 baud
- Hardware flow control disabled (RTS and CTS signals) */
UartHandle.Instance = USARTx;
UartHandle.Init.BaudRate = 9600;
UartHandle.Init.WordLength = UART_WORDLENGTH_8B;
UartHandle.Init.StopBits = UART_STOPBITS_1;
UartHandle.Init.Parity = UART_PARITY_NONE;
UartHandle.Init.HwFlowCtl = UART_HWCONTROL_NONE;
UartHandle.Init.Mode = UART_MODE_TX_RX;
UartHandle.Init.OverSampling = UART_OVERSAMPLING_16;
if(HAL_UART_Init(&UartHandle) != HAL_OK)
{
Error_Handler();
}
#ifdef TRANSMITTER_BOARD
/* Configure USER Button */
BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_GPIO);
/* Wait for USER Button press before starting the Communication */
while (BSP_PB_GetState(BUTTON_KEY) == RESET)
{
/* Toggle LED3 waiting for user to press button */
BSP_LED_Toggle(LED3);
HAL_Delay(40);
}
/* Wait for USER Button to be release before starting the Communication */
while (BSP_PB_GetState(BUTTON_KEY) == SET)
{
}
/* Turn LED3 off */
BSP_LED_Off(LED3);
/* The board sends the message and expects to receive it back */
/*##-2- Start the transmission process #####################################*/
/* While the UART in reception process, user can transmit data through
"aTxBuffer" buffer */
if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBuffer, TXBUFFERSIZE, 5000)!= HAL_OK)
{
Error_Handler();
}
/* Turn LED6 on: Transfer in transmission process is correct */
BSP_LED_On(LED6);
/*##-3- Put UART peripheral in reception process ###########################*/
if(HAL_UART_Receive(&UartHandle, (uint8_t *)aRxBuffer, RXBUFFERSIZE, 5000) != HAL_OK)
{
Error_Handler();
}
/* Turn LED4 on: Transfer in reception process is correct */
BSP_LED_On(LED4);
#else
/* The board receives the message and sends it back */
/*##-2- Put UART peripheral in reception process ###########################*/
if(HAL_UART_Receive(&UartHandle, (uint8_t *)aRxBuffer, RXBUFFERSIZE, 5000) != HAL_OK)
{
Error_Handler();
}
//.........这里部分代码省略.........
示例7: main
/**
* @brief Main program
* @param None
* @retval None
*/
int main(void)
{
uint8_t lcd_status = LCD_OK;
/* STM32F4xx HAL library initialization:
- Configure the Flash prefetch, instruction and Data caches
- 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: global MSP (MCU Support Package) initialization
*/
HAL_Init();
/* Configure the system clock to 180 MHz */
SystemClock_Config();
/* Initialize the SDRAM */
BSP_SDRAM_Init();
/* Initialize the LCD */
lcd_status = LCD_Init();
OnError_Handler(lcd_status != LCD_OK);
/* Initialize LTDC layer 0 iused for Hint */
LCD_LayertInit(0, LAYER0_ADDRESS);
BSP_LCD_SelectLayer(0);
HAL_DSI_LongWrite(&hdsi_eval, 0, DSI_DCS_LONG_PKT_WRITE, 4, OTM8009A_CMD_CASET, pColLeft);
HAL_DSI_LongWrite(&hdsi_eval, 0, DSI_DCS_LONG_PKT_WRITE, 4, OTM8009A_CMD_PASET, pPage);
/* Update pitch : the draw is done on the whole physical X Size */
HAL_LTDC_SetPitch(&hltdc_eval, BSP_LCD_GetXSize(), 0);
/* Display example brief */
LCD_BriefDisplay();
/* Show first image */
CopyPicture((uint32_t *)Images[ImageIndex++], (uint32_t *)LAYER0_ADDRESS, 240, 160, 320, 240);
pending_buffer = 0;
active_area = LEFT_AREA;
HAL_DSI_LongWrite(&hdsi_eval, 0, DSI_DCS_LONG_PKT_WRITE, 2, OTM8009A_CMD_WRTESCN, pScanCol);
/* Infinite loop */
while (1)
{
if(pending_buffer < 0)
{
CopyPicture((uint32_t *)Images[ImageIndex++], (uint32_t *)LAYER0_ADDRESS, 240, 160, 320, 240);
if(ImageIndex >= 2)
{
ImageIndex = 0;
}
pending_buffer = 1;
HAL_DSI_LongWrite(&hdsi_eval, 0, DSI_DCS_LONG_PKT_WRITE, 2, OTM8009A_CMD_WRTESCN, pScanCol);
}
/* Wait some time before switching to next image */
HAL_Delay(2000);
}
}
示例8: LCD_Delay
/**
* @brief Wait for loop in ms.
* @param Delay in ms.
* @retval None
*/
void LCD_Delay(uint32_t Delay)
{
HAL_Delay(Delay);
}
示例9: IOE_Delay
/**
* @brief IOE Delay.
* @param Delay in ms
* @retval None
*/
void IOE_Delay(uint32_t Delay)
{
HAL_Delay(Delay);
}
示例10: HAL_OPAMP_SelfCalibrate
HAL_StatusTypeDef HAL_OPAMP_SelfCalibrate(OPAMP_HandleTypeDef *hopamp)
{
HAL_StatusTypeDef status = HAL_OK;
uint32_t trimmingvaluen = 0;
uint32_t trimmingvaluep = 0;
uint32_t delta;
uint32_t opampmode;
__IO uint32_t* tmp_opamp_reg_trimming; /* Selection of register of trimming depending on power mode: OTR or LPOTR */
/* Check the OPAMP handle allocation */
/* Check if OPAMP locked */
if((hopamp == NULL) || (hopamp->State == HAL_OPAMP_STATE_BUSYLOCKED))
{
status = HAL_ERROR;
}
else
{
/* Check if OPAMP in calibration mode and calibration not yet enable */
if(hopamp->State == HAL_OPAMP_STATE_READY)
{
/* Check the parameter */
assert_param(IS_OPAMP_ALL_INSTANCE(hopamp->Instance));
assert_param(IS_OPAMP_POWERMODE(hopamp->Init.PowerMode));
/* Save OPAMP mode as in */
/* STM32L471xx STM32L475xx STM32L476xx STM32L485xx STM32L486xx */
/* the calibration is not working in PGA mode */
opampmode = READ_BIT(hopamp->Instance->CSR,OPAMP_CSR_OPAMODE);
/* Use of standalone mode */
MODIFY_REG(hopamp->Instance->CSR, OPAMP_CSR_OPAMODE, OPAMP_STANDALONE_MODE);
/* user trimming values are used for offset calibration */
SET_BIT(hopamp->Instance->CSR, OPAMP_CSR_USERTRIM);
/* Select trimming settings depending on power mode */
if (hopamp->Init.PowerMode == OPAMP_POWERMODE_NORMAL)
{
tmp_opamp_reg_trimming = &hopamp->Instance->OTR;
}
else
{
tmp_opamp_reg_trimming = &hopamp->Instance->LPOTR;
}
/* Enable calibration */
SET_BIT (hopamp->Instance->CSR, OPAMP_CSR_CALON);
/* 1st calibration - N */
CLEAR_BIT (hopamp->Instance->CSR, OPAMP_CSR_CALSEL);
/* Enable the selected opamp */
SET_BIT (hopamp->Instance->CSR, OPAMP_CSR_OPAMPxEN);
/* Init trimming counter */
/* Medium value */
trimmingvaluen = 16;
delta = 8;
while (delta != 0)
{
/* Set candidate trimming */
/* OPAMP_POWERMODE_NORMAL */
MODIFY_REG(*tmp_opamp_reg_trimming, OPAMP_OTR_TRIMOFFSETN, trimmingvaluen);
/* OFFTRIMmax delay 1 ms as per datasheet (electrical characteristics */
/* Offset trim time: during calibration, minimum time needed between */
/* two steps to have 1 mV accuracy */
HAL_Delay(OPAMP_TRIMMING_DELAY);
if (READ_BIT(hopamp->Instance->CSR, OPAMP_CSR_CALOUT) != RESET)
{
/* OPAMP_CSR_CALOUT is HIGH try higher trimming */
trimmingvaluen -= delta;
}
else
{
/* OPAMP_CSR_CALOUT is LOW try lower trimming */
trimmingvaluen += delta;
}
/* Divide range by 2 to continue dichotomy sweep */
delta >>= 1;
}
/* Still need to check if right calibration is current value or one step below */
/* Indeed the first value that causes the OUTCAL bit to change from 0 to 1 */
/* Set candidate trimming */
MODIFY_REG(*tmp_opamp_reg_trimming, OPAMP_OTR_TRIMOFFSETN, trimmingvaluen);
/* OFFTRIMmax delay 1 ms as per datasheet (electrical characteristics */
/* Offset trim time: during calibration, minimum time needed between */
/* two steps to have 1 mV accuracy */
HAL_Delay(OPAMP_TRIMMING_DELAY);
if ((READ_BIT(hopamp->Instance->CSR, OPAMP_CSR_CALOUT)) == 0)
{
/* Trimming value is actually one value more */
//.........这里部分代码省略.........
示例11: FW_UPGRADE_Process
/**
* @brief Demo application for IAP through USB mass storage.
* @param None
* @retval None
*/
void FW_UPGRADE_Process(void)
{
switch(Demo_State)
{
case DEMO_INIT:
/* Register the file system object to the FatFs module */
if(f_mount(&USBH_fatfs, "", 0 ) != FR_OK )
{
/* FatFs initialization fails */
/* Toggle LED3 and LED4 in infinite loop */
FatFs_Fail_Handler();
}
/* TO DO */
// /* Flash Disk is write protected: Turn LED4 On and Toggle LED3 in infinite loop */
// if(USBH_MSC_Param.MSWriteProtect == DISK_WRITE_PROTECTED)
// {
// /* Turn LED4 On */
// BSP_LED_On(LED4);
// /* Toggle LED3 in infinite loop */
// Fail_Handler();
// }
/* Go to IAP menu */
Demo_State = DEMO_IAP;
break;
case DEMO_IAP:
while(USBH_MSC_IsReady(&hUSBHost))
{
/* Control BUFFER_SIZE value */
USBH_USR_BufferSizeControl();
/* Keep LED1 and LED3 Off when Device connected */
BSP_LED_Off(LED3);
BSP_LED_Off(LED4);
/* USER Button pressed Delay */
IAP_UploadTimeout();
/* Writes Flash memory */
COMMAND_Download();
/* Check if USER Button is already pressed */
if((UploadCondition == 0x01))
{
/* Reads all flash memory */
COMMAND_Upload();
}
else
{
/* Turn LED4 Off: Download Done */
BSP_LED_Off(LED4);
/* Turn LED3 On: Waiting KEY button pressed */
BSP_LED_On(LED3);
}
/* Waiting USER Button Released */
while((BSP_PB_GetState(BUTTON_KEY) == GPIO_PIN_RESET) && (Appli_state == APPLICATION_READY))
{}
/* Waiting USER Button Pressed */
while((BSP_PB_GetState(BUTTON_KEY) != GPIO_PIN_RESET) && (Appli_state == APPLICATION_READY))
{}
/* Waiting USER Button Released */
while((BSP_PB_GetState(BUTTON_KEY) == GPIO_PIN_RESET) && (Appli_state == APPLICATION_READY))
{}
if(Appli_state == APPLICATION_READY)
{
/* Jump to user application code located in the internal Flash memory */
COMMAND_Jump();
}
}
break;
default:
break;
}
if(Appli_state == APPLICATION_DISCONNECT)
{
/* Toggle LED3: USB device disconnected */
BSP_LED_Toggle(LED4);
HAL_Delay(100);
}
}
示例12: Touchscreen_demo1
//.........这里部分代码省略.........
/* Reset touch data information */
BSP_TEST_APPLI_ASSERT(BSP_TS_ResetTouchData(&TS_State));
/* If calibration is not yet done, proceed with calibration */
if (TouchScreen_IsCalibrationDone() == 0)
{
ts_status = Touchscreen_Calibration();
if (ts_status == TS_OK)
{
BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize() - 65, (uint8_t *) "Touchscreen calibration success.", CENTER_MODE);
}
} /* of if (TouchScreen_IsCalibrationDone() == 0) */
if(ts_status == TS_OK)
{
/* Display touch screen demo description */
Touchscreen_SetHint_Demo(TOUCHSCREEN_DEMO_1);
Touchscreen_DrawBackground_Demo1(state);
while (exitTsUseCase == 0)
{
if (ts_status == TS_OK)
{
/* Check in polling mode in touch screen the touch status and coordinates */
/* of touches if touch occurred */
ts_status = BSP_TS_GetState(&TS_State);
if(TS_State.touchDetected)
{
/* One or dual touch have been detected */
/* Only take into account the first touch so far */
/* Get X and Y position of the first touch post calibrated */
x1 = TouchScreen_Get_Calibrated_X(TS_State.touchX[0]);
y1 = TouchScreen_Get_Calibrated_Y(TS_State.touchY[0]);
if ((y1 > (CIRCLE_YPOS(1) - CIRCLE_RADIUS)) &&
(y1 < (CIRCLE_YPOS(1) + CIRCLE_RADIUS)))
{
if ((x1 > (CIRCLE_XPOS(1) - CIRCLE_RADIUS)) &&
(x1 < (CIRCLE_XPOS(1) + CIRCLE_RADIUS)))
{
if ((state & 1) == 0)
{
Touchscreen_DrawBackground_Demo1(state);
BSP_LCD_SetTextColor(LCD_COLOR_BLUE);
BSP_LCD_FillCircle(CIRCLE_XPOS(1), CIRCLE_YPOS(1), CIRCLE_RADIUS);
state = 1;
}
}
if ((x1 > (CIRCLE_XPOS(2) - CIRCLE_RADIUS)) &&
(x1 < (CIRCLE_XPOS(2) + CIRCLE_RADIUS)))
{
if ((state & 2) == 0)
{
Touchscreen_DrawBackground_Demo1(state);
BSP_LCD_SetTextColor(LCD_COLOR_RED);
BSP_LCD_FillCircle(CIRCLE_XPOS(2), CIRCLE_YPOS(2), CIRCLE_RADIUS);
state = 2;
}
}
if ((x1 > (CIRCLE_XPOS(3) - CIRCLE_RADIUS)) &&
(x1 < (CIRCLE_XPOS(3) + CIRCLE_RADIUS)))
{
if ((state & 4) == 0)
{
Touchscreen_DrawBackground_Demo1(state);
BSP_LCD_SetTextColor(LCD_COLOR_YELLOW);
BSP_LCD_FillCircle(CIRCLE_XPOS(3), CIRCLE_YPOS(3), CIRCLE_RADIUS);
state = 4;
}
}
if ((x1 > (CIRCLE_XPOS(4) - CIRCLE_RADIUS)) &&
(x1 < (CIRCLE_XPOS(4) + CIRCLE_RADIUS)))
{
if ((state & 8) == 0)
{
Touchscreen_DrawBackground_Demo1(state);
BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
BSP_LCD_FillCircle(CIRCLE_XPOS(4), CIRCLE_YPOS(3), CIRCLE_RADIUS);
state = 8;
}
}
}
} /* of if(TS_State.TouchDetected) */
} /* of if (ts_status == TS_OK) */
/* Wait for a key button press to switch to next test case of BSP validation application */
/* Otherwise stay in the test */
exitTsUseCase = CheckForUserInput();
HAL_Delay(20);
} /* of while (exitTsUseCase == 0) */
} /* of if(status == TS_OK) */
}
示例13: main
/**
* @brief Main program
* @param None
* @retval None
*/
int main(void)
{
/* STM32F4xx HAL library initialization:
- Configure the Flash prefetch, instruction and Data caches
- 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: global MSP (MCU Support Package) initialization
*/
HAL_Init();
/* Configure the system clock to 100 MHz */
SystemClock_Config();
/* Configure LED2 */
BSP_LED_Init(LED2);
/*##-1- Configure the UART peripheral ######################################*/
/* Put the USART peripheral in the Asynchronous mode (UART Mode) */
/* UART configured as follows:
- Word Length = 8 Bits
- Stop Bit = One Stop bit
- Parity = None
- BaudRate = 9600 baud
- Hardware flow control disabled (RTS and CTS signals) */
UartHandle.Instance = USARTx;
UartHandle.Init.BaudRate = 9600;
UartHandle.Init.WordLength = UART_WORDLENGTH_8B;
UartHandle.Init.StopBits = UART_STOPBITS_1;
UartHandle.Init.Parity = UART_PARITY_NONE;
UartHandle.Init.HwFlowCtl = UART_HWCONTROL_NONE;
UartHandle.Init.Mode = UART_MODE_TX_RX;
if(HAL_UART_DeInit(&UartHandle) != HAL_OK)
{
Error_Handler();
}
if(HAL_UART_Init(&UartHandle) != HAL_OK)
{
Error_Handler();
}
#ifdef TRANSMITTER_BOARD
/* Configure User push-button in Interrupt mode */
BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_EXTI);
/* Wait for User push-button press before starting the Communication.
In the meantime, LED2 is blinking */
while(UserButtonStatus == 0)
{
/* Toggle LED2*/
BSP_LED_Toggle(LED2);
HAL_Delay(100);
}
BSP_LED_Off(LED2);
/* The board sends the message and expects to receive it back */
/*##-2- Start the transmission process #####################################*/
/* While the UART in reception process, user can transmit data through
"aTxBuffer" buffer */
if(HAL_UART_Transmit_IT(&UartHandle, (uint8_t*)aTxBuffer, TXBUFFERSIZE)!= HAL_OK)
{
Error_Handler();
}
/*##-3- Wait for the end of the transfer ###################################*/
while (UartReady != SET)
{
}
/* Reset transmission flag */
UartReady = RESET;
/*##-4- Put UART peripheral in reception process ###########################*/
if(HAL_UART_Receive_IT(&UartHandle, (uint8_t *)aRxBuffer, RXBUFFERSIZE) != HAL_OK)
{
Error_Handler();
}
#else
/* The board receives the message and sends it back */
/*##-2- Put UART peripheral in reception process ###########################*/
if(HAL_UART_Receive_IT(&UartHandle, (uint8_t *)aRxBuffer, RXBUFFERSIZE) != HAL_OK)
{
Error_Handler();
}
//.........这里部分代码省略.........
示例14: MSC_MenuProcess
/**
* @brief Manages MSC Menu Process.
* @param None
* @retval None
*/
void MSC_MenuProcess(void)
{
switch(msc_demo.state)
{
case MSC_DEMO_START:
if(Appli_state == APPLICATION_READY)
{
BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
BSP_LCD_DisplayStringAtLine(19, (uint8_t *)"Press User button to start read and write operations");
/* Wait for User Input */
while((BSP_PB_GetState(BUTTON_WAKEUP) != SET) && (Appli_state != APPLICATION_DISCONNECT))
{
}
msc_demo.state = MSC_DEMO_FILE_OPERATIONS;
/* Prevent debounce effect for user key */
HAL_Delay(400);
BSP_LCD_ClearStringLine(19);
}
break;
case MSC_DEMO_FILE_OPERATIONS:
/* Read and Write File Here */
if(Appli_state == APPLICATION_READY)
{
MSC_File_Operations();
BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
BSP_LCD_DisplayStringAtLine(19, (uint8_t *)"Press User button to display disk content");
/* Wait for User Input */
while((BSP_PB_GetState(BUTTON_WAKEUP) != SET) && (Appli_state != APPLICATION_DISCONNECT))
{
}
msc_demo.state = MSC_DEMO_EXPLORER;
/* Prevent debounce effect for user key */
HAL_Delay(400);
BSP_LCD_ClearStringLine(19);
}
break;
case MSC_DEMO_EXPLORER:
/* Display disk content */
if(Appli_state == APPLICATION_READY)
{
Explore_Disk("0:/", 1);
msc_demo.state = MSC_DEMO_START;
/* Prevent debounce effect for user key */
HAL_Delay(400);
}
break;
default:
break;
}
if(Appli_state == APPLICATION_DISCONNECT)
{
Appli_state = APPLICATION_IDLE;
LCD_LOG_ClearTextZone();
LCD_ErrLog("MSC device disconnected!\n");
msc_demo.state = MSC_DEMO_START;
msc_demo.select = 0;
}
}
示例15: Joystick_demo
/**
* @brief Joystick demo
* @param None
* @retval None
*/
void Joystick_demo (void)
{
static uint16_t xPtr = 12;
static uint16_t yPtr = 92;
static uint16_t old_xPtr = 12;
static uint16_t old_yPtr = 92;
Joystick_SetHint();
BSP_JOY_Init(JOY_MODE_GPIO);
while (1)
{
/* Get the Joystick State */
JoyState = BSP_JOY_GetState();
switch(JoyState)
{
case JOY_UP:
if(yPtr > 92)
{
yPtr--;
}
break;
case JOY_DOWN:
if(yPtr < (BSP_LCD_GetYSize() - 12 - 11))
{
yPtr++;
}
break;
case JOY_LEFT:
if(xPtr > 12)
{
xPtr--;
}
break;
case JOY_RIGHT:
if(xPtr < (BSP_LCD_GetXSize() - 8 - 11))
{
xPtr++;
}
break;
default:
break;
}
BSP_LCD_SetBackColor(LCD_COLOR_WHITE);
BSP_LCD_SetTextColor(LCD_COLOR_BLUE);
if(JoyState == JOY_SEL)
{
BSP_LCD_SetTextColor(LCD_COLOR_RED);
BSP_LCD_DisplayChar(xPtr, yPtr, 'X');
}
else if(JoyState == JOY_NONE)
{
BSP_LCD_SetTextColor(LCD_COLOR_BLUE);
BSP_LCD_DisplayChar(xPtr, yPtr, 'X');
}
else
{
BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
BSP_LCD_DisplayChar(old_xPtr, old_yPtr, 'X');
BSP_LCD_SetTextColor(LCD_COLOR_BLUE);
BSP_LCD_DisplayChar(xPtr, yPtr, 'X');
old_xPtr = xPtr;
old_yPtr = yPtr;
}
if(CheckForUserInput() > 0)
{
return;
}
HAL_Delay(5);
}
}