Skip to content

Commit ea8bd60

Browse files
committed
add CAN config and msp initial code
1 parent 9111aca commit ea8bd60

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
@@ -213,6 +213,73 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
213213
}
214214

215215
}
216+
/**
217+
* @brief CAN MSP Initialization
218+
* This function configures the hardware resources used in this example
219+
* @param hcan: CAN handle pointer
220+
* @retval None
221+
*/
222+
void HAL_CAN_MspInit(CAN_HandleTypeDef* hcan)
223+
{
224+
GPIO_InitTypeDef GPIO_InitStruct = {0};
225+
if(hcan->Instance==CAN1)
226+
{
227+
/* USER CODE BEGIN CAN1_MspInit 0 */
228+
229+
/* USER CODE END CAN1_MspInit 0 */
230+
/* Peripheral clock enable */
231+
__HAL_RCC_CAN1_CLK_ENABLE();
232+
233+
__HAL_RCC_GPIOA_CLK_ENABLE();
234+
/**CAN GPIO Configuration
235+
PA11 ------> CAN_RX
236+
PA12 ------> CAN_TX
237+
*/
238+
GPIO_InitStruct.Pin = GPIO_PIN_11;
239+
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
240+
GPIO_InitStruct.Pull = GPIO_NOPULL;
241+
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
242+
243+
GPIO_InitStruct.Pin = GPIO_PIN_12;
244+
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
245+
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
246+
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
247+
248+
/* USER CODE BEGIN CAN1_MspInit 1 */
249+
250+
/* USER CODE END CAN1_MspInit 1 */
251+
}
252+
253+
}
254+
/**
255+
* @brief CAN MSP De-Initialization
256+
* This function freeze the hardware resources used in this example
257+
* @param hcan: CAN handle pointer
258+
* @retval None
259+
*/
260+
void HAL_CAN_MspDeInit(CAN_HandleTypeDef* hcan)
261+
{
262+
if(hcan->Instance==CAN1)
263+
{
264+
/* USER CODE BEGIN CAN1_MspDeInit 0 */
265+
266+
/* USER CODE END CAN1_MspDeInit 0 */
267+
/* Peripheral clock disable */
268+
__HAL_RCC_CAN1_CLK_DISABLE();
269+
270+
/**CAN GPIO Configuration
271+
PA11 ------> CAN_RX
272+
PA12 ------> CAN_TX
273+
*/
274+
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_11|GPIO_PIN_12);
275+
276+
/* USER CODE BEGIN CAN1_MspDeInit 1 */
277+
278+
/* USER CODE END CAN1_MspDeInit 1 */
279+
}
280+
281+
}
282+
216283

217284
/* USER CODE BEGIN 1 */
218285

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,18 @@ menu "On-chip Peripheral Drivers"
175175
bool "Enable ADC1"
176176
default n
177177
endif
178-
178+
menuconfig BSP_USING_CAN
179+
bool "Enable CAN"
180+
default n
181+
select RT_USING_CAN
182+
if BSP_USING_CAN
183+
config BSP_USING_CAN1
184+
bool "Enable CAN1"
185+
default n
186+
config BSP_USING_CAN2
187+
bool "Enable CAN2"
188+
default n
189+
endif
179190
config BSP_USING_ON_CHIP_FLASH
180191
bool "Enable on-chip FLASH"
181192
default n

0 commit comments

Comments
 (0)