小白使用keil编程debug进入了harddefault,搞了半天没解决。求大佬帮下忙。

/* USER CODE BEGIN Header /
/
*


  • @file : main.c
  • @brief : Main program body ******************************************************************************
  • @attention *
  • © Copyright (c) 2019 STMicroelectronics.

  • All rights reserved. *
  • This software component is licensed by ST under BSD 3-Clause license,
  • the "License"; You may not use this file except in compliance with the
  • License. You may obtain a copy of the License at:
  • opensource.org/licenses/BSD-3-Clause * ****************************************************************************** / / USER CODE END Header */

/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "can.h"
#include "usart.h"
#include "gpio.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes /
void CAN_SetTxMsg(void)
{

hcan.pTxMsg->ExtId=0x1314; //使用的扩展ID
hcan.pTxMsg->IDE=CAN_ID_EXT; //扩展模式
hcan.pTxMsg->RTR=CAN_RTR_DATA; //发送的是数据
hcan.pTxMsg->DLC=8; //数据长度为2字节
hcan.pTxMsg->data[0]=0x01;
hcan.pTxMsg->data[1]=0x02;
hcan.pTxMsg->data[2]=0x03;
hcan.pTxMsg->data[3]=0x04;
hcan.pTxMsg->data[4]=0x05;
hcan.pTxMsg->data[5]=0x06;
hcan.pTxMsg->data[6]=0x07;
hcan.pTxMsg->data[7]=0x08;
}
/
USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */

/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */

/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */

/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/

/* USER CODE BEGIN PV */

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
/* USER CODE BEGIN PFP */

/* USER CODE END PFP */

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */

/* USER CODE END 0 */

/**

  • @brief The application entry point.
  • @retval int
    /
    int main(void)
    {
    /
    USER CODE BEGIN 1 */

    /* USER CODE END 1 */

    /* MCU Configuration--------------------------------------------------------*/

    /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
    HAL_Init();

    /* USER CODE BEGIN Init */

    /* USER CODE END Init */

    /* Configure the system clock */
    SystemClock_Config();

    /* USER CODE BEGIN SysInit */

    /* USER CODE END SysInit */

    /* Initialize all configured peripherals /
    MX_GPIO_Init();
    MX_CAN_Init();
    MX_USART1_UART_Init();
    /
    USER CODE BEGIN 2 */

    CAN_SetTxMsg();
    HAL_CAN_AddTxMessage(&hcan,hcan.pTxMsg,hcan.pTxMsg->data,(uint32_t*)CAN_TX_MAILBOX0);
    HAL_CAN_ActivateNotification(&hcan,CAN_IT_RX_FIFO0_MSG_PENDING);

    /* USER CODE END 2 */

    /* Infinite loop /
    /
    USER CODE BEGIN WHILE /
    while (1)
    {
    /
    USER CODE END WHILE */

    /* USER CODE BEGIN 3 /
    }
    /
    USER CODE END 3 */
    }

/**

  • @brief System Clock Configuration
  • @retval None
    */
    void SystemClock_Config(void)
    {
    RCC_OscInitTypeDef RCC_OscInitStruct = {0};
    RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

    /** Initializes the CPU, AHB and APB busses clocks
    /
    RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
    RCC_OscInitStruct.HSEState = RCC_HSE_ON;
    RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
    RCC_OscInitStruct.HSIState = RCC_HSI_ON;
    RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
    RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
    RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
    if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
    {
    Error_Handler();
    }
    /
    * Initializes the CPU, AHB and APB busses clocks
    */
    RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
    |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
    RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
    RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
    RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
    RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

    if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
    {
    Error_Handler();
    }
    /** Enables the Clock Security System
    */
    HAL_RCC_EnableCSS();
    }

/* USER CODE BEGIN 4 */
void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan)
{

HAL_CAN_AddTxMessage(hcan,hcan->pTxMsg,hcan->pTxMsg->data,(uint32_t*)CAN_TX_MAILBOX0);

HAL_CAN_ActivateNotification(hcan,CAN_IT_RX_FIFO0_MSG_PENDING);

}
/* USER CODE END 4 */

/**

  • @brief This function is executed in case of error occurrence.
  • @retval None
    /
    void Error_Handler(void)
    {
    /
    USER CODE BEGIN Error_Handler_Debug /
    /
    User can add his own implementation to report the HAL error return state */

    /* USER CODE END Error_Handler_Debug */
    }

#ifdef USE_FULL_ASSERT
/**

  • @brief Reports the name of the source file and the source line number
  • where the assert_param error has occurred.
  • @param file: pointer to the source file name
  • @param line: assert_param error line source number
  • @retval None / void assert_failed(uint8_t *file, uint32_t line) { / USER CODE BEGIN 6 / / User can add his own implementation to report the file name and line number, tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) / / USER CODE END 6 / } #endif / USE_FULL_ASSERT */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

这是我的主程序,debug总是在CAN_SetMsg()那里进入了hardfault.下面是定义的一些初始化结构体。

/**


  • @file stm32f1xx_hal_can.h
  • @author MCD Application Team
  • @brief Header file of CAN HAL module. ******************************************************************************
  • @attention *
  • © COPYRIGHT(c) 2016 STMicroelectronics

    *
  • Redistribution and use in source and binary forms, with or without modification,
  • are permitted provided that the following conditions are met:
  • 1. Redistributions of source code must retain the above copyright notice,
  • this list of conditions and the following disclaimer.
  • 2. Redistributions in binary form must reproduce the above copyright notice,
  • this list of conditions and the following disclaimer in the documentation
  • and/or other materials provided with the distribution.
  • 3. Neither the name of STMicroelectronics nor the names of its contributors
  • may be used to endorse or promote products derived from this software
  • without specific prior written permission. *
  • THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  • AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  • IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  • DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  • FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  • DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  • SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  • CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  • OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  • OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ****************************************************************************** */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef STM32F1xx_HAL_CAN_H
#define STM32F1xx_HAL_CAN_H

#ifdef __cplusplus
extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "stm32f1xx_hal_def.h"

/** @addtogroup STM32F1xx_HAL_Driver

  • @{ */

#if defined (CAN1)
/** @addtogroup CAN

  • @{ */

/* Exported types ------------------------------------------------------------*/
/** @defgroup CAN_Exported_Types CAN Exported Types

  • @{ / /*
  • @brief HAL State structures definition / typedef enum { HAL_CAN_STATE_RESET = 0x00U, /!< CAN not yet initialized or disabled / HAL_CAN_STATE_READY = 0x01U, /!< CAN initialized and ready for use / HAL_CAN_STATE_LISTENING = 0x02U, /!< CAN receive process is ongoing / HAL_CAN_STATE_SLEEP_PENDING = 0x03U, /!< CAN sleep request is pending / HAL_CAN_STATE_SLEEP_ACTIVE = 0x04U, /!< CAN sleep mode is active / HAL_CAN_STATE_ERROR = 0x05U /!< CAN error state */

} HAL_CAN_StateTypeDef;

/**

  • @brief CAN init structure definition
    /
    typedef struct
    {
    uint32_t Prescaler; /
    !< Specifies the length of a time quantum.
    This parameter must be a number between Min_Data = 1 and Max_Data = 1024. */

    uint32_t Mode; /*!< Specifies the CAN operating mode.
    This parameter can be a value of @ref CAN_operating_mode */

    uint32_t SyncJumpWidth; /*!< Specifies the maximum number of time quanta the CAN hardware
    is allowed to lengthen or shorten a bit to perform resynchronization.
    This parameter can be a value of @ref CAN_synchronisation_jump_width */

    uint32_t TimeSeg1; /*!< Specifies the number of time quanta in Bit Segment 1.
    This parameter can be a value of @ref CAN_time_quantum_in_bit_segment_1 */

    uint32_t TimeSeg2; /*!< Specifies the number of time quanta in Bit Segment 2.
    This parameter can be a value of @ref CAN_time_quantum_in_bit_segment_2 */

    FunctionalState TimeTriggeredMode; /*!< Enable or disable the time triggered communication mode.
    This parameter can be set to ENABLE or DISABLE. */

    FunctionalState AutoBusOff; /*!< Enable or disable the automatic bus-off management.
    This parameter can be set to ENABLE or DISABLE. */

    FunctionalState AutoWakeUp; /*!< Enable or disable the automatic wake-up mode.
    This parameter can be set to ENABLE or DISABLE. */

    FunctionalState AutoRetransmission; /*!< Enable or disable the non-automatic retransmission mode.
    This parameter can be set to ENABLE or DISABLE. */

    FunctionalState ReceiveFifoLocked; /*!< Enable or disable the Receive FIFO Locked mode.
    This parameter can be set to ENABLE or DISABLE. */

    FunctionalState TransmitFifoPriority;/*!< Enable or disable the transmit FIFO priority.
    This parameter can be set to ENABLE or DISABLE. */

} CAN_InitTypeDef;

/**

  • @brief CAN filter configuration structure definition
    /
    typedef struct
    {
    uint32_t FilterIdHigh; /
    !< Specifies the filter identification number (MSBs for a 32-bit
    configuration, first one for a 16-bit configuration).
    This parameter must be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF. */

    uint32_t FilterIdLow; /*!< Specifies the filter identification number (LSBs for a 32-bit
    configuration, second one for a 16-bit configuration).
    This parameter must be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF. */

    uint32_t FilterMaskIdHigh; /*!< Specifies the filter mask number or identification number,
    according to the mode (MSBs for a 32-bit configuration,
    first one for a 16-bit configuration).
    This parameter must be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF. */

    uint32_t FilterMaskIdLow; /*!< Specifies the filter mask number or identification number,
    according to the mode (LSBs for a 32-bit configuration,
    second one for a 16-bit configuration).
    This parameter must be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF. */

    uint32_t FilterFIFOAssignment; /*!< Specifies the FIFO (0 or 1U) which will be assigned to the filter.
    This parameter can be a value of @ref CAN_filter_FIFO */

    uint32_t FilterBank; /*!< Specifies the filter bank which will be initialized.
    For single CAN instance(14 dedicated filter banks),
    this parameter must be a number between Min_Data = 0 and Max_Data = 13.
    For dual CAN instances(28 filter banks shared),
    this parameter must be a number between Min_Data = 0 and Max_Data = 27. */

    uint32_t FilterMode; /*!< Specifies the filter mode to be initialized.
    This parameter can be a value of @ref CAN_filter_mode */

    uint32_t FilterScale; /*!< Specifies the filter scale.
    This parameter can be a value of @ref CAN_filter_scale */

    uint32_t FilterActivation; /*!< Enable or disable the filter.
    This parameter can be a value of @ref CAN_filter_activation */

    uint32_t SlaveStartFilterBank; /*!< Select the start filter bank for the slave CAN instance.
    For single CAN instances, this parameter is meaningless.
    For dual CAN instances, all filter banks with lower index are assigned to master
    CAN instance, whereas all filter banks with greater index are assigned to slave
    CAN instance.
    This parameter must be a number between Min_Data = 0 and Max_Data = 27. */

} CAN_FilterTypeDef;

/**

  • @brief CAN Tx message header structure definition
    /
    typedef struct
    {
    uint32_t StdId; /
    !< Specifies the standard identifier.
    This parameter must be a number between Min_Data = 0 and Max_Data = 0x7FF. */

    uint32_t ExtId; /*!< Specifies the extended identifier.
    This parameter must be a number between Min_Data = 0 and Max_Data = 0x1FFFFFFF. */

    uint32_t IDE; /*!< Specifies the type of identifier for the message that will be transmitted.
    This parameter can be a value of @ref CAN_identifier_type */

    uint32_t RTR; /*!< Specifies the type of frame for the message that will be transmitted.
    This parameter can be a value of @ref CAN_remote_transmission_request */

    uint32_t DLC; /*!< Specifies the length of the frame that will be transmitted.
    This parameter must be a number between Min_Data = 0 and Max_Data = 8. */

    uint8_t data[8];

    FunctionalState TransmitGlobalTime; /*!< Specifies whether the timestamp counter value captured on start
    of frame transmission, is sent in DATA6 and DATA7 replacing pData[6] and pData[7].
    @note: Time Triggered Communication Mode must be enabled.
    @note: DLC must be programmed as 8 bytes, in order these 2 bytes are sent.
    This parameter can be set to ENABLE or DISABLE. */

} CAN_TxHeaderTypeDef;

/**

  • @brief CAN Rx message header structure definition
    /
    typedef struct
    {
    uint32_t StdId; /
    !< Specifies the standard identifier.
    This parameter must be a number between Min_Data = 0 and Max_Data = 0x7FF. */

    uint32_t ExtId; /*!< Specifies the extended identifier.
    This parameter must be a number between Min_Data = 0 and Max_Data = 0x1FFFFFFF. */

    uint32_t IDE; /*!< Specifies the type of identifier for the message that will be transmitted.
    This parameter can be a value of @ref CAN_identifier_type */

    uint32_t RTR; /*!< Specifies the type of frame for the message that will be transmitted.
    This parameter can be a value of @ref CAN_remote_transmission_request */

    uint32_t DLC; /*!< Specifies the length of the frame that will be transmitted.
    This parameter must be a number between Min_Data = 0 and Max_Data = 8. */

    uint8_t Data[8];

    uint32_t Timestamp; /*!< Specifies the timestamp counter value captured on start of frame reception.
    @note: Time Triggered Communication Mode must be enabled.
    This parameter must be a number between Min_Data = 0 and Max_Data = 0xFFFF. */

    uint32_t FilterMatchIndex; /*!< Specifies the index of matching acceptance filter element.
    This parameter must be a number between Min_Data = 0 and Max_Data = 0xFF. */

} CAN_RxHeaderTypeDef;

/**

  • @brief CAN handle Structure definition
    /
    typedef struct __CAN_HandleTypeDef
    {
    CAN_TypeDef *Instance; /
    !< Register base address */

    CAN_InitTypeDef Init; /*!< CAN required parameters */

    CAN_TxHeaderTypeDef* pTxMsg;

    CAN_RxHeaderTypeDef* pRxMsg;

    HAL_LockTypeDef Lock;

    __IO HAL_CAN_StateTypeDef State; /*!< CAN communication state */

    __IO uint32_t ErrorCode; /*!< CAN Error code.
    This parameter can be a value of @ref CAN_Error_Code */

} CAN_HandleTypeDef;

/**

  • @} */

/* Exported constants --------------------------------------------------------*/

/** @defgroup CAN_Exported_Constants CAN Exported Constants

  • @{ */

/** @defgroup CAN_Error_Code CAN Error Code

  • @{ / #define HAL_CAN_ERROR_NONE (0x00000000U) /!< No error / #define HAL_CAN_ERROR_EWG (0x00000001U) /!< Protocol Error Warning / #define HAL_CAN_ERROR_EPV (0x00000002U) /!< Error Passive / #define HAL_CAN_ERROR_BOF (0x00000004U) /!< Bus-off error / #define HAL_CAN_ERROR_STF (0x00000008U) /!< Stuff error / #define HAL_CAN_ERROR_FOR (0x00000010U) /!< Form error / #define HAL_CAN_ERROR_ACK (0x00000020U) /!< Acknowledgment error / #define HAL_CAN_ERROR_BR (0x00000040U) /!< Bit recessive error / #define HAL_CAN_ERROR_BD (0x00000080U) /!< Bit dominant error / #define HAL_CAN_ERROR_CRC (0x00000100U) /!< CRC error / #define HAL_CAN_ERROR_RX_FOV0 (0x00000200U) /!< Rx FIFO0 overrun error / #define HAL_CAN_ERROR_RX_FOV1 (0x00000400U) /!< Rx FIFO1 overrun error / #define HAL_CAN_ERROR_TX_ALST0 (0x00000800U) /!< TxMailbox 0 transmit failure due to arbitration lost / #define HAL_CAN_ERROR_TX_TERR0 (0x00001000U) /!< TxMailbox 1 transmit failure due to tranmit error / #define HAL_CAN_ERROR_TX_ALST1 (0x00002000U) /!< TxMailbox 0 transmit failure due to arbitration lost / #define HAL_CAN_ERROR_TX_TERR1 (0x00004000U) /!< TxMailbox 1 transmit failure due to tranmit error / #define HAL_CAN_ERROR_TX_ALST2 (0x00008000U) /!< TxMailbox 0 transmit failure due to arbitration lost / #define HAL_CAN_ERROR_TX_TERR2 (0x00010000U) /!< TxMailbox 1 transmit failure due to tranmit error / #define HAL_CAN_ERROR_TIMEOUT (0x00020000U) /!< Timeout error / #define HAL_CAN_ERROR_NOT_INITIALIZED (0x00040000U) /!< Peripheral not initialized / #define HAL_CAN_ERROR_NOT_READY (0x00080000U) /!< Peripheral not ready / #define HAL_CAN_ERROR_NOT_STARTED (0x00100000U) /!< Peripheral not started / #define HAL_CAN_ERROR_PARAM (0x00200000U) /!< Parameter error */

#define HAL_CAN_ERROR_INTERNAL (0x00800000U) /*!< Internal error */

/**

  • @} */

/** @defgroup CAN_InitStatus CAN InitStatus

  • @{ / #define CAN_INITSTATUS_FAILED (0x00000000U) /!< CAN initialization failed / #define CAN_INITSTATUS_SUCCESS (0x00000001U) /!< CAN initialization OK / /*
  • @} */

/** @defgroup CAN_operating_mode CAN Operating Mode

  • @{ / #define CAN_MODE_NORMAL (0x00000000U) /!< Normal mode / #define CAN_MODE_LOOPBACK ((uint32_t)CAN_BTR_LBKM) /!< Loopback mode / #define CAN_MODE_SILENT ((uint32_t)CAN_BTR_SILM) /!< Silent mode / #define CAN_MODE_SILENT_LOOPBACK ((uint32_t)(CAN_BTR_LBKM | CAN_BTR_SILM)) /!< Loopback combined with silent mode / /*
  • @} */

/** @defgroup CAN_synchronisation_jump_width CAN Synchronization Jump Width

  • @{ / #define CAN_SJW_1TQ (0x00000000U) /!< 1 time quantum / #define CAN_SJW_2TQ ((uint32_t)CAN_BTR_SJW_0) /!< 2 time quantum / #define CAN_SJW_3TQ ((uint32_t)CAN_BTR_SJW_1) /!< 3 time quantum / #define CAN_SJW_4TQ ((uint32_t)CAN_BTR_SJW) /!< 4 time quantum / /*
  • @} */

/** @defgroup CAN_time_quantum_in_bit_segment_1 CAN Time Quantum in Bit Segment 1

  • @{ / #define CAN_BS1_1TQ (0x00000000U) /!< 1 time quantum / #define CAN_BS1_2TQ ((uint32_t)CAN_BTR_TS1_0) /!< 2 time quantum / #define CAN_BS1_3TQ ((uint32_t)CAN_BTR_TS1_1) /!< 3 time quantum / #define CAN_BS1_4TQ ((uint32_t)(CAN_BTR_TS1_1 | CAN_BTR_TS1_0)) /!< 4 time quantum / #define CAN_BS1_5TQ ((uint32_t)CAN_BTR_TS1_2) /!< 5 time quantum / #define CAN_BS1_6TQ ((uint32_t)(CAN_BTR_TS1_2 | CAN_BTR_TS1_0)) /!< 6 time quantum / #define CAN_BS1_7TQ ((uint32_t)(CAN_BTR_TS1_2 | CAN_BTR_TS1_1)) /!< 7 time quantum / #define CAN_BS1_8TQ ((uint32_t)(CAN_BTR_TS1_2 | CAN_BTR_TS1_1 | CAN_BTR_TS1_0)) /!< 8 time quantum / #define CAN_BS1_9TQ ((uint32_t)CAN_BTR_TS1_3) /!< 9 time quantum / #define CAN_BS1_10TQ ((uint32_t)(CAN_BTR_TS1_3 | CAN_BTR_TS1_0)) /!< 10 time quantum / #define CAN_BS1_11TQ ((uint32_t)(CAN_BTR_TS1_3 | CAN_BTR_TS1_1)) /!< 11 time quantum / #define CAN_BS1_12TQ ((uint32_t)(CAN_BTR_TS1_3 | CAN_BTR_TS1_1 | CAN_BTR_TS1_0)) /!< 12 time quantum / #define CAN_BS1_13TQ ((uint32_t)(CAN_BTR_TS1_3 | CAN_BTR_TS1_2)) /!< 13 time quantum / #define CAN_BS1_14TQ ((uint32_t)(CAN_BTR_TS1_3 | CAN_BTR_TS1_2 | CAN_BTR_TS1_0)) /!< 14 time quantum / #define CAN_BS1_15TQ ((uint32_t)(CAN_BTR_TS1_3 | CAN_BTR_TS1_2 | CAN_BTR_TS1_1)) /!< 15 time quantum / #define CAN_BS1_16TQ ((uint32_t)CAN_BTR_TS1) /!< 16 time quantum / /*
  • @} */

/** @defgroup CAN_time_quantum_in_bit_segment_2 CAN Time Quantum in Bit Segment 2

  • @{ / #define CAN_BS2_1TQ (0x00000000U) /!< 1 time quantum / #define CAN_BS2_2TQ ((uint32_t)CAN_BTR_TS2_0) /!< 2 time quantum / #define CAN_BS2_3TQ ((uint32_t)CAN_BTR_TS2_1) /!< 3 time quantum / #define CAN_BS2_4TQ ((uint32_t)(CAN_BTR_TS2_1 | CAN_BTR_TS2_0)) /!< 4 time quantum / #define CAN_BS2_5TQ ((uint32_t)CAN_BTR_TS2_2) /!< 5 time quantum / #define CAN_BS2_6TQ ((uint32_t)(CAN_BTR_TS2_2 | CAN_BTR_TS2_0)) /!< 6 time quantum / #define CAN_BS2_7TQ ((uint32_t)(CAN_BTR_TS2_2 | CAN_BTR_TS2_1)) /!< 7 time quantum / #define CAN_BS2_8TQ ((uint32_t)CAN_BTR_TS2) /!< 8 time quantum / /*
  • @} */

/** @defgroup CAN_filter_mode CAN Filter Mode

  • @{ / #define CAN_FILTERMODE_IDMASK (0x00000000U) /!< Identifier mask mode / #define CAN_FILTERMODE_IDLIST (0x00000001U) /!< Identifier list mode / /*
  • @} */

/** @defgroup CAN_filter_scale CAN Filter Scale

  • @{ / #define CAN_FILTERSCALE_16BIT (0x00000000U) /!< Two 16-bit filters / #define CAN_FILTERSCALE_32BIT (0x00000001U) /!< One 32-bit filter / /*
  • @} */

/** @defgroup CAN_filter_activation CAN Filter Activation

  • @{ / #define CAN_FILTER_DISABLE (0x00000000U) /!< Disable filter / #define CAN_FILTER_ENABLE (0x00000001U) /!< Enable filter / /*
  • @} */

/** @defgroup CAN_filter_FIFO CAN Filter FIFO

  • @{ / #define CAN_FILTER_FIFO0 (0x00000000U) /!< Filter FIFO 0 assignment for filter x / #define CAN_FILTER_FIFO1 (0x00000001U) /!< Filter FIFO 1 assignment for filter x / /*
  • @} */

/** @defgroup CAN_identifier_type CAN Identifier Type

  • @{ / #define CAN_ID_STD ((uint32_t)0x00000000) /!< Standard Id / #define CAN_ID_EXT ((uint32_t)0x00000004) /!< Extended Id / /*
  • @} */

/** @defgroup CAN_remote_transmission_request CAN Remote Transmission Request

  • @{ / #define CAN_RTR_DATA ((uint32_t)0x00000000) /!< Data frame / #define CAN_RTR_REMOTE ((uint32_t)0x00000002) /!< Remote frame / /*
  • @} */

/** @defgroup CAN_receive_FIFO_number CAN Receive FIFO Number

  • @{ / #define CAN_RX_FIFO0 (0x00000000U) /!< CAN receive FIFO 0 / #define CAN_RX_FIFO1 (0x00000001U) /!< CAN receive FIFO 1 / /*
  • @} */

/** @defgroup CAN_Tx_Mailboxes CAN Tx Mailboxes

  • @{ / #define CAN_TX_MAILBOX0 (0x00000001U) /!< Tx Mailbox 0 / #define CAN_TX_MAILBOX1 (0x00000002U) /!< Tx Mailbox 1 / #define CAN_TX_MAILBOX2 (0x00000004U) /!< Tx Mailbox 2 / /*
  • @} */

/** @defgroup CAN_flags CAN Flags

  • @{ / / Transmit Flags / #define CAN_FLAG_RQCP0 (0x00000500U) /!< Request complete MailBox 0 flag / #define CAN_FLAG_TXOK0 (0x00000501U) /!< Transmission OK MailBox 0 flag / #define CAN_FLAG_ALST0 (0x00000502U) /!< Arbitration Lost MailBox 0 flag / #define CAN_FLAG_TERR0 (0x00000503U) /!< Transmission error MailBox 0 flag / #define CAN_FLAG_RQCP1 (0x00000508U) /!< Request complete MailBox1 flag / #define CAN_FLAG_TXOK1 (0x00000509U) /!< Transmission OK MailBox 1 flag / #define CAN_FLAG_ALST1 (0x0000050AU) /!< Arbitration Lost MailBox 1 flag / #define CAN_FLAG_TERR1 (0x0000050BU) /!< Transmission error MailBox 1 flag / #define CAN_FLAG_RQCP2 (0x00000510U) /!< Request complete MailBox2 flag / #define CAN_FLAG_TXOK2 (0x00000511U) /!< Transmission OK MailBox 2 flag / #define CAN_FLAG_ALST2 (0x00000512U) /!< Arbitration Lost MailBox 2 flag / #define CAN_FLAG_TERR2 (0x00000513U) /!< Transmission error MailBox 2 flag / #define CAN_FLAG_TME0 (0x0000051AU) /!< Transmit mailbox 0 empty flag / #define CAN_FLAG_TME1 (0x0000051BU) /!< Transmit mailbox 1 empty flag / #define CAN_FLAG_TME2 (0x0000051CU) /!< Transmit mailbox 2 empty flag / #define CAN_FLAG_LOW0 (0x0000051DU) /!< Lowest priority mailbox 0 flag / #define CAN_FLAG_LOW1 (0x0000051EU) /!< Lowest priority mailbox 1 flag / #define CAN_FLAG_LOW2 (0x0000051FU) /!< Lowest priority mailbox 2 flag */

/* Receive Flags /
#define CAN_FLAG_FF0 (0x00000203U) /
!< RX FIFO 0 Full flag /
#define CAN_FLAG_FOV0 (0x00000204U) /
!< RX FIFO 0 Overrun flag /
#define CAN_FLAG_FF1 (0x00000403U) /
!< RX FIFO 1 Full flag /
#define CAN_FLAG_FOV1 (0x00000404U) /
!< RX FIFO 1 Overrun flag */

/* Operating Mode Flags /
#define CAN_FLAG_INAK (0x00000100U) /
!< Initialization acknowledge flag /
#define CAN_FLAG_SLAK (0x00000101U) /
!< Sleep acknowledge flag /
#define CAN_FLAG_ERRI (0x00000102U) /
!< Error flag /
#define CAN_FLAG_WKU (0x00000103U) /
!< Wake up interrupt flag /
#define CAN_FLAG_SLAKI (0x00000104U) /
!< Sleep acknowledge interrupt flag */

/* Error Flags /
#define CAN_FLAG_EWG (0x00000300U) /
!< Error warning flag /
#define CAN_FLAG_EPV (0x00000301U) /
!< Error passive flag /
#define CAN_FLAG_BOF (0x00000302U) /
!< Bus-Off flag /
/
*

  • @} */

/** @defgroup CAN_Interrupts CAN Interrupts

  • @{ / / Transmit Interrupt / #define CAN_IT_TX_MAILBOX_EMPTY ((uint32_t)CAN_IER_TMEIE) /!< Transmit mailbox empty interrupt */

/* Receive Interrupts /
#define CAN_IT_RX_FIFO0_MSG_PENDING ((uint32_t)CAN_IER_FMPIE0) /
!< FIFO 0 message pending interrupt /
#define CAN_IT_RX_FIFO0_FULL ((uint32_t)CAN_IER_FFIE0) /
!< FIFO 0 full interrupt /
#define CAN_IT_RX_FIFO0_OVERRUN ((uint32_t)CAN_IER_FOVIE0) /
!< FIFO 0 overrun interrupt /
#define CAN_IT_RX_FIFO1_MSG_PENDING ((uint32_t)CAN_IER_FMPIE1) /
!< FIFO 1 message pending interrupt /
#define CAN_IT_RX_FIFO1_FULL ((uint32_t)CAN_IER_FFIE1) /
!< FIFO 1 full interrupt /
#define CAN_IT_RX_FIFO1_OVERRUN ((uint32_t)CAN_IER_FOVIE1) /
!< FIFO 1 overrun interrupt */

/* Operating Mode Interrupts /
#define CAN_IT_WAKEUP ((uint32_t)CAN_IER_WKUIE) /
!< Wake-up interrupt /
#define CAN_IT_SLEEP_ACK ((uint32_t)CAN_IER_SLKIE) /
!< Sleep acknowledge interrupt */

/* Error Interrupts /
#define CAN_IT_ERROR_WARNING ((uint32_t)CAN_IER_EWGIE) /
!< Error warning interrupt /
#define CAN_IT_ERROR_PASSIVE ((uint32_t)CAN_IER_EPVIE) /
!< Error passive interrupt /
#define CAN_IT_BUSOFF ((uint32_t)CAN_IER_BOFIE) /
!< Bus-off interrupt /
#define CAN_IT_LAST_ERROR_CODE ((uint32_t)CAN_IER_LECIE) /
!< Last error code interrupt /
#define CAN_IT_ERROR ((uint32_t)CAN_IER_ERRIE) /
!< Error Interrupt /
/
*

  • @} */

/**

  • @} */

/* Exported macros -----------------------------------------------------------*/
/** @defgroup CAN_Exported_Macros CAN Exported Macros

  • @{ */

/** @brief Reset CAN handle state

  • @param HANDLE CAN handle.
  • @retval None */ #define HAL_CAN_RESET_HANDLE_STATE(HANDLE__) ((__HANDLE__)->State = HAL_CAN_STATE_RESET)

/**

  • @brief Enable the specified CAN interrupts.
  • @param HANDLE CAN handle.
  • @param INTERRUPT CAN Interrupt sources to enable.
  • This parameter can be any combination of @arg CAN_Interrupts
  • @retval None */ #define HAL_CAN_ENABLE_IT(HANDLE__, INTERRUPT) (((__HANDLE__)->Instance->IER) |= (__INTERRUPT__))

/**

  • @brief Disable the specified CAN interrupts.
  • @param HANDLE CAN handle.
  • @param INTERRUPT CAN Interrupt sources to disable.
  • This parameter can be any combination of @arg CAN_Interrupts
  • @retval None */ #define HAL_CAN_DISABLE_IT(HANDLE__, INTERRUPT) (((__HANDLE__)->Instance->IER) &= ~(__INTERRUPT__))

/** @brief Check if the specified CAN interrupt source is enabled or disabled.

  • @param HANDLE specifies the CAN Handle.
  • @param INTERRUPT specifies the CAN interrupt source to check.
  • This parameter can be a value of @arg CAN_Interrupts
  • @retval The state of IT (TRUE or FALSE). */ #define HAL_CAN_GET_IT_SOURCE(HANDLE__, INTERRUPT) (((__HANDLE__)->Instance->IER) & (__INTERRUPT__))

/** @brief Check whether the specified CAN flag is set or not.

  • @param HANDLE specifies the CAN Handle.
  • @param FLAG specifies the flag to check.
  • This parameter can be one of @arg CAN_flags
  • @retval The state of FLAG (TRUE or FALSE). */ #define HAL_CAN_GET_FLAG(HANDLE__, FLAG) \ ((((__FLAG__) >> 8U) == 5U)? ((((__HANDLE__)->Instance->TSR) & (1U << ((__FLAG__) & CAN_FLAG_MASK))) == (1U << ((__FLAG__) & CAN_FLAG_MASK))): \ (((__FLAG__) >> 8U) == 2U)? ((((__HANDLE__)->Instance->RF0R) & (1U << ((__FLAG__) & CAN_FLAG_MASK))) == (1U << ((__FLAG__) & CAN_FLAG_MASK))): \ (((__FLAG__) >> 8U) == 4U)? ((((__HANDLE__)->Instance->RF1R) & (1U << ((__FLAG__) & CAN_FLAG_MASK))) == (1U << ((__FLAG__) & CAN_FLAG_MASK))): \ (((__FLAG__) >> 8U) == 1U)? ((((__HANDLE__)->Instance->MSR) & (1U << ((__FLAG__) & CAN_FLAG_MASK))) == (1U << ((__FLAG__) & CAN_FLAG_MASK))): \ (((__FLAG__) >> 8U) == 3U)? ((((__HANDLE__)->Instance->ESR) & (1U << ((__FLAG__) & CAN_FLAG_MASK))) == (1U << ((__FLAG__) & CAN_FLAG_MASK))): 0U)

/** @brief Clear the specified CAN pending flag.

  • @param HANDLE specifies the CAN Handle.
  • @param FLAG specifies the flag to check.
  • This parameter can be one of the following values:
  • @arg CAN_FLAG_RQCP0: Request complete MailBox 0 Flag
  • @arg CAN_FLAG_TXOK0: Transmission OK MailBox 0 Flag
  • @arg CAN_FLAG_ALST0: Arbitration Lost MailBox 0 Flag
  • @arg CAN_FLAG_TERR0: Transmission error MailBox 0 Flag
  • @arg CAN_FLAG_RQCP1: Request complete MailBox 1 Flag
  • @arg CAN_FLAG_TXOK1: Transmission OK MailBox 1 Flag
  • @arg CAN_FLAG_ALST1: Arbitration Lost MailBox 1 Flag
  • @arg CAN_FLAG_TERR1: Transmission error MailBox 1 Flag
  • @arg CAN_FLAG_RQCP2: Request complete MailBox 2 Flag
  • @arg CAN_FLAG_TXOK2: Transmission OK MailBox 2 Flag
  • @arg CAN_FLAG_ALST2: Arbitration Lost MailBox 2 Flag
  • @arg CAN_FLAG_TERR2: Transmission error MailBox 2 Flag
  • @arg CAN_FLAG_FF0: RX FIFO 0 Full Flag
  • @arg CAN_FLAG_FOV0: RX FIFO 0 Overrun Flag
  • @arg CAN_FLAG_FF1: RX FIFO 1 Full Flag
  • @arg CAN_FLAG_FOV1: RX FIFO 1 Overrun Flag
  • @arg CAN_FLAG_WKUI: Wake up Interrupt Flag
  • @arg CAN_FLAG_SLAKI: Sleep acknowledge Interrupt Flag
  • @retval None */ #define HAL_CAN_CLEAR_FLAG(HANDLE__, FLAG) \ ((((__FLAG__) >> 8U) == 5U)? (((__HANDLE__)->Instance->TSR) = (1U << ((__FLAG__) & CAN_FLAG_MASK))): \ (((__FLAG__) >> 8U) == 2U)? (((__HANDLE__)->Instance->RF0R) = (1U << ((__FLAG__) & CAN_FLAG_MASK))): \ (((__FLAG__) >> 8U) == 4U)? (((__HANDLE__)->Instance->RF1R) = (1U << ((__FLAG__) & CAN_FLAG_MASK))): \ (((__FLAG__) >> 8U) == 1U)? (((__HANDLE__)->Instance->MSR) = (1U << ((__FLAG__) & CAN_FLAG_MASK))): 0U)

/**

  • @} */

/* Exported functions --------------------------------------------------------*/
/** @addtogroup CAN_Exported_Functions CAN Exported Functions

  • @{ */

/** @addtogroup CAN_Exported_Functions_Group1 Initialization and de-initialization functions

  • @brief Initialization and Configuration functions
  • @{ */

/* Initialization and de-initialization functions *****************************/
HAL_StatusTypeDef HAL_CAN_Init(CAN_HandleTypeDef *hcan);
HAL_StatusTypeDef HAL_CAN_DeInit(CAN_HandleTypeDef *hcan);
void HAL_CAN_MspInit(CAN_HandleTypeDef *hcan);
void HAL_CAN_MspDeInit(CAN_HandleTypeDef *hcan);

/**

  • @} */

/** @addtogroup CAN_Exported_Functions_Group2 Configuration functions

  • @brief Configuration functions
  • @{ */

/* Configuration functions ****************************************************/
HAL_StatusTypeDef HAL_CAN_ConfigFilter(CAN_HandleTypeDef *hcan, CAN_FilterTypeDef *sFilterConfig);

/**

  • @} */

/** @addtogroup CAN_Exported_Functions_Group3 Control functions

  • @brief Control functions
  • @{ */

/* Control functions **********************************************************/
HAL_StatusTypeDef HAL_CAN_Start(CAN_HandleTypeDef *hcan);
HAL_StatusTypeDef HAL_CAN_Stop(CAN_HandleTypeDef *hcan);
HAL_StatusTypeDef HAL_CAN_RequestSleep(CAN_HandleTypeDef *hcan);
HAL_StatusTypeDef HAL_CAN_WakeUp(CAN_HandleTypeDef *hcan);
uint32_t HAL_CAN_IsSleepActive(CAN_HandleTypeDef *hcan);
HAL_StatusTypeDef HAL_CAN_AddTxMessage(CAN_HandleTypeDef *hcan, CAN_TxHeaderTypeDef *pHeader, uint8_t aData[], uint32_t *pTxMailbox);
HAL_StatusTypeDef HAL_CAN_AbortTxRequest(CAN_HandleTypeDef *hcan, uint32_t TxMailboxes);
uint32_t HAL_CAN_GetTxMailboxesFreeLevel(CAN_HandleTypeDef *hcan);
uint32_t HAL_CAN_IsTxMessagePending(CAN_HandleTypeDef *hcan, uint32_t TxMailboxes);
uint32_t HAL_CAN_GetTxTimestamp(CAN_HandleTypeDef *hcan, uint32_t TxMailbox);
HAL_StatusTypeDef HAL_CAN_GetRxMessage(CAN_HandleTypeDef *hcan, uint32_t RxFifo, CAN_RxHeaderTypeDef *pHeader, uint8_t aData[]);
uint32_t HAL_CAN_GetRxFifoFillLevel(CAN_HandleTypeDef *hcan, uint32_t RxFifo);

/**

  • @} */

/** @addtogroup CAN_Exported_Functions_Group4 Interrupts management

  • @brief Interrupts management
  • @{ / / Interrupts management ******************************************************/ HAL_StatusTypeDef HAL_CAN_ActivateNotification(CAN_HandleTypeDef *hcan, uint32_t ActiveITs); HAL_StatusTypeDef HAL_CAN_DeactivateNotification(CAN_HandleTypeDef *hcan, uint32_t InactiveITs); void HAL_CAN_IRQHandler(CAN_HandleTypeDef *hcan);

/**

  • @} */

/** @addtogroup CAN_Exported_Functions_Group5 Callback functions

  • @brief Callback functions
  • @{ / / Callbacks functions ********************************************************/

void HAL_CAN_TxMailbox0CompleteCallback(CAN_HandleTypeDef *hcan);
void HAL_CAN_TxMailbox1CompleteCallback(CAN_HandleTypeDef *hcan);
void HAL_CAN_TxMailbox2CompleteCallback(CAN_HandleTypeDef *hcan);
void HAL_CAN_TxMailbox0AbortCallback(CAN_HandleTypeDef *hcan);
void HAL_CAN_TxMailbox1AbortCallback(CAN_HandleTypeDef *hcan);
void HAL_CAN_TxMailbox2AbortCallback(CAN_HandleTypeDef *hcan);
void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan);
void HAL_CAN_RxFifo0FullCallback(CAN_HandleTypeDef *hcan);
void HAL_CAN_RxFifo1MsgPendingCallback(CAN_HandleTypeDef *hcan);
void HAL_CAN_RxFifo1FullCallback(CAN_HandleTypeDef *hcan);
void HAL_CAN_SleepCallback(CAN_HandleTypeDef *hcan);
void HAL_CAN_WakeUpFromRxMsgCallback(CAN_HandleTypeDef *hcan);
void HAL_CAN_ErrorCallback(CAN_HandleTypeDef *hcan);

/**

  • @} */

/** @addtogroup CAN_Exported_Functions_Group6 Peripheral State and Error functions

  • @brief CAN Peripheral State functions
  • @{ / / Peripheral State and Error functions ***************************************/ HAL_CAN_StateTypeDef HAL_CAN_GetState(CAN_HandleTypeDef *hcan); uint32_t HAL_CAN_GetError(CAN_HandleTypeDef *hcan); HAL_StatusTypeDef HAL_CAN_ResetError(CAN_HandleTypeDef *hcan);

/**

  • @} */

/**

  • @} */

/* Private types -------------------------------------------------------------*/
/** @defgroup CAN_Private_Types CAN Private Types

  • @{ */

/**

  • @} */

/* Private variables ---------------------------------------------------------*/
/** @defgroup CAN_Private_Variables CAN Private Variables

  • @{ */

/**

  • @} */

/* Private constants ---------------------------------------------------------*/
/** @defgroup CAN_Private_Constants CAN Private Constants

  • @{ / #define CAN_FLAG_MASK (0x000000FFU) /*
  • @} */

/* Private Macros -----------------------------------------------------------*/
/** @defgroup CAN_Private_Macros CAN Private Macros

  • @{ */

#define IS_CAN_MODE(MODE) (((MODE) == CAN_MODE_NORMAL) || \
((MODE) == CAN_MODE_LOOPBACK)|| \
((MODE) == CAN_MODE_SILENT) || \
((MODE) == CAN_MODE_SILENT_LOOPBACK))
#define IS_CAN_SJW(SJW) (((SJW) == CAN_SJW_1TQ) || ((SJW) == CAN_SJW_2TQ) || \
((SJW) == CAN_SJW_3TQ) || ((SJW) == CAN_SJW_4TQ))
#define IS_CAN_BS1(BS1) (((BS1) == CAN_BS1_1TQ) || ((BS1) == CAN_BS1_2TQ) || \
((BS1) == CAN_BS1_3TQ) || ((BS1) == CAN_BS1_4TQ) || \
((BS1) == CAN_BS1_5TQ) || ((BS1) == CAN_BS1_6TQ) || \
((BS1) == CAN_BS1_7TQ) || ((BS1) == CAN_BS1_8TQ) || \
((BS1) == CAN_BS1_9TQ) || ((BS1) == CAN_BS1_10TQ)|| \
((BS1) == CAN_BS1_11TQ)|| ((BS1) == CAN_BS1_12TQ)|| \
((BS1) == CAN_BS1_13TQ)|| ((BS1) == CAN_BS1_14TQ)|| \
((BS1) == CAN_BS1_15TQ)|| ((BS1) == CAN_BS1_16TQ))
#define IS_CAN_BS2(BS2) (((BS2) == CAN_BS2_1TQ) || ((BS2) == CAN_BS2_2TQ) || \
((BS2) == CAN_BS2_3TQ) || ((BS2) == CAN_BS2_4TQ) || \
((BS2) == CAN_BS2_5TQ) || ((BS2) == CAN_BS2_6TQ) || \
((BS2) == CAN_BS2_7TQ) || ((BS2) == CAN_BS2_8TQ))
#define IS_CAN_PRESCALER(PRESCALER) (((PRESCALER) >= 1U) && ((PRESCALER) <= 1024U))
#define IS_CAN_FILTER_ID_HALFWORD(HALFWORD) ((HALFWORD) <= 0xFFFFU)
#if defined(CAN2)
#define IS_CAN_FILTER_BANK_DUAL(BANK) ((BANK) <= 27U)
#endif
#define IS_CAN_FILTER_BANK_SINGLE(BANK) ((BANK) <= 13U)
#define IS_CAN_FILTER_MODE(MODE) (((MODE) == CAN_FILTERMODE_IDMASK) || \
((MODE) == CAN_FILTERMODE_IDLIST))
#define IS_CAN_FILTER_SCALE(SCALE) (((SCALE) == CAN_FILTERSCALE_16BIT) || \
((SCALE) == CAN_FILTERSCALE_32BIT))
#define IS_CAN_FILTER_ACTIVATION(ACTIVATION) (((ACTIVATION) == CAN_FILTER_DISABLE) || \
((ACTIVATION) == CAN_FILTER_ENABLE))
#define IS_CAN_FILTER_FIFO(FIFO) (((FIFO) == CAN_FILTER_FIFO0) || \
((FIFO) == CAN_FILTER_FIFO1))
#define IS_CAN_TX_MAILBOX(TRANSMITMAILBOX) (((TRANSMITMAILBOX) == CAN_TX_MAILBOX0 ) || \
((TRANSMITMAILBOX) == CAN_TX_MAILBOX1 ) || \
((TRANSMITMAILBOX) == CAN_TX_MAILBOX2 ))
#define IS_CAN_TX_MAILBOX_LIST(TRANSMITMAILBOX) ((TRANSMITMAILBOX) <= (CAN_TX_MAILBOX0 | CAN_TX_MAILBOX1 | CAN_TX_MAILBOX2))
#define IS_CAN_STDID(STDID) ((STDID) <= 0x7FFU)
#define IS_CAN_EXTID(EXTID) ((EXTID) <= 0x1FFFFFFFU)
#define IS_CAN_DLC(DLC) ((DLC) <= 8U)
#define IS_CAN_IDTYPE(IDTYPE) (((IDTYPE) == CAN_ID_STD) || \
((IDTYPE) == CAN_ID_EXT))
#define IS_CAN_RTR(RTR) (((RTR) == CAN_RTR_DATA) || ((RTR) == CAN_RTR_REMOTE))
#define IS_CAN_RX_FIFO(FIFO) (((FIFO) == CAN_RX_FIFO0) || ((FIFO) == CAN_RX_FIFO1))
#define IS_CAN_IT(IT) ((IT) <= (CAN_IT_TX_MAILBOX_EMPTY | CAN_IT_RX_FIFO0_MSG_PENDING | \
CAN_IT_RX_FIFO0_FULL | CAN_IT_RX_FIFO0_OVERRUN | \
CAN_IT_RX_FIFO1_MSG_PENDING | CAN_IT_RX_FIFO1_FULL | \
CAN_IT_RX_FIFO1_OVERRUN | CAN_IT_WAKEUP | \
CAN_IT_SLEEP_ACK | CAN_IT_ERROR_WARNING | \
CAN_IT_ERROR_PASSIVE | CAN_IT_BUSOFF | \
CAN_IT_LAST_ERROR_CODE | CAN_IT_ERROR))

/**

  • @} / / End of private macros -----------------------------------------------------*/

/**

  • @} */

#endif /* CAN1 /
/
*

  • @} */

#ifdef __cplusplus
}
#endif

#endif /* STM32F1xx_HAL_CAN_H */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

求大佬指点哪里错了。。

1个回答

备份,再一步一步查代码

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
使用keil编程第一部就出了问题
想问大家我在用keil输入include“STM32l151C8.h”后显示cannot open source input file,说没有这个文件或目录,这种情况怎么办呀
keil C51 数码管的动态显示 延时问题
我在写数码管动态显示的时候发现意义相同的两个代码写出来显示的结果却不同,代码如下: ``` void display_SEG(unsigned int t) { Y_SEG_show(1, 2); while(t--); Y_SEG_show(2, 0); while(t--); Y_SEG_show(3, 1); while(t--); Y_SEG_show(4, 8); while(t--); Y_SEG_show(5, 16); while(t--); Y_SEG_show(6, 16); while(t--); Y_SEG_show(7, i/10); while(t--); Y_SEG_show(8, i%10); while(t--); } ``` t=500;上面这个运行起来延时时间明显过长,从而达不到余辉效应。 ``` void delay_SEG(unsigned char t) { while(t--); } void display_SEG() { Y_SEG_show(1, 2); delay_SEG(500); Y_SEG_show(2, 0); delay_SEG(500); Y_SEG_show(3, 1); delay_SEG(500); Y_SEG_show(4, 8); delay_SEG(500); Y_SEG_show(5, 16); delay_SEG(500); Y_SEG_show(6, 16); delay_SEG(500); Y_SEG_show(7, i/10); delay_SEG(500); Y_SEG_show(8, i%10); delay_SEG(500); } ``` 当定义一个延时函数放进去时,却可以达到效果,可用的不都是while(500--)的延迟吗,为什么会有这个差别。求解答
KEIL MDK 怎么设置--no_conditionalize?
我的STM32L476在调用 arm_rfft_fast_f32函数时出现“ Warning: L6989W: Could not apply patch sdcomp-29491-629360 to instruction VPOP {d8-d15} at offset 0x1c2, instruction is within an IT block and is not the last instruction for arm_cfft_radix8_f32.o(.text).”的报错信息。网上查看了下,需要在KEIL里面将编译选项设置成--no_conditionalize,但是这一步不知道怎么操作。
keil使用全局搜索会停止响应
![图片说明](https://img-ask.csdn.net/upload/201912/10/1575958153_345011.png)版本信息如图 每次使用全局搜索都会停止响应,求助。。![图片说明](https://img-ask.csdn.net/upload/201912/10/1575958404_866854.png)
keil5安装出现这样问题?请问怎么解决?
![图片说明](https://img-ask.csdn.net/upload/202001/04/1578115967_648098.png)
keil error #20 stm32
![图片说明](https://img-ask.csdn.net/upload/201912/27/1577419627_902411.jpg) 刚开始用stm32,还不会用,不了解stm32f10x系列芯片用管脚需要如何配置,望各路大神提点小弟一二
keil5 project 栏叹号咋回事?
![图片说明](https://img-ask.csdn.net/upload/201912/16/1576490164_169717.png)
lcd设计电子时钟protues ,keil编程
以AT89C51单片机为核心的时钟,在LCD显示器上显示当前的时间:使用字符型LCD显示器显示当前时间。显示格式为“时时:分分:秒秒”。用4个功能键操作来设置当前时间。功能键K1~K4功能如下。 K1—进入设置现在的时间。 K2—设置小时。 K3—设置分钟。 K4—确认完成设置。 程序执行后工作指示灯LED闪动,表示程序开始执行,LCD显示“00:00:00”,然后开始计时。c语言编程
单片机KEIL出现了different length of parameter lists 的错误,如何修改?
#include<reg51.h> typedef unsigned int u16; typedef unsigned char u8; #define GPIO_DIG P0 #define GPIO_KEY P1 u8 KeyValue; u8 code smgduan[17]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07, 0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};//???0~F??? **void delay(u16 i)** { while(i--); } void KeyDown(void) { char a=0; GPIO_KEY=0x0f; if(GPIO_KEY!=0x0f) ![图片说明](https://img-ask.csdn.net/upload/201911/11/1573471052_510016.jpg) 加粗处一直在提示错误,如何修改?
keil编程,数组方面的一些疑问
uchar code table[]="12345678";这算数组吗?数组初始化不是要用大括号扩起来,用逗号隔开吗?但为什么他可以这样被调用: for(num=0;num<8;num++) LCDdate(table[num]); 如果真的这样的方法可以表示数组,那么他每个数组元素岂不是只可以表示0~9之间的数字?
keil 编程遇到关于数组问题
#include<reg51.h> typedef unsigned int u16; typedef unsigned char u8; #define GPIO_DIG P0 #define GPIO_KEY P1 #define GPIOdongtai_ P3 sbit LSA=P2^2; sbit LSB=P2^3; sbit LSC=P2^4; sbit JIDIANQI=P2^0; sbit FENGMINGQI=P2^1; u8 code smg[8]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07}; u8 code b[8]={0,1,2,3,4,5,6,7}; void fengmingqi (); void jidianqi (); void juzhenanjian (u8 a,u8 i); void panduan (u8 a,u8 i); void xianshi (u8 a,u8 j); void delay (u16 i); void main () { u8 a [8]={0,0,0,0,0,0,0,0}; while(1) { u8 t=500000; juzhenanjian(a,8); while(t--) { xianshi(a,8); } panduan(a,8); } } void juzhenanjian (u8 a,u8 i) { u8 cishu=0; u8 key=0; while(cishu<=7) { GPIO_KEY=0x0f; if(GPIO_KEY!=0x0f) { delay(100); cishu++; if(GPIO_KEY!=0x0f) { switch(GPIO_KEY) { case(0X07): key=0;break; case(0X0b): key=1;break; case(0X0d): key=2;break; case(0X0e): key=3;break; } GPIO_KEY=0xf0; switch(GPIO_KEY) { case(0X70): key=key;break; case(0Xb0): key=key+4;break; } while((a<50)&&(GPIO_KEY!=0xf0)) { delay(1000); a++; } } } a[cishu]=key; GPIO_DIG=~smg[key]; } } void xianshi (u8 a,u8 j) { u8 i; for(i=0;i<=7;i++) { switch(a[i]) { case(0): LSA=0;LSB=0;LSC=0; break; case(1): LSA=1;LSB=0;LSC=0; break; case(2): LSA=0;LSB=1;LSC=0; break; case(3): LSA=1;LSB=1;LSC=0; break; case(4): LSA=0;LSB=0;LSC=1; break; case(5): LSA=1;LSB=0;LSC=1; break; case(6): LSA=0;LSB=1;LSC=1; break; case(7): LSA=1;LSB=1;LSC=1; break; } GPIOdongtai_=smg[a[i]]; delay(100); GPIOdongtai_=0x00; } } void panduan (u8 a,u8 t) { u8 kaiguan=0,i=0,j=0; while(a[i]==b[j]) { i++;j++; if(i==8) kaiguan=1; } if(kaiguan) jidianqi(); else if (kaiguan==0) fengmingqi (); } void jidianqi () { JIDIANQI=0; delay(100000); } void fengmingqi () { u8 i=10000; while(i--) { FENGMINGQI=~FENGMINGQI; delay(10); } } void delay (u16 i) { while(i--); } 系统说 a[cishu]=key有错
no debug unit device found 怎么解决
keil5在调试仿真器是遇到的问题 仿真器亮绿灯 这是设备管理器的图片 ![图片说明](https://img-ask.csdn.net/upload/201910/17/1571304875_627024.png) 这是keil5的图片 ![图片说明](https://img-ask.csdn.net/upload/201910/17/1571304931_185264.png) 用的是JTAG仿真器
关于stc可仿真芯片用keil debug调试
为什么,每次编译之后运行debug调试,idata跟xdata数据存储器都不会清除,还是上次运行的值?但data会清楚的!求怎么设置让idata和xdata没次运行都清楚啊!![图片说明](https://img-ask.csdn.net/upload/201705/22/1495455283_314947.png)![图片说明](https://img-ask.csdn.net/upload/201705/22/1495455010_600325.png)![图片说明](https://img-ask.csdn.net/upload/201705/22/1495455321_200881.png)
51单片机编程sbit与#define的区别
在keil编程中: #define dula P2^6不对 而必须sbit dula=P2^6; 请问为何?
关于keil中头文件无法打开
最近在搞keil相关的东西,先遇到一问题,想向各位大神们请教! 我在Keil uVision4中新建了一个工程,添加了一个.c文件,其中包含#include<boebot.h>,但是问题出现了说不能打开。 请问是什么问题?
keil c51 和keil v6.12有什么区别
我需要下载的keil版本为v6.12,但在keil官网上只能买到keil c51,请问这两个有区别吗?可以买c51吗?(用于单片机编程)主要是我买的书上使用的版本为v6.12
keil中能不能调用web service服务?
大家好,现在在开发一套系统,需要实现软件与硬件的数据传输,硬件使用keil编程,采用c或者C++ ,然后把程序拷入cortex M3中,不知道能不能调用web service,希望大家告知
keil5打开keil4工程后编译出现问题怎么办?
keil5打开keil4工程出现这样的情况,编译后出现"no source": Error: #5: cannot open source input file "..\source\crc32.c": No such file or directory的问题?
关于keil软件卸载的一点提问。。。
小弟不才,昨天装了两个keil软件。一个keil uversion2,一个keil5。。当卸载keil2时,他提示找不到相关模块,当卸载keil5时,删除成功但安装目录下的文件并没有被完全删除。。。。求大神,指点一二。。。
Java学习的正确打开方式
在博主认为,对于入门级学习java的最佳学习方法莫过于视频+博客+书籍+总结,前三者博主将淋漓尽致地挥毫于这篇博客文章中,至于总结在于个人,实际上越到后面你会发现学习的最好方式就是阅读参考官方文档其次就是国内的书籍,博客次之,这又是一个层次了,这里暂时不提后面再谈。博主将为各位入门java保驾护航,各位只管冲鸭!!!上天是公平的,只要不辜负时间,时间自然不会辜负你。 何谓学习?博主所理解的学习,它是一个过程,是一个不断累积、不断沉淀、不断总结、善于传达自己的个人见解以及乐于分享的过程。
程序员必须掌握的核心算法有哪些?
由于我之前一直强调数据结构以及算法学习的重要性,所以就有一些读者经常问我,数据结构与算法应该要学习到哪个程度呢?,说实话,这个问题我不知道要怎么回答你,主要取决于你想学习到哪些程度,不过针对这个问题,我稍微总结一下我学过的算法知识点,以及我觉得值得学习的算法。这些算法与数据结构的学习大多数是零散的,并没有一本把他们全部覆盖的书籍。下面是我觉得值得学习的一些算法以及数据结构,当然,我也会整理一些看过...
前端 | 2. 正则
转载请注明以下: 本文转自清自以敬的博客:https://blog.csdn.net/qq_45791147 文章目录1.转义2.正则表达式初步2.1.匹配字符2.1.1.组成元素2.1.2.基础正则的设计 1.转义 转义的作用: 当某个字符在表达式中具有特殊含义,例如字符串引号中出现了引号,为了可以使用这些字符本身,而不是使用其在表达式中的特殊含义,则需要通过转义符“\”来构建该字符转义...
有哪些让程序员受益终生的建议
从业五年多,辗转两个大厂,出过书,创过业,从技术小白成长为基层管理,联合几个业内大牛回答下这个问题,希望能帮到大家,记得帮我点赞哦。 敲黑板!!!读了这篇文章,你将知道如何才能进大厂,如何实现财务自由,如何在工作中游刃有余,这篇文章很长,但绝对是精品,记得帮我点赞哦!!!! 一腔肺腑之言,能看进去多少,就看你自己了!!! 目录: 在校生篇: 为什么要尽量进大厂? 如何选择语言及方...
大学四年自学走来,这些私藏的实用工具/学习网站我贡献出来了
大学四年,看课本是不可能一直看课本的了,对于学习,特别是自学,善于搜索网上的一些资源来辅助,还是非常有必要的,下面我就把这几年私藏的各种资源,网站贡献出来给你们。主要有:电子书搜索、实用工具、在线视频学习网站、非视频学习网站、软件下载、面试/求职必备网站。 注意:文中提到的所有资源,文末我都给你整理好了,你们只管拿去,如果觉得不错,转发、分享就是最大的支持了。 一、电子书搜索 对于大部分程序员...
linux系列之常用运维命令整理笔录
本博客记录工作中需要的linux运维命令,大学时候开始接触linux,会一些基本操作,可是都没有整理起来,加上是做开发,不做运维,有些命令忘记了,所以现在整理成博客,当然vi,文件操作等就不介绍了,慢慢积累一些其它拓展的命令,博客不定时更新 free -m 其中:m表示兆,也可以用g,注意都要小写 Men:表示物理内存统计 total:表示物理内存总数(total=used+free) use...
比特币原理详解
一、什么是比特币 比特币是一种电子货币,是一种基于密码学的货币,在2008年11月1日由中本聪发表比特币白皮书,文中提出了一种去中心化的电子记账系统,我们平时的电子现金是银行来记账,因为银行的背后是国家信用。去中心化电子记账系统是参与者共同记账。比特币可以防止主权危机、信用风险。其好处不多做赘述,这一层面介绍的文章很多,本文主要从更深层的技术原理角度进行介绍。 二、问题引入 假设现有4个人...
程序员接私活怎样防止做完了不给钱?
首先跟大家说明一点,我们做 IT 类的外包开发,是非标品开发,所以很有可能在开发过程中会有这样那样的需求修改,而这种需求修改很容易造成扯皮,进而影响到费用支付,甚至出现做完了项目收不到钱的情况。 那么,怎么保证自己的薪酬安全呢? 我们在开工前,一定要做好一些证据方面的准备(也就是“讨薪”的理论依据),这其中最重要的就是需求文档和验收标准。一定要让需求方提供这两个文档资料作为开发的基础。之后开发...
网页实现一个简单的音乐播放器(大佬别看。(⊙﹏⊙))
今天闲着无事,就想写点东西。然后听了下歌,就打算写个播放器。 于是乎用h5 audio的加上js简单的播放器完工了。 演示地点演示 html代码如下` music 这个年纪 七月的风 音乐 ` 然后就是css`*{ margin: 0; padding: 0; text-decoration: none; list-...
Python十大装B语法
Python 是一种代表简单思想的语言,其语法相对简单,很容易上手。不过,如果就此小视 Python 语法的精妙和深邃,那就大错特错了。本文精心筛选了最能展现 Python 语法之精妙的十个知识点,并附上详细的实例代码。如能在实战中融会贯通、灵活使用,必将使代码更为精炼、高效,同时也会极大提升代码B格,使之看上去更老练,读起来更优雅。
数据库优化 - SQL优化
以实际SQL入手,带你一步一步走上SQL优化之路!
2019年11月中国大陆编程语言排行榜
2019年11月2日,我统计了某招聘网站,获得有效程序员招聘数据9万条。针对招聘信息,提取编程语言关键字,并统计如下: 编程语言比例 rank pl_ percentage 1 java 33.62% 2 cpp 16.42% 3 c_sharp 12.82% 4 javascript 12.31% 5 python 7.93% 6 go 7.25% 7 p...
通俗易懂地给女朋友讲:线程池的内部原理
餐盘在灯光的照耀下格外晶莹洁白,女朋友拿起红酒杯轻轻地抿了一小口,对我说:“经常听你说线程池,到底线程池到底是个什么原理?”
《奇巧淫技》系列-python!!每天早上八点自动发送天气预报邮件到QQ邮箱
将代码部署服务器,每日早上定时获取到天气数据,并发送到邮箱。 也可以说是一个小型人工智障。 知识可以运用在不同地方,不一定非是天气预报。
经典算法(5)杨辉三角
杨辉三角 是经典算法,这篇博客对它的算法思想进行了讲解,并有完整的代码实现。
腾讯算法面试题:64匹马8个跑道需要多少轮才能选出最快的四匹?
昨天,有网友私信我,说去阿里面试,彻底的被打击到了。问了为什么网上大量使用ThreadLocal的源码都会加上private static?他被难住了,因为他从来都没有考虑过这个问题。无独有偶,今天笔者又发现有网友吐槽了一道腾讯的面试题,我们一起来看看。 腾讯算法面试题:64匹马8个跑道需要多少轮才能选出最快的四匹? 在互联网职场论坛,一名程序员发帖求助到。二面腾讯,其中一个算法题:64匹...
面试官:你连RESTful都不知道我怎么敢要你?
干货,2019 RESTful最贱实践
Docker 从入门到掉坑
Docker 介绍 简单的对docker进行介绍,可以把它理解为一个应用程序执行的容器。但是docker本身和虚拟机还是有较为明显的出入的。我大致归纳了一下,可以总结为以下几点: docker自身也有着很多的优点,关于它的优点,可以总结为以下几项: 安装docker 从 2017 年 3 月开始 docker 在原来的基础上分为两个分支版本: Docker CE 和 Doc...
为啥国人偏爱Mybatis,而老外喜欢Hibernate/JPA呢?
关于SQL和ORM的争论,永远都不会终止,我也一直在思考这个问题。昨天又跟群里的小伙伴进行了一番讨论,感触还是有一些,于是就有了今天这篇文。 声明:本文不会下关于Mybatis和JPA两个持久层框架哪个更好这样的结论。只是摆事实,讲道理,所以,请各位看官勿喷。 一、事件起因 关于Mybatis和JPA孰优孰劣的问题,争论已经很多年了。一直也没有结论,毕竟每个人的喜好和习惯是大不相同的。我也看...
白话阿里巴巴Java开发手册高级篇
不久前,阿里巴巴发布了《阿里巴巴Java开发手册》,总结了阿里巴巴内部实际项目开发过程中开发人员应该遵守的研发流程规范,这些流程规范在一定程度上能够保证最终的项目交付质量,通过在时间中总结模式,并推广给广大开发人员,来避免研发人员在实践中容易犯的错误,确保最终在大规模协作的项目中达成既定目标。 无独有偶,笔者去年在公司里负责升级和制定研发流程、设计模板、设计标准、代码标准等规范,并在实际工作中进行...
SQL-小白最佳入门sql查询一
不要偷偷的查询我的个人资料,即使你再喜欢我,也不要这样,真的不好;
项目中的if else太多了,该怎么重构?
介绍 最近跟着公司的大佬开发了一款IM系统,类似QQ和微信哈,就是聊天软件。我们有一部分业务逻辑是这样的 if (msgType = "文本") { // dosomething } else if(msgType = "图片") { // doshomething } else if(msgType = "视频") { // doshomething } else { // doshom...
Nginx 原理和架构
Nginx 是一个免费的,开源的,高性能的 HTTP 服务器和反向代理,以及 IMAP / POP3 代理服务器。Nginx 以其高性能,稳定性,丰富的功能,简单的配置和低资源消耗而闻名。 Nginx 的整体架构 Nginx 里有一个 master 进程和多个 worker 进程。master 进程并不处理网络请求,主要负责调度工作进程:加载配置、启动工作进程及非停升级。worker 进程负责处...
Python 编程开发 实用经验和技巧
Python是一门很灵活的语言,也有很多实用的方法,有时候实现一个功能可以用多种方法实现,我这里总结了一些常用的方法和技巧,包括小数保留指定位小数、判断变量的数据类型、类方法@classmethod、制表符中文对齐、遍历字典、datetime.timedelta的使用等,会持续更新......
YouTube排名第一的励志英文演讲《Dream(梦想)》
Idon’t know what that dream is that you have, I don't care how disappointing it might have been as you've been working toward that dream,but that dream that you’re holding in your mind, that it’s po...
“狗屁不通文章生成器”登顶GitHub热榜,分分钟写出万字形式主义大作
一、垃圾文字生成器介绍 最近在浏览GitHub的时候,发现了这样一个骨骼清奇的雷人项目,而且热度还特别高。 项目中文名:狗屁不通文章生成器 项目英文名:BullshitGenerator 根据作者的介绍,他是偶尔需要一些中文文字用于GUI开发时测试文本渲染,因此开发了这个废话生成器。但由于生成的废话实在是太过富于哲理,所以最近已经被小伙伴们给玩坏了。 他的文风可能是这样的: 你发现,...
程序员:我终于知道post和get的区别
是一个老生常谈的话题,然而随着不断的学习,对于以前的认识有很多误区,所以还是需要不断地总结的,学而时习之,不亦说乎
《程序人生》系列-这个程序员只用了20行代码就拿了冠军
你知道的越多,你不知道的越多 点赞再看,养成习惯GitHub上已经开源https://github.com/JavaFamily,有一线大厂面试点脑图,欢迎Star和完善 前言 这一期不算《吊打面试官》系列的,所有没前言我直接开始。 絮叨 本来应该是没有这期的,看过我上期的小伙伴应该是知道的嘛,双十一比较忙嘛,要值班又要去帮忙拍摄年会的视频素材,还得搞个程序员一天的Vlog,还要写BU...
程序员把地府后台管理系统做出来了,还有3.0版本!12月7号最新消息:已在开发中有github地址
第一幕:缘起 听说阎王爷要做个生死簿后台管理系统,我们派去了一个程序员…… 996程序员做的梦: 第一场:团队招募 为了应对地府管理危机,阎王打算找“人”开发一套地府后台管理系统,于是就在地府总经办群中发了项目需求。 话说还是中国电信的信号好,地府都是满格,哈哈!!! 经常会有外行朋友问:看某网站做的不错,功能也简单,你帮忙做一下? 而这次,面对这样的需求,这个程序员...
网易云6亿用户音乐推荐算法
网易云音乐是音乐爱好者的集聚地,云音乐推荐系统致力于通过 AI 算法的落地,实现用户千人千面的个性化推荐,为用户带来不一样的听歌体验。 本次分享重点介绍 AI 算法在音乐推荐中的应用实践,以及在算法落地过程中遇到的挑战和解决方案。 将从如下两个部分展开: AI算法在音乐推荐中的应用 音乐场景下的 AI 思考 从 2013 年 4 月正式上线至今,网易云音乐平台持续提供着:乐屏社区、UGC...
相关热词 c# 图片上传 c# gdi 占用内存 c#中遍历字典 c#控制台模拟dos c# 斜率 最小二乘法 c#进程延迟 c# mysql完整项目 c# grid 总行数 c# web浏览器插件 c# xml 生成xsd
立即提问