Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
use_can_stm.h
00001 #ifndef USE_CAN_F303K8 00002 #define USE_CAN_F303K8 00003 00004 #include "mbed.h" 00005 #include "stm32f3xx_hal_can.h" 00006 #include "stm32f3xx_hal.h" 00007 #include "core_cm4.h" 00008 00009 namespace CAN_STATE{ 00010 const int RESET = 0x00U; /*!< CAN not yet initialized or disabled */ 00011 const int READY = 0x01U; /*!< CAN initialized and ready for use */ 00012 const int BUSY = 0x02U; /*!< CAN process is ongoing */ 00013 const int BUSY_TX = 0x12U; /*!< CAN process is ongoing */ 00014 const int BUSY_RX0 = 0x22U; /*!< CAN process is ongoing */ 00015 const int BUSY_RX1 = 0x32U; /*!< CAN process is ongoing */ 00016 const int BUSY_TX_RX0 = 0x42U; /*!< CAN process is ongoing */ 00017 const int BUSY_TX_RX1 = 0x52U; /*!< CAN process is ongoing */ 00018 const int BUSY_RX0_RX1 = 0x62U; /*!< CAN process is ongoing */ 00019 const int BUSY_TX_RX0_RX1 = 0x72U; /*!< CAN process is ongoing */ 00020 const int TIMEOUT = 0x03U; /*!< CAN in Timeout state */ 00021 const int ERROR = 0x04U; /*!< CAN error state */ 00022 }; 00023 00024 enum FIFO{ 00025 FIFO_0, 00026 FIFO_1, 00027 }; 00028 00029 enum IRQ_MODE{ 00030 RX_FIFO0, 00031 RX_FIFO1, 00032 TX_READY, 00033 }; 00034 00035 enum PROCESS_RESULT{ 00036 //ERROR = 0, 00037 //SUCCESS = 1, 00038 BUSY = 2, 00039 TIMEOUT = 3, 00040 }; 00041 00042 enum BAUDRATE{ 00043 CAN_125KHZ, 00044 CAN_250KHZ, 00045 CAN_500KHZ, 00046 CAN_1MHZ, 00047 }; 00048 00049 enum DATA_CATEGORY{ 00050 STANDARD_ID, 00051 EXTENDED_ID, 00052 IDE, 00053 RTR, 00054 DLC, 00055 FMI, 00056 FIFO_NUMBER, 00057 RX_DATA_0, 00058 RX_DATA_1, 00059 RX_DATA_2, 00060 RX_DATA_3, 00061 RX_DATA_4, 00062 RX_DATA_5, 00063 RX_DATA_6, 00064 RX_DATA_7, 00065 }; 00066 00067 class CanStm{ 00068 00069 public: 00070 int init(int baudrate); 00071 int transmit(uint32_t id, int format, uint8_t* tx_array); 00072 int receive(); 00073 int getData(int category_data); 00074 int attach(uint32_t id,void func(),int irq_mode); 00075 void exitIrqHandler(void); 00076 CanRxMsgTypeDef rx_data[2]; 00077 CAN_HandleTypeDef canHandler; 00078 private: 00079 HAL_StatusTypeDef hal_can_init(CAN_HandleTypeDef* hcan); 00080 HAL_StatusTypeDef hal_can_transmit(CAN_HandleTypeDef* hcan, uint32_t Timeout); 00081 HAL_StatusTypeDef hal_can_configfilter(CAN_HandleTypeDef* hcan,CAN_FilterConfTypeDef* sFilterConfig); 00082 void hal_can_mspinit(CAN_HandleTypeDef* hcan); 00083 void setPriority(IRQn_Type IRQn); 00084 void ConvertMessage(CAN_HandleTypeDef* hcan,CanRxMsgTypeDef* rx_message,uint32_t FIFONumber); 00085 00086 uint32_t use_fifo; 00087 uint32_t function; 00088 uint16_t can_rx_data[9]; 00089 float CAN_TIMEOUT_VALUE; 00090 Timer timer; 00091 }; 00092 #endif
Generated on Wed Jul 13 2022 06:52:25 by
