source: ctrl/firmware/Main/CubeMX/Core/Src/fdcan.c

Last change on this file was 114, checked in by Zed, 2 weeks ago

Fixing the project.

File size: 4.1 KB
Line 
1/* USER CODE BEGIN Header */
2/**
3  ******************************************************************************
4  * @file    fdcan.c
5  * @brief   This file provides code for the configuration
6  *          of the FDCAN instances.
7  ******************************************************************************
8  * @attention
9  *
10  * Copyright (c) 2025 STMicroelectronics.
11  * All rights reserved.
12  *
13  * This software is licensed under terms that can be found in the LICENSE file
14  * in the root directory of this software component.
15  * If no LICENSE file comes with this software, it is provided AS-IS.
16  *
17  ******************************************************************************
18  */
19/* USER CODE END Header */
20/* Includes ------------------------------------------------------------------*/
21#include "fdcan.h"
22
23/* USER CODE BEGIN 0 */
24
25/* USER CODE END 0 */
26
27FDCAN_HandleTypeDef hfdcan1;
28
29/* FDCAN1 init function */
30void MX_FDCAN1_Init(void)
31{
32
33  /* USER CODE BEGIN FDCAN1_Init 0 */
34
35  /* USER CODE END FDCAN1_Init 0 */
36
37  /* USER CODE BEGIN FDCAN1_Init 1 */
38
39  /* USER CODE END FDCAN1_Init 1 */
40  hfdcan1.Instance = FDCAN1;
41  hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC;
42  hfdcan1.Init.Mode = FDCAN_MODE_NORMAL;
43  hfdcan1.Init.AutoRetransmission = DISABLE;
44  hfdcan1.Init.TransmitPause = DISABLE;
45  hfdcan1.Init.ProtocolException = DISABLE;
46  hfdcan1.Init.NominalPrescaler = 16;
47  hfdcan1.Init.NominalSyncJumpWidth = 1;
48  hfdcan1.Init.NominalTimeSeg1 = 1;
49  hfdcan1.Init.NominalTimeSeg2 = 1;
50  hfdcan1.Init.DataPrescaler = 1;
51  hfdcan1.Init.DataSyncJumpWidth = 1;
52  hfdcan1.Init.DataTimeSeg1 = 1;
53  hfdcan1.Init.DataTimeSeg2 = 1;
54  hfdcan1.Init.MessageRAMOffset = 0;
55  hfdcan1.Init.StdFiltersNbr = 0;
56  hfdcan1.Init.ExtFiltersNbr = 0;
57  hfdcan1.Init.RxFifo0ElmtsNbr = 0;
58  hfdcan1.Init.RxFifo0ElmtSize = FDCAN_DATA_BYTES_8;
59  hfdcan1.Init.RxFifo1ElmtsNbr = 0;
60  hfdcan1.Init.RxFifo1ElmtSize = FDCAN_DATA_BYTES_8;
61  hfdcan1.Init.RxBuffersNbr = 0;
62  hfdcan1.Init.RxBufferSize = FDCAN_DATA_BYTES_8;
63  hfdcan1.Init.TxEventsNbr = 0;
64  hfdcan1.Init.TxBuffersNbr = 0;
65  hfdcan1.Init.TxFifoQueueElmtsNbr = 0;
66  hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION;
67  hfdcan1.Init.TxElmtSize = FDCAN_DATA_BYTES_8;
68  if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK)
69  {
70    Error_Handler();
71  }
72  /* USER CODE BEGIN FDCAN1_Init 2 */
73
74  /* USER CODE END FDCAN1_Init 2 */
75
76}
77
78void HAL_FDCAN_MspInit(FDCAN_HandleTypeDef* fdcanHandle)
79{
80
81  GPIO_InitTypeDef GPIO_InitStruct = {0};
82  RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
83  if(fdcanHandle->Instance==FDCAN1)
84  {
85  /* USER CODE BEGIN FDCAN1_MspInit 0 */
86
87  /* USER CODE END FDCAN1_MspInit 0 */
88
89  /** Initializes the peripherals clock
90  */
91    PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_FDCAN;
92    PeriphClkInitStruct.FdcanClockSelection = RCC_FDCANCLKSOURCE_PLL;
93    if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
94    {
95      Error_Handler();
96    }
97
98    /* FDCAN1 clock enable */
99    __HAL_RCC_FDCAN_CLK_ENABLE();
100
101    __HAL_RCC_GPIOD_CLK_ENABLE();
102    /**FDCAN1 GPIO Configuration
103    PD0     ------> FDCAN1_RX
104    PD1     ------> FDCAN1_TX
105    */
106    GPIO_InitStruct.Pin = CAN_RX_Pin|CAN_TX_Pin;
107    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
108    GPIO_InitStruct.Pull = GPIO_NOPULL;
109    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
110    GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN1;
111    HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
112
113  /* USER CODE BEGIN FDCAN1_MspInit 1 */
114
115  /* USER CODE END FDCAN1_MspInit 1 */
116  }
117}
118
119void HAL_FDCAN_MspDeInit(FDCAN_HandleTypeDef* fdcanHandle)
120{
121
122  if(fdcanHandle->Instance==FDCAN1)
123  {
124  /* USER CODE BEGIN FDCAN1_MspDeInit 0 */
125
126  /* USER CODE END FDCAN1_MspDeInit 0 */
127    /* Peripheral clock disable */
128    __HAL_RCC_FDCAN_CLK_DISABLE();
129
130    /**FDCAN1 GPIO Configuration
131    PD0     ------> FDCAN1_RX
132    PD1     ------> FDCAN1_TX
133    */
134    HAL_GPIO_DeInit(GPIOD, CAN_RX_Pin|CAN_TX_Pin);
135
136  /* USER CODE BEGIN FDCAN1_MspDeInit 1 */
137
138  /* USER CODE END FDCAN1_MspDeInit 1 */
139  }
140}
141
142/* USER CODE BEGIN 1 */
143
144/* USER CODE END 1 */
Note: See TracBrowser for help on using the repository browser.