Skip to content

Commit 6c6b385

Browse files
BernardXionggitee-org
authored andcommitted
!30 增加CAN配置和使用CubeMx生成的CAN模块Mspinit代码
Merge pull request !30 from sgf201/addCanConfit
2 parents 69258cd + b3f1bf1 commit 6c6b385

File tree

3 files changed

+80
-2
lines changed

3 files changed

+80
-2
lines changed

bsp/stm32/stm32f103-atk-warshipv3/board/CubeMX_Config/Inc/stm32f1xx_hal_conf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#define HAL_MODULE_ENABLED
3636
/*#define HAL_ADC_MODULE_ENABLED */
3737
/*#define HAL_CRYP_MODULE_ENABLED */
38-
/*#define HAL_CAN_MODULE_ENABLED */
38+
#define HAL_CAN_MODULE_ENABLED
3939
/*#define HAL_CAN_LEGACY_MODULE_ENABLED */
4040
/*#define HAL_CEC_MODULE_ENABLED */
4141
/*#define HAL_CORTEX_MODULE_ENABLED */

bsp/stm32/stm32f103-atk-warshipv3/board/CubeMX_Config/Src/stm32f1xx_hal_msp.c

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,73 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
294294
}
295295

296296
}
297+
/**
298+
* @brief CAN MSP Initialization
299+
* This function configures the hardware resources used in this example
300+
* @param hcan: CAN handle pointer
301+
* @retval None
302+
*/
303+
void HAL_CAN_MspInit(CAN_HandleTypeDef* hcan)
304+
{
305+
GPIO_InitTypeDef GPIO_InitStruct = {0};
306+
if(hcan->Instance==CAN1)
307+
{
308+
/* USER CODE BEGIN CAN1_MspInit 0 */
309+
310+
/* USER CODE END CAN1_MspInit 0 */
311+
/* Peripheral clock enable */
312+
__HAL_RCC_CAN1_CLK_ENABLE();
313+
314+
__HAL_RCC_GPIOA_CLK_ENABLE();
315+
/**CAN GPIO Configuration
316+
PA11 ------> CAN_RX
317+
PA12 ------> CAN_TX
318+
*/
319+
GPIO_InitStruct.Pin = GPIO_PIN_11;
320+
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
321+
GPIO_InitStruct.Pull = GPIO_NOPULL;
322+
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
323+
324+
GPIO_InitStruct.Pin = GPIO_PIN_12;
325+
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
326+
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
327+
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
328+
329+
/* USER CODE BEGIN CAN1_MspInit 1 */
330+
331+
/* USER CODE END CAN1_MspInit 1 */
332+
}
333+
334+
}
335+
/**
336+
* @brief CAN MSP De-Initialization
337+
* This function freeze the hardware resources used in this example
338+
* @param hcan: CAN handle pointer
339+
* @retval None
340+
*/
341+
void HAL_CAN_MspDeInit(CAN_HandleTypeDef* hcan)
342+
{
343+
if(hcan->Instance==CAN1)
344+
{
345+
/* USER CODE BEGIN CAN1_MspDeInit 0 */
346+
347+
/* USER CODE END CAN1_MspDeInit 0 */
348+
/* Peripheral clock disable */
349+
__HAL_RCC_CAN1_CLK_DISABLE();
350+
351+
/**CAN GPIO Configuration
352+
PA11 ------> CAN_RX
353+
PA12 ------> CAN_TX
354+
*/
355+
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_11|GPIO_PIN_12);
356+
357+
/* USER CODE BEGIN CAN1_MspDeInit 1 */
358+
359+
/* USER CODE END CAN1_MspDeInit 1 */
360+
}
361+
362+
}
363+
297364

298365
static uint32_t FSMC_Initialized = 0;
299366

bsp/stm32/stm32f103-atk-warshipv3/board/Kconfig

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,18 @@ menu "On-chip Peripheral Drivers"
188188
bool "Enable ADC1"
189189
default n
190190
endif
191-
191+
menuconfig BSP_USING_CAN
192+
bool "Enable CAN"
193+
default n
194+
select RT_USING_CAN
195+
if BSP_USING_CAN
196+
config BSP_USING_CAN1
197+
bool "Enable CAN1"
198+
default n
199+
config BSP_USING_CAN2
200+
bool "Enable CAN2"
201+
default n
202+
endif
192203
config BSP_USING_ON_CHIP_FLASH
193204
bool "Enable on-chip FLASH"
194205
default n

0 commit comments

Comments
 (0)