本文整理汇总了C++中BSP_LED_On函数的典型用法代码示例。如果您正苦于以下问题:C++ BSP_LED_On函数的具体用法?C++ BSP_LED_On怎么用?C++ BSP_LED_On使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了BSP_LED_On函数的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 and LED3 */
BSP_LED_Init(LED1);
BSP_LED_Init(LED2);
BSP_LED_Init(LED3);
/*##-1- Configure the CRYP peripheral ######################################*/
/* Set the CRYP parameters */
CrypHandle.Instance = CRYP;
CrypHandle.Init.DataType = CRYP_DATATYPE_8B;
CrypHandle.Init.KeySize = CRYP_KEYSIZE_128B;
CrypHandle.Init.pKey = aAES128Key;
if(HAL_CRYP_Init(&CrypHandle) != HAL_OK)
{
/* Initialization Error */
Error_Handler();
}
/*##-2- Start the AES encryption in ECB chaining mode with DMA #############*/
if(HAL_CRYP_AESECB_Encrypt_DMA(&CrypHandle, aPlaintext, DATA_SIZE, aEncryptedText) != HAL_OK)
{
/* Processing Error */
Error_Handler();
}
/* Before starting a new process, 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
process, but application may perform other tasks while transfer operation
is ongoing. */
while (HAL_CRYP_GetState(&CrypHandle) != HAL_CRYP_STATE_READY)
{
}
/*##-3- Check the encrypted text with the expected one #####################*/
if(memcmp(aEncryptedText, aCyphertext, DATA_SIZE) != 0)
{
/* Wrong encryption: Turn LED2 on */
BSP_LED_On(LED2);
}
else
{
/* Right encryption: Turn LED1 on */
BSP_LED_On(LED1);
}
/* Deinitialize Crypto peripheral */
HAL_CRYP_DeInit(&CrypHandle);
/* Set the CRYP parameters */
CrypHandle.Init.DataType = CRYP_DATATYPE_8B;
CrypHandle.Init.KeySize = CRYP_KEYSIZE_128B;
CrypHandle.Init.pKey = aAES128Key;
if(HAL_CRYP_Init(&CrypHandle) != HAL_OK)
{
/* Initialization Error */
Error_Handler();
}
/*##-4- Start the AES decryption in ECB chaining mode with DMA #############*/
if(HAL_CRYP_AESECB_Decrypt_DMA(&CrypHandle, aEncryptedText, DATA_SIZE, aDecryptedText) != HAL_OK)
{
/* Processing Error */
Error_Handler();
}
/* Before starting a new process, 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
process, but application may perform other tasks while transfer operation
is ongoing. */
while (HAL_CRYP_GetState(&CrypHandle) != HAL_CRYP_STATE_READY)
{
}
/*##-5- Check the decrypted text with the expected one #####################*/
if(memcmp(aDecryptedText, aPlaintext, DATA_SIZE) != 0)
{
/* Wrong encryption: Turn LED2 on */
BSP_LED_On(LED2);
//.........这里部分代码省略.........
示例2: ethernetif_notify_conn_changed
/**
* @brief This function notify user about link status changement.
* @param netif: the network interface
* @retval None
*/
void ethernetif_notify_conn_changed(struct netif *netif)
{
struct ip_addr ipaddr;
struct ip_addr netmask;
struct ip_addr gw;
if(netif_is_link_up(netif))
{
#ifdef USE_DHCP
#ifndef USE_LCD
BSP_LED_Off(LED2);
BSP_LED_On(LED1);
#endif /* USE_LCD */
/* Update DHCP state machine */
DHCP_state = DHCP_START;
#else
IP4_ADDR(&ipaddr, IP_ADDR0, IP_ADDR1, IP_ADDR2, IP_ADDR3);
IP4_ADDR(&netmask, NETMASK_ADDR0, NETMASK_ADDR1 , NETMASK_ADDR2, NETMASK_ADDR3);
IP4_ADDR(&gw, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3);
#ifdef USE_LCD
uint8_t iptxt[20];
sprintf((char*)iptxt, " %d.%d.%d.%d", IP_ADDR0, IP_ADDR1, IP_ADDR2, IP_ADDR3);
BSP_LCD_ClearStringLine(7);
BSP_LCD_ClearStringLine(8);
BSP_LCD_ClearStringLine(9);
BSP_LCD_DisplayStringAtLine(8,(uint8_t *) " Static IP address:");
BSP_LCD_DisplayStringAtLine(9,(uint8_t *) iptxt);
#else
BSP_LED_Off(LED2);
BSP_LED_On(LED1);
#endif /* USE_LCD */
#endif /* USE_DHCP */
netif_set_addr(netif, &ipaddr , &netmask, &gw);
/* When the netif is fully configured this function must be called.*/
netif_set_up(netif);
}
else
{
#ifdef USE_DHCP
/* Update DHCP state machine */
DHCP_state = DHCP_LINK_DOWN;
#endif /* USE_DHCP */
/* When the netif link is down this function must be called.*/
netif_set_down(netif);
#ifdef USE_LCD
BSP_LCD_ClearStringLine(7);
BSP_LCD_ClearStringLine(8);
BSP_LCD_ClearStringLine(9);
BSP_LCD_DisplayStringAtLine(8,(uint8_t *) " The network cable");
BSP_LCD_DisplayStringAtLine(9,(uint8_t *) " is not connected");
#else
BSP_LED_Off(LED1);
BSP_LED_On(LED2);
#endif /* USE_LCD */
}
/* Clear IO Expander Interrupt flag */
BSP_IO_ITClear();
}
示例3: MSC_Application
/**
* @brief Main routine for Mass Storage Class
* @param None
* @retval None
*/
static void MSC_Application(void)
{
FRESULT res; /* FatFs function common result code */
uint32_t byteswritten, bytesread; /* File write/read counts */
uint8_t wtext[] = "This is STM32 working with FatFs"; /* File write buffer */
uint8_t rtext[100]; /* File read buffer */
/* Register the file system object to the FatFs module */
if(f_mount(&USBDISKFatFs, (TCHAR const*)USBDISKPath, 0) != FR_OK)
{
/* FatFs Initialization Error */
Error_Handler();
}
else
{
/* Create and Open a new text file object with write access */
if(f_open(&MyFile, "STM32.TXT", FA_CREATE_ALWAYS | FA_WRITE) != FR_OK)
{
/* 'STM32.TXT' file Open for write Error */
Error_Handler();
}
else
{
/* Write data to the text file */
res = f_write(&MyFile, wtext, sizeof(wtext), (void *)&byteswritten);
if((byteswritten == 0) || (res != FR_OK))
{
/* 'STM32.TXT' file Write or EOF Error */
Error_Handler();
}
else
{
/* Close the open text file */
f_close(&MyFile);
/* Open the text file object with read access */
if(f_open(&MyFile, "STM32.TXT", FA_READ) != FR_OK)
{
/* 'STM32.TXT' file Open for read Error */
Error_Handler();
}
else
{
/* Read data from the text file */
res = f_read(&MyFile, rtext, sizeof(rtext), (void *)&bytesread);
if((bytesread == 0) || (res != FR_OK))
{
/* 'STM32.TXT' file Read or EOF Error */
Error_Handler();
}
else
{
/* Close the open text file */
f_close(&MyFile);
/* Compare read data with the expected data */
if((bytesread != byteswritten))
{
/* Read data is different from the expected data */
Error_Handler();
}
else
{
/* Success of the demo: no error occurrence */
BSP_LED_On(LED1);
}
}
}
}
}
}
/* Unlink the USB disk I/O driver */
FATFS_UnLinkDriver(USBDISKPath);
}
示例4: 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)
{
}
}
示例5: HAL_SPI_ErrorCallback
/**
* @brief SPI error callbacks
* @param hspi: SPI handle
* @note This example shows a simple way to report transfer error, and you can
* add your own implementation.
* @retval None
*/
void HAL_SPI_ErrorCallback(SPI_HandleTypeDef *hspi)
{
/* Turn LED5 on: Transfer error in reception/transmission process */
BSP_LED_On(LED5);
}
示例6: BlueNRG_Init
static void BlueNRG_Init()
{
int rc;
uint8_t bdaddr[] = {0x12, 0x34, 0x00, 0xE1, 0x80, 0x02};
uint16_t service_handle, dev_name_char_handle, appearance_char_handle;
const char *ble_name = "BlueNRG";
BSP_LED_On(LED3);
HCI_Init();
/* Enable and set EXTI for BlueNRG IRQ */
HAL_NVIC_SetPriority(BLUENRG_IRQ_EXTI_IRQn, 2, 0);
HAL_NVIC_EnableIRQ(BLUENRG_IRQ_EXTI_IRQn);
BlueNRG_RST();
BSP_LED_On(LED4);
rc = aci_hal_write_config_data(CONFIG_DATA_PUBADDR_OFFSET,
CONFIG_DATA_PUBADDR_LEN, bdaddr);
while (rc) {
HAL_Delay(100);
BSP_LED_Toggle(LED4);
}
BSP_LED_On(LED5);
rc = aci_gatt_init();
while (rc) {
HAL_Delay(100);
BSP_LED_Toggle(LED5);
}
BSP_LED_On(LED6);
rc = aci_gap_init(1, &service_handle, &dev_name_char_handle,
&appearance_char_handle);
while (rc) {
HAL_Delay(100);
BSP_LED_Toggle(LED6);
}
BSP_LED_Off(LED3);
rc = aci_gatt_update_char_value(service_handle, dev_name_char_handle,
0, strlen(ble_name), (uint8_t *)ble_name);
while (rc) {
HAL_Delay(100);
BSP_LED_Toggle(LED3);
}
BSP_LED_Off(LED4);
rc = aci_gap_set_auth_requirement(MITM_PROTECTION_REQUIRED,
OOB_AUTH_DATA_ABSENT,
NULL,
7,
16,
USE_FIXED_PIN_FOR_PAIRING,
123456,
BONDING);
while (rc) {
HAL_Delay(100);
BSP_LED_Toggle(LED4);
}
/* sensors have been initialized in HW_Init() */
BSP_LED_Off(LED5);
rc = Add_Acc_Service();
while (rc) {
HAL_Delay(100);
BSP_LED_Toggle(LED5);
}
BSP_LED_Off(LED6);
rc = Add_Environmental_Sensor_Service();
while (rc) {
HAL_Delay(100);
BSP_LED_Toggle(LED6);
}
/* Init_User_Timer();
Start_User_Timer(); */
BSP_LED_On(LED3);
/* -2 dBm output power */
rc = aci_hal_set_tx_power_level(1, 4);
while (rc) {
HAL_Delay(100);
BSP_LED_Toggle(LED3);
}
}
示例7: DHCP_Process
/**
* @brief DHCP_Process_Handle
* @param None
* @retval None
*/
void DHCP_Process(struct netif *netif)
{
struct ip_addr ipaddr;
struct ip_addr netmask;
struct ip_addr gw;
uint32_t IPaddress = 0;
switch (DHCP_state)
{
case DHCP_START:
{
netif->ip_addr.addr = 0;
netif->netmask.addr = 0;
netif->gw.addr = 0;
IPaddress = 0;
DHCP_state = DHCP_WAIT_ADDRESS;
dhcp_start(netif);
#ifdef USE_LCD
LCD_UsrLog (" State: Looking for DHCP sever ...\n");
#endif
}
break;
case DHCP_WAIT_ADDRESS:
{
/* Read the new IP address */
IPaddress = netif->ip_addr.addr;
if (IPaddress !=0)
{
DHCP_state = DHCP_ADDRESS_ASSIGNED;
/* Stop DHCP */
dhcp_stop(netif);
#ifdef USE_LCD
uint8_t iptab[4];
uint8_t iptxt[20];
iptab[0] = (uint8_t)(IPaddress >> 24);
iptab[1] = (uint8_t)(IPaddress >> 16);
iptab[2] = (uint8_t)(IPaddress >> 8);
iptab[3] = (uint8_t)(IPaddress);
sprintf((char*)iptxt, "%d.%d.%d.%d", iptab[3], iptab[2], iptab[1], iptab[0]);
LCD_UsrLog ("IP address assigned by a DHCP server: %s\n", iptxt);
#else
BSP_LED_On(LED1);
#endif
}
else
{
/* DHCP timeout */
if (netif->dhcp->tries > MAX_DHCP_TRIES)
{
DHCP_state = DHCP_TIMEOUT;
/* Stop DHCP */
dhcp_stop(netif);
/* Static address used */
IP4_ADDR(&ipaddr, IP_ADDR0 ,IP_ADDR1 , IP_ADDR2 , IP_ADDR3 );
IP4_ADDR(&netmask, NETMASK_ADDR0, NETMASK_ADDR1, NETMASK_ADDR2, NETMASK_ADDR3);
IP4_ADDR(&gw, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3);
netif_set_addr(netif, &ipaddr , &netmask, &gw);
#ifdef USE_LCD
uint8_t iptxt[20];
sprintf((char*)iptxt, "%d.%d.%d.%d", IP_ADDR0, IP_ADDR1, IP_ADDR2, IP_ADDR3);
LCD_UsrLog ("DHCP timeout !!\n");
LCD_UsrLog ("Static IP address : %s\n", iptxt);
#else
BSP_LED_On(LED1);
#endif
}
}
}
示例8: HAL_SPI_TxRxCpltCallback
/**
* @brief TxRx Transfer completed callback.
* @param hspi: SPI handle
* @note This example shows a simple way to report end of Interrupt TxRx transfer, and
* you can add your own implementation.
* @retval None
*/
void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi)
{
/* Turn LED on: Transfer in transmission/reception process is correct */
BSP_LED_On(LED2);
}
示例9: main
/**
* @brief Main program
* @param None
* @retval None
*/
int main(void)
{
/* STM32L0xx HAL library initialization:
- Configure the Flash prefetch, Flash preread and Buffer 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.
- Low Level Initialization
*/
HAL_Init();
/*******************************************************************************
* Common Configuration Routines *
*******************************************************************************/
/* Configure LED2 and Key Button */
BSP_LED_Init(LED2);
BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_EXTI);
/* Configure the system clock to 32 Mhz */
SystemClock_Config();
/*##-1- Check if the system has resumed from IWDG reset ####################*/
if (__HAL_RCC_GET_FLAG(RCC_FLAG_IWDGRST) != RESET)
{
/* IWDGRST flag set: Turn LED2 on */
BSP_LED_On(LED2);
/* Insert 4s delay */
HAL_Delay(4000);
/* Clear reset flags */
__HAL_RCC_CLEAR_RESET_FLAGS();
}
else
{
/* IWDGRST flag is not set: Turn LED2 off */
BSP_LED_Off(LED2);
}
/*##-2- Get the LSI frequency: TIM21 is used to measure the LSI frequency ###*/
uwLsiFreq = GetLSIFrequency();
/*##-3- Configure & Initialize the IWDG peripheral ######################################*/
/* Set counter reload value to obtain 250ms IWDG TimeOut.
IWDG counter clock Frequency = LsiFreq/32
Counter Reload Value = 250ms/IWDG counter clock period
= 0.25s / (32/LsiFreq)
= LsiFreq/(32 * 4)
= LsiFreq/128 */
IwdgHandle.Instance = IWDG;
IwdgHandle.Init.Prescaler = IWDG_PRESCALER_32;
IwdgHandle.Init.Reload = uwLsiFreq/128;
IwdgHandle.Init.Window = IWDG_WINDOW_DISABLE;
if(HAL_IWDG_Init(&IwdgHandle) != HAL_OK)
{
/* Initialization Error */
Error_Handler();
}
/*##-4- Start the IWDG #####################################################*/
if(HAL_IWDG_Start(&IwdgHandle) != HAL_OK)
{
Error_Handler();
}
/* Infinite loop */
while (1)
{
/* Toggle LED2 */
BSP_LED_Toggle(LED2);
/* Insert 240 ms delay */
HAL_Delay(240);
/* Refresh IWDG: reload counter */
if(HAL_IWDG_Refresh(&IwdgHandle) != HAL_OK)
{
/* Refresh Error */
Error_Handler();
}
}
}
示例10: 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 the system clock to 72 MHz */
SystemClock_Config();
/* Initialize LED5, LED6 and LED4 */
BSP_LED_Init(LED5);
BSP_LED_Init(LED6);
BSP_LED_Init(LED4);
/* Initialize test status */
MemoryProgramStatus = PASSED;
/* Unlock the Flash to enable the flash control register access *************/
HAL_FLASH_Unlock();
/* Unlock the Options Bytes *************************************************/
HAL_FLASH_OB_Unlock();
/* Get pages write protection status ****************************************/
HAL_FLASHEx_OBGetConfig(&OptionsBytesStruct);
#ifdef WRITE_PROTECTION_DISABLE
/* Check if desired pages are already write protected ***********************/
if((OptionsBytesStruct.WRPPage & FLASH_PAGE_TO_BE_PROTECTED) != FLASH_PAGE_TO_BE_PROTECTED)
{
/* Restore write protected pages */
OptionsBytesStruct.OptionType = OPTIONBYTE_WRP;
OptionsBytesStruct.WRPState = OB_WRPSTATE_DISABLE;
OptionsBytesStruct.WRPPage = FLASH_PAGE_TO_BE_PROTECTED;
if(HAL_FLASHEx_OBProgram(&OptionsBytesStruct) != HAL_OK)
{
/* Error occurred while options bytes programming. **********************/
while (1)
{
BSP_LED_On(LED4);
}
}
/* Generate System Reset to load the new option byte values ***************/
HAL_FLASH_OB_Launch();
}
#elif defined WRITE_PROTECTION_ENABLE
/* Check if desired pages are not yet write protected ***********************/
if(((~OptionsBytesStruct.WRPPage) & FLASH_PAGE_TO_BE_PROTECTED )!= FLASH_PAGE_TO_BE_PROTECTED)
{
/* Enable the pages write protection **************************************/
OptionsBytesStruct.OptionType = OPTIONBYTE_WRP;
OptionsBytesStruct.WRPState = OB_WRPSTATE_ENABLE;
OptionsBytesStruct.WRPPage = FLASH_PAGE_TO_BE_PROTECTED;
if(HAL_FLASHEx_OBProgram(&OptionsBytesStruct) != HAL_OK)
{
/* Error occurred while options bytes programming. **********************/
while (1)
{
BSP_LED_On(LED4);
}
}
/* Generate System Reset to load the new option byte values ***************/
HAL_FLASH_OB_Launch();
}
#endif /* WRITE_PROTECTION_DISABLE */
/* Lock the Options Bytes *************************************************/
HAL_FLASH_OB_Lock();
/* The selected pages are not write protected *******************************/
if ((OptionsBytesStruct.WRPPage & FLASH_PAGE_TO_BE_PROTECTED) != 0x00)
{
/* Fill EraseInit structure************************************************/
EraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES;
EraseInitStruct.PageAddress = FLASH_USER_START_ADDR;
EraseInitStruct.NbPages = (FLASH_USER_END_ADDR - FLASH_USER_START_ADDR)/FLASH_PAGE_SIZE;
if (HAL_FLASHEx_Erase(&EraseInitStruct, &PageError) != HAL_OK)
{
/*
Error occurred while page erase.
User can add here some code to deal with this error.
PageError will contain the faulty page and then to know the code error on this page,
user can call function 'HAL_FLASH_GetError()'
*/
//.........这里部分代码省略.........
示例11: 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 */
BSP_LED_Init(LED3);
/* Configure the system clock to 48 MHz */
SystemClock_Config();
#ifdef BOARD_IN_STOP_MODE
/* HSI must be UART clock source to be able to wake up the MCU */
USARTx_RCC_CONFIG(RCC_USARTxCLKSOURCE_HSI);
#endif
/*##-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;
HAL_UART_DeInit(&UartHandle);
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_Init(&UartHandle) != HAL_OK)
{
Error_Handler();
}
#ifdef BOARD_IN_STOP_MODE
BSP_LED_On(LED3);
/* wait for two seconds before test start */
HAL_Delay(2000);
/* make sure that no UART transfer is on-going */
while(__HAL_UART_GET_FLAG(&UartHandle, USART_ISR_BUSY) == SET);
/* make sure that UART is ready to receive
* (test carried out again later in HAL_UARTEx_StopModeWakeUpSourceConfig) */
while(__HAL_UART_GET_FLAG(&UartHandle, USART_ISR_REACK) == RESET);
/* set the wake-up event:
* specify wake-up on RXNE flag */
WakeUpSelection.WakeUpEvent = UART_WAKEUP_ON_READDATA_NONEMPTY;
if (HAL_UARTEx_StopModeWakeUpSourceConfig(&UartHandle, WakeUpSelection)!= HAL_OK)
{
Error_Handler();
}
/* Enable the UART Wake UP from stop mode Interrupt */
__HAL_UART_ENABLE_IT(&UartHandle, UART_IT_WUF);
/* about to enter stop mode: switch off LED */
BSP_LED_Off(LED3);
/* enable MCU wake-up by UART */
HAL_UARTEx_EnableStopMode(&UartHandle);
/* enter stop mode */
HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
/* ... STOP mode ... */
SystemClock_Config_fromSTOP();
/* at that point, MCU has been awoken: the LED has been turned back on */
/* Wake Up based on RXNE flag successful */
HAL_UARTEx_DisableStopMode(&UartHandle);
/* wait for some delay */
HAL_Delay(100);
/* Inform other board that wake up is successful */
if (HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBuffer1, COUNTOF(aTxBuffer1)-1, 5000)!= HAL_OK)
//.........这里部分代码省略.........
示例12: main
//.........这里部分代码省略.........
/* Configure LED1 and LED3 */
BSP_LED_Init(LED1);
BSP_LED_Init(LED3);
/* Configure the system clock to 48 MHz */
SystemClock_Config();
/*##-1- Link the micro SD disk I/O driver ##################################*/
if(FATFS_LinkDriver(&SD_Driver, SDPath) == 0)
{
/*##-2- Register the file system object to the FatFs module ##############*/
if(f_mount(&SDFatFs, (TCHAR const*)SDPath, 0) != FR_OK)
{
/* FatFs Initialization Error */
Error_Handler();
}
else
{
/*##-3- Create a FAT file system (format) on the logical drive #########*/
/* WARNING: Formatting the uSD card will delete all content on the device */
if(f_mkfs((TCHAR const*)SDPath, 0, 0) != FR_OK)
{
/* FatFs Format Error */
Error_Handler();
}
else
{
/*##-4- Create and Open a new text file object with write access #####*/
if(f_open(&MyFile, "STM32.TXT", FA_CREATE_ALWAYS | FA_WRITE) != FR_OK)
{
/* 'STM32.TXT' file Open for write Error */
Error_Handler();
}
else
{
/*##-5- Write data to the text file ################################*/
res = f_write(&MyFile, wtext, sizeof(wtext), (void *)&byteswritten);
/*##-6- Close the open text file #################################*/
if (f_close(&MyFile) != FR_OK )
{
Error_Handler();
}
if((byteswritten == 0) || (res != FR_OK))
{
/* 'STM32.TXT' file Write or EOF Error */
Error_Handler();
}
else
{
/*##-7- Open the text file object with read access ###############*/
if(f_open(&MyFile, "STM32.TXT", FA_READ) != FR_OK)
{
/* 'STM32.TXT' file Open for read Error */
Error_Handler();
}
else
{
/*##-8- Read data from the text file ###########################*/
res = f_read(&MyFile, rtext, sizeof(rtext), (UINT*)&bytesread);
if((bytesread == 0) || (res != FR_OK))
{
/* 'STM32.TXT' file Read or EOF Error */
Error_Handler();
}
else
{
/*##-9- Close the open text file #############################*/
f_close(&MyFile);
/*##-10- Compare read data with the expected data ############*/
if((bytesread != byteswritten))
{
/* Read data is different from the expected data */
Error_Handler();
}
else
{
/* Success of the demo: no error occurrence */
BSP_LED_On(LED1);
}
}
}
}
}
}
}
}
/*##-11- Unlink the RAM disk I/O driver ####################################*/
FATFS_UnLinkDriver(SDPath);
/* Infinite loop */
while (1)
{
}
}
示例13: main
/**
* @brief Main program
* @param None
* @retval None
*/
int main(void)
{
/* Enable the CPU Cache */
CPU_CACHE_Enable();
/* STM32F7xx HAL library initialization:
- Configure the Flash ART accelerator on ITCM interface
- 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 216 MHz */
SystemClock_Config();
/* Initialize LED1, LED2, LED4 and LED3 */
BSP_LED_Init(LED1);
BSP_LED_Init(LED2);
BSP_LED_Init(LED4);
BSP_LED_Init(LED3);
/*##-1- Configure the CRYP peripheral ######################################*/
CrypHandle.Instance = CRYP;
/* Set the CRYP parameters */
CrypHandle.Init.DataType = CRYP_DATATYPE_8B;
CrypHandle.Init.KeySize = CRYP_KEYSIZE_128B;
CrypHandle.Init.pKey = aAES128Key;
if(HAL_CRYP_Init(&CrypHandle) != HAL_OK)
{
/* Initialization Error */
Error_Handler();
}
/*##-2- Start the AES encryption in ECB chaining mode with DMA #############*/
if(HAL_CRYP_AESECB_Encrypt_DMA(&CrypHandle, aPlaintext, DATA_SIZE, aEncryptedText) != HAL_OK)
{
/* Processing Error */
Error_Handler();
}
/* Before starting a new process, 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
process, but application may perform other tasks while transfer operation
is ongoing. */
while (HAL_CRYP_GetState(&CrypHandle) != HAL_CRYP_STATE_READY)
{
}
/*##-3- Check the encrypted text with the expected one #####################*/
if(memcmp(aEncryptedText, aCyphertext, DATA_SIZE) != 0)
{
/* Wrong encryption: Turn LED2 on */
BSP_LED_On(LED2);
}
else
{
/* Right encryption: Turn LED1 on */
BSP_LED_On(LED1);
}
/* Deinitialize Crypto peripheral */
HAL_CRYP_DeInit(&CrypHandle);
/* Set the CRYP parameters */
CrypHandle.Init.DataType = CRYP_DATATYPE_8B;
CrypHandle.Init.KeySize = CRYP_KEYSIZE_128B;
CrypHandle.Init.pKey = aAES128Key;
if(HAL_CRYP_Init(&CrypHandle) != HAL_OK)
{
/* Initialization Error */
Error_Handler();
}
/*##-4- Start the AES decryption in ECB chaining mode with DMA #############*/
if(HAL_CRYP_AESECB_Decrypt_DMA(&CrypHandle, aEncryptedText, DATA_SIZE, aDecryptedText) != HAL_OK)
{
/* Processing Error */
Error_Handler();
}
/* Before starting a new process, 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
process, but application may perform other tasks while transfer operation
is ongoing. */
while (HAL_CRYP_GetState(&CrypHandle) != HAL_CRYP_STATE_READY)
//.........这里部分代码省略.........
示例14: main
/**
* @brief Main program
* @param None
* @retval None
*/
int main(void)
{
/* STM32L0xx HAL library initialization:
- Configure the Flash prefetch, Flash preread and Buffer 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.
- Low Level Initialization
*/
HAL_Init();
/* Configure the system clock to have a system clock 2 Mhz */
SystemClock_Config();
/* Initialize LED3 */
BSP_LED_Init(LED3);
/* Unlock the Flash to enable the flash control register access *************/
HAL_FLASH_Unlock();
/* Unlock the Options Bytes *************************************************/
HAL_FLASH_OB_Unlock();
/* Get pages write protection status ****************************************/
HAL_FLASHEx_OBGetConfig(&OptionsBytesStruct);
#ifdef WRITE_PROTECTION_DISABLE
/* Get pages already write protected ****************************************/
ProtectedPages = OptionsBytesStruct.WRPSector | FLASH_SECTORS_TO_BE_PROTECTED;
/* Check if there is write protected pages ********************************/
if(ProtectedPages != 0x0)
{
/* Restore write protected pages */
OptionsBytesStruct.OptionType = OPTIONBYTE_WRP;
OptionsBytesStruct.WRPState = WRPSTATE_DISABLE;
OptionsBytesStruct.WRPSector = ProtectedPages;
if(HAL_FLASHEx_OBProgram(&OptionsBytesStruct) != HAL_OK)
{
/* Error occurred while options bytes programming. **********************/
while (1)
{
BSP_LED_On(LED3);
}
}
}
/* Generate System Reset to load the new option byte values ***************/
HAL_FLASH_OB_Launch();
#elif defined WRITE_PROTECTION_ENABLE
/* Get current write protected pages and the new pages to be protected ******/
ProtectedPages = OptionsBytesStruct.WRPSector | FLASH_SECTORS_TO_BE_PROTECTED;
/* Check if desired pages are not yet write protected ***********************/
if((OptionsBytesStruct.WRPSector & FLASH_SECTORS_TO_BE_PROTECTED )!= FLASH_SECTORS_TO_BE_PROTECTED)
{
/* Enable the pages write protection **************************************/
OptionsBytesStruct.OptionType = OPTIONBYTE_WRP;
OptionsBytesStruct.WRPState = WRPSTATE_ENABLE;
OptionsBytesStruct.WRPSector = ProtectedPages;
if(HAL_FLASHEx_OBProgram(&OptionsBytesStruct) != HAL_OK)
{
/* Error occurred while options bytes programming. **********************/
while (1)
{
BSP_LED_On(LED3);
}
}
/* Generate System Reset to load the new option byte values ***************/
HAL_FLASH_OB_Launch();
}
#endif /* WRITE_PROTECTION_DISABLE */
/* Lock the Options Bytes *************************************************/
HAL_FLASH_OB_Lock();
#ifdef FLASH_PAGE_PROGRAM
/* The selected pages are not write protected *******************************/
if ((OptionsBytesStruct.WRPSector & FLASH_SECTORS_TO_BE_PROTECTED) == 0x00)
{
/* Fill EraseInit structure************************************************/
EraseInitStruct.TypeErase = TYPEERASE_PAGEERASE;
EraseInitStruct.Page = FLASH_USER_START_ADDR;
EraseInitStruct.NbPages = (FLASH_USER_END_ADDR - FLASH_USER_START_ADDR)/FLASH_PAGE_SIZE;
if (HAL_FLASHEx_Erase(&EraseInitStruct, &PageError) != HAL_OK)
{
/*
Error occurred while page erase.
//.........这里部分代码省略.........
示例15: 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 180 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);
/* Initialize the Push buttons */
/* Wakeup button used for Volume Low */
BSP_PB_Init(BUTTON_WAKEUP, BUTTON_MODE_GPIO);
/* Tamper button used for Volume High */
BSP_PB_Init(BUTTON_TAMPER, BUTTON_MODE_GPIO);
/* Initialize the LCD */
BSP_LCD_Init();
BSP_LCD_LayerDefaultInit(1, 0xC0130000);
BSP_LCD_SelectLayer(1);
/* Display message on EVAL LCD **********************************************/
/* Clear the LCD */
BSP_LCD_Clear(LCD_COLOR_BLUE);
/* Set the LCD Back Color */
BSP_LCD_SetBackColor(LCD_COLOR_BLUE);
/* Set the LCD Text Color */
BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
BSP_LCD_DisplayStringAt(0, LINE(0), (uint8_t *)MESSAGE1, CENTER_MODE);
BSP_LCD_DisplayStringAt(0, LINE(1), (uint8_t *)MESSAGE2, CENTER_MODE);
BSP_LCD_DisplayStringAt(0, LINE(2), (uint8_t *)MESSAGE3, CENTER_MODE);
/* Turn on LEDs available on EVAL *******************************************/
BSP_LED_On(LED1);
BSP_LED_On(LED2);
BSP_LED_On(LED3);
BSP_LED_On(LED4);
/* Initialize the Audio codec and all related peripherals (SAI, I2C, IOs...) */
if(AUDIO_Init() == AUDIO_ERROR_NONE)
{
BSP_LCD_DisplayStringAt(0, LINE(4), (uint8_t *)"====================", CENTER_MODE);
BSP_LCD_DisplayStringAt(0, LINE(5), (uint8_t *)"Tamper: Vol+ ", CENTER_MODE);
BSP_LCD_DisplayStringAt(0, LINE(6), (uint8_t *)"Wakeup: Vol- ", CENTER_MODE);
BSP_LCD_DisplayStringAt(0, LINE(7), (uint8_t *)"====================", CENTER_MODE);
BSP_LCD_DisplayStringAt(0, LINE(8), (uint8_t *)" AUDIO CODEC OK ", CENTER_MODE);
}
else
{
BSP_LCD_DisplayStringAt(0, LINE(4), (uint8_t *)" AUDIO CODEC FAIL ", CENTER_MODE);
BSP_LCD_DisplayStringAt(0, LINE(5), (uint8_t *)" Try to reset board ", CENTER_MODE);
}
/*
Start playing the file from a circular buffer, once the DMA is enabled, it is
always in running state. Application has to fill the buffer with the audio data
using Transfer complete and/or half transfer complete interrupts callbacks
(EVAL_AUDIO_TransferComplete_CallBack() or EVAL_AUDIO_HalfTransfer_CallBack()...
*/
AUDIO_Start();
/* Display the state on the screen */
BSP_LCD_DisplayStringAt(0, LINE(9), (uint8_t *)" PLAYING... ", CENTER_MODE);
/* IMPORTANT:
AUDIO_Process() is called by the SysTick Handler, as it should be called
within a periodic process */
/* Infinite loop */
while(1)
{
/* Check on the Volume high button */
if (BSP_PB_GetState(BUTTON_WAKEUP) != RESET)
{
/* Wait to avoid rebound */
while (BSP_PB_GetState(BUTTON_WAKEUP) != RESET);
/* Decrease volume by 5% */
if (uwVolume > 5)
uwVolume -= 5;
else
//.........这里部分代码省略.........