cancel
Showing results for 
Search instead for 
Did you mean: 

Fatal error stm32h7xx_hal_can.h: No such file or directory

Dragonmonkey
Associate II

Please help how I can find this library.

STM32-H7A3ZI-Q with latest STM32CubeIDE

1 ACCEPTED SOLUTION

Accepted Solutions

Hello,

There is no stm32h7xx_hal_can.h in H7 cube HAL. You need to use FDCAN (stm32h7xx_hal_fdcan.h).

You need to use FDCAN peripheral in classic mode as a replacement of bxCAN.

Refer to this example: https://github.com/STMicroelectronics/STM32CubeH7/tree/b9d11df3020deef82310c88f3d8590d076b43ef7/Projects/STM32H743I-EVAL/Examples/FDCAN/FDCAN_Classic_Frame_Networking

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

View solution in original post

6 REPLIES 6
TDK
Guru

There is no such file.

There is stm32h7xx_hal_fdcan.h, which you can find here:

https://github.com/STMicroelectronics/stm32h7xx_hal_driver/blob/a13c7d54ce2a8493b3c2a4ae591953afee1ce5c2/Inc/stm32h7xx_hal_fdcan.h

If you initialize an FDCAN peripheral within your IOC file and generate code, CubeMX will put this file in your project.

If you feel a post has answered your question, please click "Accept as Solution".

My friend sent me the code with #include "stm32h7xx_hal_can.h"

But no way I can find it.

Dragonmonkey
Associate II

Here ia the code sample

#include "stm32h7xx_hal.h"

#include "stm32h7xx_hal_adc.h"

#include "stm32h7xx_hal_can.h"

 

ADC_HandleTypeDef hadc1;

CAN_HandleTypeDef hcan1;

 

void SystemClock_Config(void);

static void MX_GPIO_Init(void);

static void MX_ADC1_Init(void);

static void MX_CAN1_Init(void);

 

int main(void) {

  HAL_Init();

  SystemClock_Config();

  MX_GPIO_Init();

  MX_ADC1_Init();

  MX_CAN1_Init();

 

  uint16_t adc_value;

 

  while (1) {

    // Start ADC conversion

    HAL_ADC_Start(&hadc1);

    // Wait for conversion to complete

    if (HAL_ADC_PollForConversion(&hadc1, 100) == HAL_OK) {

      // Read ADC value

      adc_value = HAL_ADC_GetValue(&hadc1);

      // Process ADC value (filtering, amplification if needed)

      

      // Send data through CAN bus

      CAN_TxHeaderTypeDef TxHeader;

      uint8_t TxData[8];

      TxHeader.StdId = 0x321; // Example CAN ID

      TxHeader.DLC = 8;

      TxHeader.IDE = CAN_ID_STD;

      TxHeader.RTR = CAN_RTR_DATA;

      TxData[0] = (adc_value >> 8) & 0xFF;

      TxData[1] = adc_value & 0xFF;

      HAL_CAN_AddTxMessage(&hcan1, &TxHeader, TxData, (uint32_t *)CAN_TX_MAILBOX0);

    }

  }

}

Dragonmonkey
Associate II

If I can't find CAN, can I use FDCAN as replacement. And below ts the code for CAN. Canyou help convert to FDCAN, please?

 

static void MX_CAN1_Init(void) {

  hcan1.Instance = CAN1;

  hcan1.Init.Prescaler = 1;

  hcan1.Init.Mode = CAN_MODE_NORMAL;

  hcan1.Init.SyncJumpWidth = CAN_SJW_1TQ;

  hcan1.Init.TimeSeg1 = CAN_BS1_13TQ;

  hcan1.Init.TimeSeg2 = CAN_BS2_2TQ;

  hcan1.Init.TimeTriggeredMode = DISABLE;

  hcan1.Init.AutoBusOff = ENABLE;

  hcan1.Init.AutoWakeUp = DISABLE;

  hcan1.Init.AutoRetransmission = DISABLE;

  hcan1.Init.ReceiveFifoLocked = DISABLE;

  hcan1.Init.TransmitFifoPriority = DISABLE;

  if (HAL_CAN_Init(&hcan1) != HAL_OK) {

    Error_Handler();

  }

}

 

int main(void) {

  HAL_Init();

  SystemClock_Config();

  MX_GPIO_Init();

  MX_ADC1_Init();

  MX_CAN1_Init();

 

  uint16_t adc_value;

 

  while (1) {

    // Start ADC conversion

    HAL_ADC_Start(&hadc1);

    // Wait for conversion to complete

    if (HAL_ADC_PollForConversion(&hadc1, 100) == HAL_OK) {

      // Read ADC value

      adc_value = HAL_ADC_GetValue(&hadc1);

      // Process ADC value (filtering, amplification if needed)

      

      // Send data through CAN bus

      CAN_TxHeaderTypeDef TxHeader;

      uint8_t TxData[8];

      TxHeader.StdId = 0x321; // Example CAN ID

      TxHeader.DLC = 8;

      TxHeader.IDE = CAN_ID_STD;

      TxHeader.RTR = CAN_RTR_DATA;

      TxData[0] = (adc_value >> 8) & 0xFF;

      TxData[1] = adc_value & 0xFF;

      HAL_CAN_AddTxMessage(&hcan1, &TxHeader, TxData, (uint32_t *)CAN_TX_MAILBOX0);

    }

  }

}

 

 

Hello,

There is no stm32h7xx_hal_can.h in H7 cube HAL. You need to use FDCAN (stm32h7xx_hal_fdcan.h).

You need to use FDCAN peripheral in classic mode as a replacement of bxCAN.

Refer to this example: https://github.com/STMicroelectronics/STM32CubeH7/tree/b9d11df3020deef82310c88f3d8590d076b43ef7/Projects/STM32H743I-EVAL/Examples/FDCAN/FDCAN_Classic_Frame_Networking

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

It doesn't exist, as I explained earlier, so you won't be finding it.

Perhaps ask your friend why he is including a file that doesn't exist.

If you feel a post has answered your question, please click "Accept as Solution".