标签/分类 "stm32" 下的文章
stm32 串口DMA配置
一、定义串口DMA缓存 #define UART2_MAX_LENGTH 255 uint8_t aU2DmaRxBuffer[UART2_MAX_LENGTH]; uint8_t aU2DmaTxBuffer[UART2_MAX_LENGTH]; // = "1234"; 二、串口基本初始化 UartHandle[Uart2].Instance = USART2; UartHandle[Uart2].Init.BaudRate = bute; UartHandle[Uart2].Init.WordLength = mx_get_uart_databit(databit); UartHandle[Uart2].Init.StopBits = UART_STOPBITS_1; UartHandle[Uart2].Init.Parity = mx_get_uart_paritybit(parity); UartHandle[Uart2].Init.Mode = UART_MODE_TX_RX; UartHandle[Uart2].Init.HwFlowCtl = UART_HWCONTROL_NONE; UartHandle[Uart2].Init.OverSampling = UART_OVERSAMPLING_16; UartHandle[Uart2].Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; UartHandle[Uart2].AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; if (HAL_UART_Init(&UartHandle[Uart2]) != HAL_OK) { Error_Handler(); } 三、打开串口空闲中断 __HAL_UART_ENABLE_IT(&UartHandle[Uart2], UART_IT_IDLE); 四、DMA初始化 找到 void HAL_UART_MspInit(UART_HandleTypeDef *uartHandle)函数,里面实现如下所示: __HAL_RCC_USART2_CLK_ENABLE(); #if UART2_DMA __HAL_RCC_DMA1_CLK_ENABLE(); #endif
STM32L073RZ -EEPROM 踩过的一些坑
代码 uint16_t bsp_eeprom_write (uint32_t WriteAddr, uint8_t *pBuffer, uint16_t NumToWrite) { uint16_t t,err = 0; assert_param( ( DATA_EEPROM_BASE + WriteAddr ) >= DATA_EEPROM_BASE ); assert_param( pBuffer != NULL ); if (HAL_FLASHEx_DATAEEPROM_Unlock()!= HAL_OK) { err |= EEPROM_UNLOCK_ERR; } for (t = 0; t < NumToWrite; t++) { if (HAL_FLASHEx_DATAEEPROM_Program (FLASH_TYPEPROGRAMDATA_BYTE, (DATA_EEPROM_BASE + WriteAddr + t), pBuffer[t])!=HAL_OK) { err |= EEPROM_PROGRAM_ERR; break; } } if (HAL_FLASHEx_DATAEEPROM_Lock() != HAL_OK) { err |= EEPROM_LOCK_ERR; } return err; } //PageRange 0-511 uint16_t bsp_eeprom_easer_page (uint16_t startPage, uint16_t endPage) { uint16_t t,err = 0; for (t = startPage ; t <= endPage; t++) { dbg_printf("-->[data ] DATA_EEPROM_BASE + WriteAddr + t:0X%X\r\n",DATA_EEPROM_BASE + t * 4); if (HAL_FLASHEx_DATAEEPROM_Erase (DATA_EEPROM_BASE + t * 4) !=HAL_OK) { err |= EEPROM_EASER_ERR;