本文整理汇总了C++中BSP_LED_Toggle函数的典型用法代码示例。如果您正苦于以下问题:C++ BSP_LED_Toggle函数的具体用法?C++ BSP_LED_Toggle怎么用?C++ BSP_LED_Toggle使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了BSP_LED_Toggle函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
/**
* @brief Main program.
* @param None
* @retval None
*/
int main(void)
{
/* STM32F0xx 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.
- Low Level Initialization
*/
HAL_Init();
/* Initialize LEDs */
BSP_LED_Init(LED1);
BSP_LED_Init(LED2);
BSP_LED_Init(LED3);
BSP_LED_Init(LED4);
/* Configure the system clock to have a system clock = 48 MHz */
SystemClock_Config();
/* Turn on LED1 and LED3 */
BSP_LED_On(LED1);
BSP_LED_On(LED3);
/* SysTick Timer is configured by default to generate an interrupt each 1 msec.
---------------------------------------------------------------------------
1. The configuration is done using HAL_SYSTICK_Config() located in HAL_Init().
2. The HAL_SYSTICK_Config() function configure:
- The SysTick Reload register with value passed as function parameter.
- Configure the SysTick IRQ priority to the lowest value.
- Reset the SysTick Counter register.
- Configure the SysTick Counter clock source to be Core Clock Source (HCLK).
- Enable the SysTick Interrupt.
- Start the SysTick Counter.
3. The SysTick time base 1 msec is computed using the following formula:
Reload Value = SysTick Counter Clock (Hz) x Desired Time base (s)
- Reload Value is the parameter to be passed for SysTick_Config() function
- Reload Value should not exceed 0xFFFFFF
@note: Caution, the SysTick time base 1 msec must not be changed due to use
of these time base by HAL driver.
*/
/* Infinite loop */
while (1)
{
/* Toggle LED2 and LED4 */
BSP_LED_Toggle(LED2);
BSP_LED_Toggle(LED4);
/* Insert 50 ms delay */
HAL_Delay(50);
/* Toggle LED1 and LED3 */
BSP_LED_Toggle(LED1);
BSP_LED_Toggle(LED3);
/* Insert 100 ms delay */
HAL_Delay(100);
}
}
示例2: main
/**
* @brief Main program.
* @param None
* @retval None
*/
int main(void)
{
/* STM32F0xx 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.
- Low Level Initialization
*/
HAL_Init();
/* Configure LED2, LED2 and LED2 */
BSP_LED_Init(LED2);
/* Configure the system clock to 48 MHz */
SystemClock_Config();
/*##-1- Configure the SPI peripheral #######################################*/
/* Set the SPI parameters */
SpiHandle.Instance = SPIx;
SpiHandle.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_256;
SpiHandle.Init.Direction = SPI_DIRECTION_2LINES;
SpiHandle.Init.CLKPhase = SPI_PHASE_1EDGE;
SpiHandle.Init.CLKPolarity = SPI_POLARITY_LOW;
SpiHandle.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
SpiHandle.Init.CRCPolynomial = 7;
SpiHandle.Init.DataSize = SPI_DATASIZE_8BIT;
SpiHandle.Init.FirstBit = SPI_FIRSTBIT_MSB;
SpiHandle.Init.NSS = SPI_NSS_SOFT;
SpiHandle.Init.TIMode = SPI_TIMODE_DISABLE;
SpiHandle.Init.NSSPMode = SPI_NSS_PULSE_DISABLE;
SpiHandle.Init.CRCLength = SPI_CRC_LENGTH_8BIT;
#ifdef MASTER_BOARD
SpiHandle.Init.Mode = SPI_MODE_MASTER;
#else
SpiHandle.Init.Mode = SPI_MODE_SLAVE;
#endif /* MASTER_BOARD */
if(HAL_SPI_Init(&SpiHandle) != HAL_OK)
{
/* Initialization Error */
Error_Handler();
}
#ifdef MASTER_BOARD
/* Configure push button */
BSP_PB_Init(BUTTON_USER, BUTTON_MODE_GPIO);
/* Wait for Button press before starting the Communication */
while (BSP_PB_GetState(BUTTON_USER) != GPIO_PIN_RESET)
{
BSP_LED_Toggle(LED2);
HAL_Delay(100);
}
BSP_LED_Off(LED2);
#endif /* MASTER_BOARD */
/*##-2- Start the Full Duplex Communication process ########################*/
/* While the SPI in TransmitReceive process, user can transmit data through
"aTxBuffer" buffer & receive data through "aRxBuffer" */
/* Timeout is set to 5S */
switch(HAL_SPI_TransmitReceive(&SpiHandle, (uint8_t*)aTxBuffer, (uint8_t *)aRxBuffer, BUFFERSIZE, 5000))
{
case HAL_OK:
/* Communication is completed ___________________________________________ */
/* Compare the sent and received buffers */
if (Buffercmp((uint8_t *)aTxBuffer, (uint8_t *)aRxBuffer, BUFFERSIZE))
{
/* Transfer error in transmission process */
Error_Handler();
}
/* Turn LED2 on: Transfer in transmission/Reception process is correct */
BSP_LED_On(LED2);
break;
case HAL_TIMEOUT:
/* An Error Occur ______________________________________________________ */
case HAL_ERROR:
/* Call Timeout Handler */
Error_Handler();
break;
default:
break;
}
/* Infinite loop */
while (1)
{
}
}
示例3: HAL_I2C_SlaveRxCpltCallback
void HAL_I2C_SlaveRxCpltCallback(I2C_HandleTypeDef *I2cHandle)
{
/* Toggle LED2: Transfer in reception process is correct */
BSP_LED_Toggle(LED2);
}
示例4: main
//.........这里部分代码省略.........
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)
{
}
/* 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_DMA(&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;
/* Turn LED3 Off */
BSP_LED_Off(LED3);
/*##-4- Put UART peripheral in reception process ###########################*/
if(HAL_UART_Receive_DMA(&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_DMA(&UartHandle, (uint8_t *)aRxBuffer, RXBUFFERSIZE) != HAL_OK)
{
Error_Handler();
}
/*##-3- Wait for the end of the transfer ###################################*/
while (UartReady != SET)
{
}
/* Reset transmission flag */
UartReady = RESET;
/* Turn LED3 Off */
BSP_LED_Off(LED3);
/*##-4- Start the transmission process #####################################*/
/* While the UART in reception process, user can transmit data through
"aTxBuffer" buffer */
if(HAL_UART_Transmit_DMA(&UartHandle, (uint8_t*)aTxBuffer, TXBUFFERSIZE)!= HAL_OK)
{
Error_Handler();
}
#endif /* TRANSMITTER_BOARD */
/*##-5- Wait for the end of the transfer ###################################*/
while (UartReady != SET)
{
}
/* Reset transmission flag */
UartReady = RESET;
/*##-6- Compare the sent and received buffers ##############################*/
if(Buffercmp((uint8_t*)aTxBuffer,(uint8_t*)aRxBuffer,RXBUFFERSIZE))
{
Error_Handler();
}
/* Infinite loop */
while (1)
{
/* Toggle LED3 */
BSP_LED_Toggle(LED3);
/* Wait for 40ms */
HAL_Delay(40);
}
}
示例5: HAL_COMP_TriggerCallback
/**
* @brief COMP1 interrupt callback
* @param hcomp : COMP handle
* @retval none
*/
void HAL_COMP_TriggerCallback(COMP_HandleTypeDef *hcomp)
{
/* Turn On LED1 */
BSP_LED_Toggle(LED1);
}
示例6: main
//.........这里部分代码省略.........
/*##-7- Master receives aRxBuffer from slave #############################*/
while(HAL_I2C_Master_Receive_IT(&I2cHandle, (uint16_t)I2C_ADDRESS, (uint8_t*)aRxBuffer, RXBUFFERSIZE)!= HAL_OK)
{
/* Error_Handler() function is called when Timout error occurs.
When Acknowledge failure ocucurs (Slave don't acknowledge it's address)
Master restarts communication */
if (HAL_I2C_GetError(&I2cHandle) != HAL_I2C_ERROR_AF)
{
Error_Handler();
}
}
/* Before starting a new communication transfer, you need to check the current
state of the peripheral; if it’s busy you need to wait for the end of current
transfer before starting a new one.
For simplicity reasons, this example is just waiting till the end of the
transfer, but application may perform other tasks while transfer operation
is ongoing. */
while (HAL_I2C_GetState(&I2cHandle) != HAL_I2C_STATE_READY)
{
}
/* Check correctness of received buffer ##################################*/
if(Buffercmp((uint8_t*)aTxBuffer,(uint8_t*)aRxBuffer,hRxNumData))
{
/* Processing Error */
Error_Handler();
}
/* Flush Rx buffers */
Flush_Buffer((uint8_t*)aRxBuffer,RXBUFFERSIZE);
/* Toggle LED1 */
BSP_LED_Toggle(LED1);
/* This delay permit the key to see LED3 toggling */
HAL_Delay(25);
}
#else
while(1)
{
/* Initialize number of data variables */
hTxNumData = 0;
hRxNumData = 0;
/*##-2- Slave receive request from master ################################*/
while(HAL_I2C_Slave_Receive_IT(&I2cHandle, (uint8_t*)&bTransferRequest, 1)!= HAL_OK)
{
}
/* Before starting a new communication transfer, you need to check the current
state of the peripheral; if it’s busy you need to wait for the end of current
transfer before starting a new one.
For simplicity reasons, this example is just waiting till the end of the
transfer, but application may perform other tasks while transfer operation
is ongoing. */
while (HAL_I2C_GetState(&I2cHandle) != HAL_I2C_STATE_READY)
{
}
/* If master request write operation #####################################*/
if (bTransferRequest == MASTER_REQ_WRITE)
{
/*##-3- Slave receive number of data to be read ########################*/
while(HAL_I2C_Slave_Receive_IT(&I2cHandle, (uint8_t*)&hRxNumData, 2)!= HAL_OK);
示例7: main
/**
* @brief Main program.
* @param None
* @retval None
*/
int main(void)
{
/* STM32F0xx 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.
- Low Level Initialization
*/
HAL_Init();
/* Configure LED3 and LED4 and User push-button */
BSP_LED_Init(LED3);
BSP_LED_Init(LED4);
BSP_PB_Init(BUTTON_USER, BUTTON_MODE_EXTI);
/* Configure the system clock to 48 MHz */
SystemClock_Config();
/*##-1- Check if the system has resumed from WWDG reset ####################*/
if (__HAL_RCC_GET_FLAG(RCC_FLAG_WWDGRST) != RESET)
{
/* WWDGRST flag set: Turn LED3 on */
BSP_LED_On(LED3);
/* Clear reset flags */
__HAL_RCC_CLEAR_RESET_FLAGS();
}
else
{
/* WWDGRST flag is not set: Turn LED3 off */
BSP_LED_Off(LED3);
}
/*##-2- Configure the WWDG peripheral ######################################*/
/* WWDG clock counter = (PCLK1 (48MHz)/4096)/8) = 1464.8 Hz (~683 us)
WWDG Window value = 80 means that the WWDG counter should be refreshed only
when the counter is below 80 (and greater than 64 (63+1)) otherwise a reset will
be generated.
WWDG Counter value = 127, WWDG timeout = ~683 us * 64 = 43.7 ms */
WwdgHandle.Instance = WWDG;
WwdgHandle.Init.Prescaler = WWDG_PRESCALER_8;
WwdgHandle.Init.Window = 80;
WwdgHandle.Init.Counter = 127;
if (HAL_WWDG_Init(&WwdgHandle) != HAL_OK)
{
/* Initialization Error */
Error_Handler();
}
/*##-3- Start the WWDG #####################################################*/
if (HAL_WWDG_Start(&WwdgHandle) != HAL_OK)
{
Error_Handler();
}
/* Infinite loop */
while (1)
{
/* Toggle LED4 */
BSP_LED_Toggle(LED4);
/* Insert 40 ms delay */
HAL_Delay(40);
/* Refresh WWDG: update counter value to 127, the refresh window is:
refresh window between 32.1ms (~683 * (127-80)) and 43.7ms (~683 * 64) */
if (HAL_WWDG_Refresh(&WwdgHandle, 127) != HAL_OK)
{
Error_Handler();
}
}
}
示例8: ssl_client
//.........这里部分代码省略.........
{
printf( " failed\n\r" );
if( ( ret & BADCERT_EXPIRED ) != 0 )
printf( " ! server certificate has expired\n" );
if( ( ret & BADCERT_REVOKED ) != 0 )
printf( " ! server certificate has been revoked\n" );
if( ( ret & BADCERT_CN_MISMATCH ) != 0 )
printf( " ! CN mismatch (expected CN=%s)\n", "PolarSSL Server 1" );
if( ( ret & BADCERT_NOT_TRUSTED ) != 0 )
printf( " ! self-signed or not signed by a trusted CA\n" );
printf( "\n\r" );
}
else
printf( " ok\n\r" );
/*
* Write the GET request
*/
printf( " > Write to server:" );
len = sprintf( (char *) buf, GET_REQUEST );
while( ( ret = ssl_write( &ssl, buf, len ) ) <= 0 )
{
if( ret != POLARSSL_ERR_NET_WANT_READ && ret != POLARSSL_ERR_NET_WANT_WRITE )
{
printf( " failed\n ! ssl_write returned %d\n\n\r", ret );
goto exit;
}
}
len = ret;
printf( " %d bytes written\n\n\r%s", len, (char *) buf );
/*
* Read the HTTP response
*/
printf( " < Read from server:" );
do
{
len = sizeof( buf ) - 1;
memset( buf, 0, sizeof( buf ) );
ret = ssl_read( &ssl, buf, len );
if( ret == POLARSSL_ERR_NET_WANT_READ || ret == POLARSSL_ERR_NET_WANT_WRITE )
continue;
if( ret == POLARSSL_ERR_SSL_PEER_CLOSE_NOTIFY )
break;
if( ret < 0 )
{
printf( "failed\n\r ! ssl_read returned %d\n\n\r", ret );
break;
}
if( ret == 0 )
{
printf( "\n\nEOF\n\n\r" );
break;
}
len = ret;
printf( " %d bytes read\n\n\r%s", len, (char *) buf );
}
while( 1 );
exit:
#ifdef POLARSSL_ERROR_C
if( ret != 0 )
{
char error_buf[100];
error_strerror( ret, error_buf, 100 );
printf("Last error was: %d - %s\n\n\r", ret, error_buf );
}
#endif
x509_free( &cacert );
net_close( server_fd );
ssl_free( &ssl );
memset( &ssl, 0, sizeof( ssl ) );
/* Infinite loop */
for( ;; )
{
/* Toggle LED1 */
BSP_LED_Toggle(LED1);
/* Insert 400 ms delay */
osDelay(400);
}
}
示例9: main
/**
* @brief Main program
* @param None
* @retval None
*/
int main(void)
{
/* STM32F3xx 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 Green, Red and Orange LEDs */
BSP_LED_Init(LED_GREEN);
BSP_LED_Init(LED_RED);
BSP_LED_Init(LED_ORANGE);
/* Configure the system clock to 72 Mhz */
SystemClock_Config();
/* Enable Power Clock */
__PWR_CLK_ENABLE();
/* Check and handle if the system was resumed from StandBy mode */
if(__HAL_PWR_GET_FLAG(PWR_FLAG_SB) != RESET)
{
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB);
/* Turn on the Orange LED */
BSP_LED_On(LED_ORANGE);
uwStandByOutFlag = 1;
}
/* infinite loop */
while(1)
{
/* Configure User Button */
BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_EXTI);
UserButtonStatus = 0;
/* Wait until User button is pressed to enter the Low Power mode.
In the meantime, LED_GREEN is blinking */
while(UserButtonStatus == 0)
{
BSP_LED_Toggle(LED_GREEN);
HAL_Delay(100);
/* if exiting from stand-by mode,
keep LED_ORANGE ON for about 3 sec. */
if (uwStandByOutFlag > 0)
{
uwStandByOutFlag++;
if (uwStandByOutFlag == 30)
{
BSP_LED_Off(LED_ORANGE);
uwStandByOutFlag = 0;
}
}
/* if exiting from stop mode thru RTC alarm
interrupt, keep LED_ORANGE ON for about 3 sec. */
if (uwWakeUpIntFlag > 0)
{
uwWakeUpIntFlag++;
if (uwWakeUpIntFlag == 30)
{
BSP_LED_Off(LED_BLUE);
uwWakeUpIntFlag = 0;
}
}
}
/* Loop while Key button is maintained pressed */
while(BSP_PB_GetState(BUTTON_KEY) != SET) {}
/* Make sure LED_GREEN is turned off to
reduce low power mode consumption */
BSP_LED_Off(LED_GREEN);
#if defined (SLEEP_MODE)
/* Sleep Mode Entry
- System Running at PLL (72 MHz)
- Flash 2 wait state
- Instruction and Data caches ON
- Prefetch ON
- Code running from Internal FLASH
- All peripherals disabled.
- Wakeup using EXTI Line (Key Button PE.06)
*/
SleepMode_Measure();
#elif defined (STOP_MODE)
/* STOP Mode Entry
//.........这里部分代码省略.........
示例10: HAL_PWR_PVDCallback
/**
* @brief PWR PVD interrupt callback
* @param none
* @retval none
*/
void HAL_PWR_PVDCallback(void)
{
/* Toggle LED1 */
BSP_LED_Toggle(LED1);
}
示例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: main
/**
* @brief Main program
* @param None
* @retval None
*/
int main(void)
{
/* STM32F0xx 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.
- Low Level Initialization
*/
HAL_Init();
/* Configure LED2 */
BSP_LED_Init(LED2);
/* Configure the system clock to 48 MHz */
SystemClock_Config();
/*##-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;
UartHandle.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
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_USER, 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(&UartHandle, (uint8_t*)aTxBuffer, TXBUFFERSIZE, 5000)!= HAL_OK)
{
Error_Handler();
}
/*##-3- Put UART peripheral in reception process ###########################*/
if(HAL_UART_Receive(&UartHandle, (uint8_t *)aRxBuffer, RXBUFFERSIZE, 5000) != 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(&UartHandle, (uint8_t *)aRxBuffer, RXBUFFERSIZE, 0x1FFFFFF) != HAL_OK)
{
Error_Handler();
}
/*##-3- Start the transmission process #####################################*/
/* While the UART in reception process, user can transmit data through
//.........这里部分代码省略.........
示例13: main
/**
* @brief Main program
* @param None
* @retval None
*/
int main(void)
{
/* STM32F0xx 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.
- Low Level Initialization
*/
HAL_Init();
/* Configure LED */
BSP_LED_Init(LED2);
/* Configure the system clock to 48 MHz */
SystemClock_Config();
/* Enable Power Clock */
__HAL_RCC_PWR_CLK_ENABLE();
/* Check and handle if the system was resumed from StandBy mode */
if (__HAL_PWR_GET_FLAG(PWR_FLAG_SB) != RESET)
{
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB);
/* Configure User push-button */
BSP_PB_Init(BUTTON_USER, BUTTON_MODE_GPIO);
/* Turn on the LED2 and keep
it on for 2 sec. to indicate
exit from stand-by mode */
BSP_LED_On(LED2);
while(BSP_PB_GetState(BUTTON_USER) == GPIO_PIN_RESET){}
HAL_Delay(2000);
uwStandByOutFlag = 1;
}
/* Infinite loop */
while(1)
{
/* Configure User push-button as external interrupt generator */
BSP_PB_Init(BUTTON_USER, BUTTON_MODE_EXTI);
UserButtonStatus = 0;
/* Wait until User push-button is pressed to enter the Low Power mode.
In the meantime, LED2 is blinks */
while (UserButtonStatus == 0)
{
/* Toggle LED2 */
BSP_LED_Toggle(LED2);
HAL_Delay(100);
}
/* Make sure LED2 is turned off to
reduce low power mode consumption */
BSP_LED_Off(LED2);
#if defined (SLEEP_MODE)
/* Sleep Mode Entry
- System Running at PLL (48 MHz)
- Flash 2 wait state
- Instruction and Data caches ON
- Prefetch ON
- Code running from Internal FLASH
- All peripherals disabled.
- Wakeup using EXTI Line (User push-button PC.13)
*/
SleepMode_Measure();
#elif defined (STOP_RTC_MODE)
/* STOP Mode Entry
- RTC Clocked by LSI or LSE
- Regulator in LP mode
- HSI, HSE OFF and LSI OFF if not used as RTC Clock source
- No IWDG
- Automatic Wakeup using RTC clocked by LSI (after ~20s)
- Wakeup using EXTI Line (User push-button PC.13)
*/
StopRTCMode_Measure();
#elif defined (STANDBY_MODE)
/* STANDBY Mode Entry
- RTC OFF
- IWDG and LSI OFF
- Wakeup using WakeUp Pin PWR_WAKEUP_PIN2 connected to PC.13
*/
StandbyMode_Measure();
#elif defined (STANDBY_RTC_MODE)
/* STANDBY Mode with RTC on LSE/LSI Entry
- RTC Clocked by LSE or LSI
- IWDG OFF and LSI OFF if not used as RTC Clock source
- Automatic Wakeup using RTC clocked by LSE/LSI (after ~20s)
//.........这里部分代码省略.........
示例14: main
/**
* @brief Main program.
* @param None
* @retval None
*/
int main(void)
{
/* STM32F0xx 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.
- Low Level Initialization
*/
HAL_Init();
/* Configure LED2 */
BSP_LED_Init(LED2);
/* Configure the system clock to 48 MHz */
SystemClock_Config();
/*##-1- Configure the SPI peripheral #######################################*/
/* Set the SPI parameters */
SpiHandle.Instance = SPIx;
SpiHandle.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_256;
SpiHandle.Init.Direction = SPI_DIRECTION_2LINES;
SpiHandle.Init.CLKPhase = SPI_PHASE_1EDGE;
SpiHandle.Init.CLKPolarity = SPI_POLARITY_LOW;
SpiHandle.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
SpiHandle.Init.CRCPolynomial = 7;
SpiHandle.Init.DataSize = SPI_DATASIZE_8BIT;
SpiHandle.Init.FirstBit = SPI_FIRSTBIT_MSB;
SpiHandle.Init.NSS = SPI_NSS_SOFT;
SpiHandle.Init.TIMode = SPI_TIMODE_DISABLE;
SpiHandle.Init.NSSPMode = SPI_NSS_PULSE_DISABLE;
SpiHandle.Init.CRCLength = SPI_CRC_LENGTH_8BIT;
#ifdef MASTER_BOARD
SpiHandle.Init.Mode = SPI_MODE_MASTER;
#else
SpiHandle.Init.Mode = SPI_MODE_SLAVE;
#endif /* MASTER_BOARD */
if(HAL_SPI_Init(&SpiHandle) != HAL_OK)
{
/* Initialization Error */
Error_Handler();
}
#ifdef MASTER_BOARD
/* Configure User push-button */
BSP_PB_Init(BUTTON_USER, BUTTON_MODE_GPIO);
/* Wait for User push-button press before starting the Communication */
while (BSP_PB_GetState(BUTTON_USER) != GPIO_PIN_RESET)
{
BSP_LED_Toggle(LED2);
HAL_Delay(40);
}
BSP_LED_Off(LED2);
#endif /* MASTER_BOARD */
/*##-2- Start the Full Duplex Communication process ########################*/
/* While the SPI in TransmitReceive process, user can transmit data through
"aTxBuffer" buffer & receive data through "aRxBuffer" */
if(HAL_SPI_TransmitReceive_IT(&SpiHandle, (uint8_t*)aTxBuffer, (uint8_t *)aRxBuffer, BUFFERSIZE) != HAL_OK)
{
/* Transfer error in transmission process */
Error_Handler();
}
/*##-3- Wait for the end of the transfer ###################################*/
/* Before starting a new communication transfer, you need to check the current
state of the peripheral; if it’s busy you need to wait for the end of current
transfer before starting a new one.
For simplicity reasons, this example is just waiting till the end of the
transfer, but application may perform other tasks while transfer operation
is ongoing. */
while (HAL_SPI_GetState(&SpiHandle) != HAL_SPI_STATE_READY)
{
}
/*##-4- Compare the sent and received buffers ##############################*/
if(Buffercmp((uint8_t*)aTxBuffer, (uint8_t*)aRxBuffer, BUFFERSIZE))
{
/* Processing Error */
Error_Handler();
}
/* Infinite loop */
while (1)
{
}
}
示例15: main
/**
* @brief Main program
* @param None
* @retval None
*/
int main(void)
{
uint32_t index = 0;
RTC_TamperTypeDef stamperstructure;
/* STM32F4xx 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 180 MHz */
SystemClock_Config();
/* Configure LED1 and LED3 */
BSP_LED_Init(LED1);
BSP_LED_Init(LED3);
/* Configure User push-button button */
BSP_PB_Init(BUTTON_TAMPER, BUTTON_MODE_GPIO);
/*##-1- Configure the RTC peripheral #######################################*/
/* Configure RTC prescaler and RTC data registers */
/* RTC configured as follows:
- Hour Format = Format 24
- Asynch Prediv = Value according to source clock
- Synch Prediv = Value according to source clock
- OutPut = Output Disable
- OutPutPolarity = High Polarity
- OutPutType = Open Drain */
RtcHandle.Instance = RTC;
RtcHandle.Init.HourFormat = RTC_HOURFORMAT_24;
RtcHandle.Init.AsynchPrediv = RTC_ASYNCH_PREDIV;
RtcHandle.Init.SynchPrediv = RTC_SYNCH_PREDIV;
RtcHandle.Init.OutPut = RTC_OUTPUT_DISABLE;
RtcHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
RtcHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
if (HAL_RTC_Init(&RtcHandle) != HAL_OK)
{
/* Initialization Error */
Error_Handler();
}
/*##-2- Configure RTC Tamper ###############################################*/
stamperstructure.Tamper = RTC_TAMPER_1;
/* Use PC13 as Tamper 1 with interrupt mode */
stamperstructure.PinSelection = RTC_TAMPERPIN_PC13;
stamperstructure.Trigger = RTC_TAMPERTRIGGER_FALLINGEDGE;
stamperstructure.Filter = RTC_TAMPERFILTER_DISABLE;
stamperstructure.SamplingFrequency = RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV32768;
stamperstructure.PrechargeDuration = RTC_TAMPERPRECHARGEDURATION_1RTCCLK;
stamperstructure.TamperPullUp = RTC_TAMPER_PULLUP_ENABLE;
stamperstructure.TimeStampOnTamperDetection = RTC_TIMESTAMPONTAMPERDETECTION_DISABLE;
if (HAL_RTCEx_SetTamper_IT(&RtcHandle, &stamperstructure) != HAL_OK)
{
/* Initialization Error */
Error_Handler();
}
/* Clear the Tamper interrupt pending bit */
__HAL_RTC_TAMPER_CLEAR_FLAG(&RtcHandle,RTC_FLAG_TAMP1F);
/*##-3- Write Data on the Back Up registers ################################*/
for (index = 0; index < BACKUP_COUNT; index++)
{
HAL_RTCEx_BKUPWrite(&RtcHandle, aBKPDataReg[index], 0xDF59 + (index * 0x5A));
}
/*##-4- Check Data is stored on the Back Up registers ######################*/
for (index = 0; index < BACKUP_COUNT; index++)
{
if (HAL_RTCEx_BKUPRead(&RtcHandle, aBKPDataReg[index]) != (0xDF59 + (index * 0x5A)))
{
Error_Handler();
}
}
/*##-5- Wait for the tamper button is pressed ##############################*/
while (TamperStatus != SET)
{
/* Toggle LED1 with a period of 1s */
BSP_LED_Toggle(LED1);
/* Delay */
HAL_Delay(1000);
}
//.........这里部分代码省略.........