Uncrustify the code

This commit is contained in:
Daniel Trevitz 2022-10-11 19:27:57 -04:00
parent 4540120e94
commit cfca364c2a
18 changed files with 3572 additions and 425 deletions

View File

@ -57,7 +57,7 @@ bool can_send(can_data_t *hcan, struct gs_host_frame *frame);
*/
uint32_t can_get_error_status(can_data_t *hcan);
#define CAN_ERRCOUNT_THRESHOLD 15 /* send an error frame if tx/rx counters increase by more than this amount */
#define CAN_ERRCOUNT_THRESHOLD 15 /* send an error frame if tx/rx counters increase by more than this amount */
/** parse status value returned by can_get_error_status().
* @param frame : will hold the generated error frame

View File

@ -38,174 +38,174 @@ THE SOFTWARE.
#include "version.h"
#define CAN_QUEUE_SIZE 64
#define CAN_QUEUE_SIZE 64
#define USBD_VID 0x1d50
#define USBD_PID_FS 0x606f
#define USBD_LANGID_STRING 1033
#define USBD_VID 0x1d50
#define USBD_PID_FS 0x606f
#define USBD_LANGID_STRING 1033
#define USBD_CONFIGURATION_STRING_FS (uint8_t*) GIT_HASH
#define USBD_INTERFACE_STRING_FS (uint8_t*) "gs_usb interface"
#define USBD_INTERFACE_STRING_FS (uint8_t*) "gs_usb interface"
#if defined(BOARD_candleLight)
#define USBD_PRODUCT_STRING_FS (uint8_t*) "candleLight USB to CAN adapter"
#define USBD_MANUFACTURER_STRING (uint8_t*) "bytewerk"
#define DFU_INTERFACE_STRING_FS (uint8_t*) "candleLight firmware upgrade interface"
#define CAN_S_Pin GPIO_PIN_13
#define CAN_S_GPIO_Port GPIOC
#define USBD_PRODUCT_STRING_FS (uint8_t*) "candleLight USB to CAN adapter"
#define USBD_MANUFACTURER_STRING (uint8_t*) "bytewerk"
#define DFU_INTERFACE_STRING_FS (uint8_t*) "candleLight firmware upgrade interface"
#define CAN_S_Pin GPIO_PIN_13
#define CAN_S_GPIO_Port GPIOC
#define LEDRX_Pin GPIO_PIN_0
#define LEDRX_Mode GPIO_MODE_OUTPUT_OD
#define LEDRX_GPIO_Port GPIOA
#define LEDRX_Active_High 0
#define LEDRX_Pin GPIO_PIN_0
#define LEDRX_Mode GPIO_MODE_OUTPUT_OD
#define LEDRX_GPIO_Port GPIOA
#define LEDRX_Active_High 0
#define LEDTX_GPIO_Port GPIOA
#define LEDTX_Pin GPIO_PIN_1
#define LEDTX_Mode GPIO_MODE_OUTPUT_OD
#define LEDTX_Active_High 0
#define LEDTX_GPIO_Port GPIOA
#define LEDTX_Pin GPIO_PIN_1
#define LEDTX_Mode GPIO_MODE_OUTPUT_OD
#define LEDTX_Active_High 0
#elif defined(BOARD_CANable_MKS)
#define USBD_PRODUCT_STRING_FS (uint8_t*) "CANable-MKS gs_usb"
#define USBD_MANUFACTURER_STRING (uint8_t*) "makerbase"
#define DFU_INTERFACE_STRING_FS (uint8_t*) "CANable-MKS firmware upgrade interface"
#define USBD_PRODUCT_STRING_FS (uint8_t*) "CANable-MKS gs_usb"
#define USBD_MANUFACTURER_STRING (uint8_t*) "makerbase"
#define DFU_INTERFACE_STRING_FS (uint8_t*) "CANable-MKS firmware upgrade interface"
// SILENT pin not connected
// SILENT pin not connected
#define LEDRX_GPIO_Port GPIOA
#define LEDRX_Pin GPIO_PIN_1
#define LEDRX_Mode GPIO_MODE_OUTPUT_OD
#define LEDRX_GPIO_Port GPIOA
#define LEDRX_Pin GPIO_PIN_1
#define LEDRX_Mode GPIO_MODE_OUTPUT_OD
#define LEDRX_Active_High 0
#define LEDTX_GPIO_Port GPIOA
#define LEDTX_Pin GPIO_PIN_0
#define LEDTX_Mode GPIO_MODE_OUTPUT_OD
#define LEDTX_GPIO_Port GPIOA
#define LEDTX_Pin GPIO_PIN_0
#define LEDTX_Mode GPIO_MODE_OUTPUT_OD
#define LEDTX_Active_High 0
#elif defined(BOARD_cantact)
#define USBD_PRODUCT_STRING_FS (uint8_t*) "cantact gs_usb"
#define USBD_MANUFACTURER_STRING (uint8_t*) "cantact.io"
#define DFU_INTERFACE_STRING_FS (uint8_t*) "cantact firmware upgrade interface"
#define USBD_PRODUCT_STRING_FS (uint8_t*) "cantact gs_usb"
#define USBD_MANUFACTURER_STRING (uint8_t*) "cantact.io"
#define DFU_INTERFACE_STRING_FS (uint8_t*) "cantact firmware upgrade interface"
// SILENT pin not connected
// SILENT pin not connected
#define LEDRX_GPIO_Port GPIOB
#define LEDRX_Pin GPIO_PIN_0 /* green */
#define LEDRX_Mode GPIO_MODE_OUTPUT_PP
#define LEDRX_GPIO_Port GPIOB
#define LEDRX_Pin GPIO_PIN_0 /* green */
#define LEDRX_Mode GPIO_MODE_OUTPUT_PP
#define LEDRX_Active_High 1
#define LEDTX_GPIO_Port GPIOB
#define LEDTX_Pin GPIO_PIN_1 /* red */
#define LEDTX_Mode GPIO_MODE_OUTPUT_PP
#define LEDTX_GPIO_Port GPIOB
#define LEDTX_Pin GPIO_PIN_1 /* red */
#define LEDTX_Mode GPIO_MODE_OUTPUT_PP
#define LEDTX_Active_High 1
#elif defined(BOARD_canable)
#define USBD_PRODUCT_STRING_FS (uint8_t*) "canable gs_usb"
#define USBD_MANUFACTURER_STRING (uint8_t*) "canable.io"
#define DFU_INTERFACE_STRING_FS (uint8_t*) "canable firmware upgrade interface"
#define USBD_PRODUCT_STRING_FS (uint8_t*) "canable gs_usb"
#define USBD_MANUFACTURER_STRING (uint8_t*) "canable.io"
#define DFU_INTERFACE_STRING_FS (uint8_t*) "canable firmware upgrade interface"
// SILENT pin not connected
// SILENT pin not connected
#define LEDRX_GPIO_Port GPIOB
#define LEDRX_Pin GPIO_PIN_0 /* green */
#define LEDRX_Mode GPIO_MODE_OUTPUT_PP
#define LEDRX_GPIO_Port GPIOB
#define LEDRX_Pin GPIO_PIN_0 /* green */
#define LEDRX_Mode GPIO_MODE_OUTPUT_PP
#define LEDRX_Active_High 1
#define LEDTX_GPIO_Port GPIOB
#define LEDTX_Pin GPIO_PIN_1 /* blue */
#define LEDTX_Mode GPIO_MODE_OUTPUT_PP
#define LEDTX_GPIO_Port GPIOB
#define LEDTX_Pin GPIO_PIN_1 /* blue */
#define LEDTX_Mode GPIO_MODE_OUTPUT_PP
#define LEDTX_Active_High 0
#elif defined(BOARD_usb2can)
#define USBD_PRODUCT_STRING_FS (uint8_t*) "USB2CAN RCA gs_usb"
#define USBD_MANUFACTURER_STRING (uint8_t*) "Roboter Club Aachen"
#define DFU_INTERFACE_STRING_FS (uint8_t*) "usb2can firmware upgrade interface"
#define USBD_PRODUCT_STRING_FS (uint8_t*) "USB2CAN RCA gs_usb"
#define USBD_MANUFACTURER_STRING (uint8_t*) "Roboter Club Aachen"
#define DFU_INTERFACE_STRING_FS (uint8_t*) "usb2can firmware upgrade interface"
// SILENT pin not connected
// SILENT pin not connected
#define LED4_GPIO_Port GPIOA
#define LED4_Pin GPIO_PIN_0 /* white */
#define LED4_Mode GPIO_MODE_OUTPUT_OD
#define LED4_Pin GPIO_PIN_0 /* white */
#define LED4_Mode GPIO_MODE_OUTPUT_OD
#define LED4_Active_Low
#define LEDTX_GPIO_Port GPIOA
#define LEDTX_Pin GPIO_PIN_1 /* blue */
#define LEDTX_Mode GPIO_MODE_OUTPUT_OD
#define LEDTX_GPIO_Port GPIOA
#define LEDTX_Pin GPIO_PIN_1 /* blue */
#define LEDTX_Mode GPIO_MODE_OUTPUT_OD
#define LEDTX_Active_High 0
#define LED3_GPIO_Port GPIOA
#define LED3_Pin GPIO_PIN_2 /* red */
#define LED3_Mode GPIO_MODE_OUTPUT_OD
#define LED3_GPIO_Port GPIOA
#define LED3_Pin GPIO_PIN_2 /* red */
#define LED3_Mode GPIO_MODE_OUTPUT_OD
#define LED3_Active_Low
#define LEDRX_GPIO_Port GPIOB
#define LEDRX_Pin GPIO_PIN_3 /* green */
#define LEDRX_Mode GPIO_MODE_OUTPUT_OD
#define LEDRX_GPIO_Port GPIOB
#define LEDRX_Pin GPIO_PIN_3 /* green */
#define LEDRX_Mode GPIO_MODE_OUTPUT_OD
#define LEDRX_Active_High 0
#elif defined(BOARD_canalyze)
#define USBD_PRODUCT_STRING_FS (uint8_t*) "CANAlyze gs_usb"
#define USBD_MANUFACTURER_STRING (uint8_t*) "STMicroelectronics"
#define DFU_INTERFACE_STRING_FS (uint8_t*) "CANAlyze firmware upgrade interface"
#define USBD_PRODUCT_STRING_FS (uint8_t*) "CANAlyze gs_usb"
#define USBD_MANUFACTURER_STRING (uint8_t*) "STMicroelectronics"
#define DFU_INTERFACE_STRING_FS (uint8_t*) "CANAlyze firmware upgrade interface"
// SILENT pin not connected
// SILENT pin not connected
#define LEDRX_GPIO_Port GPIOB
#define LEDRX_Pin GPIO_PIN_0 /* green */
#define LEDRX_Mode GPIO_MODE_OUTPUT_PP
#define LEDRX_GPIO_Port GPIOB
#define LEDRX_Pin GPIO_PIN_0 /* green */
#define LEDRX_Mode GPIO_MODE_OUTPUT_PP
#define LEDRX_Active_High 1
#define LEDTX_GPIO_Port GPIOB
#define LEDTX_Pin GPIO_PIN_1 /* red */
#define LEDTX_Mode GPIO_MODE_OUTPUT_PP
#define LEDTX_GPIO_Port GPIOB
#define LEDTX_Pin GPIO_PIN_1 /* red */
#define LEDTX_Mode GPIO_MODE_OUTPUT_PP
#define LEDTX_Active_High 1
#elif defined(BOARD_cannette)
#define USBD_PRODUCT_STRING_FS (uint8_t*) "cannette gs_usb"
#define USBD_MANUFACTURER_STRING (uint8_t*) "chacaltech"
#define DFU_INTERFACE_STRING_FS (uint8_t*) "cannette firmware upgrade interface"
#define USBD_PRODUCT_STRING_FS (uint8_t*) "cannette gs_usb"
#define USBD_MANUFACTURER_STRING (uint8_t*) "chacaltech"
#define DFU_INTERFACE_STRING_FS (uint8_t*) "cannette firmware upgrade interface"
// SILENT pin not connected
// SILENT pin not connected
#define LEDRX_GPIO_Port GPIOA
#define LEDRX_Pin GPIO_PIN_9 /* RX: green */
#define LEDRX_Mode GPIO_MODE_OUTPUT_OD
#define LEDRX_Active_High 0
#define LEDRX_GPIO_Port GPIOA
#define LEDRX_Pin GPIO_PIN_9 /* RX: green */
#define LEDRX_Mode GPIO_MODE_OUTPUT_OD
#define LEDRX_Active_High 0
#define LEDTX_GPIO_Port GPIOA
#define LEDTX_Pin GPIO_PIN_8 /* TX: red */
#define LEDTX_Mode GPIO_MODE_OUTPUT_OD
#define LEDTX_Active_High 0
#define LEDTX_GPIO_Port GPIOA
#define LEDTX_Pin GPIO_PIN_8 /* TX: red */
#define LEDTX_Mode GPIO_MODE_OUTPUT_OD
#define LEDTX_Active_High 0
#define nCANSTBY_Port GPIOC
#define nCANSTBY_Pin GPIO_PIN_14 /* control xceiver standby, active low */
#define nCANSTBY_Port GPIOC
#define nCANSTBY_Pin GPIO_PIN_14 /* control xceiver standby, active low */
#define nCANSTBY_Active_High 1
#define nSI86EN_Port GPIOC
#define nSI86EN_Pin GPIO_PIN_13 /* enable power to Si86xx isolater, active low */
#define nSI86EN_Port GPIOC
#define nSI86EN_Pin GPIO_PIN_13 /* enable power to Si86xx isolater, active low */
#define DCDCEN_Port GPIOC
#define DCDCEN_Pin GPIO_PIN_15 /* activate DCDC converter, active high */
#define DCDCEN_Port GPIOC
#define DCDCEN_Pin GPIO_PIN_15 /* activate DCDC converter, active high */
#elif defined(BOARD_STM32F4_DevBoard)
#define USBD_PRODUCT_STRING_FS (uint8_t*) "STM32F4VE Dev Board"
#define USBD_MANUFACTURER_STRING (uint8_t*) "misc"
#define DFU_INTERFACE_STRING_FS (uint8_t*) "STM32F4VE firmware upgrade interface"
#define DFU_INTERFACE_STRING_FS (uint8_t*) "STM32F4VE firmware upgrade interface"
#define CAN_S_Pin GPIO_PIN_10
#define CAN_S_GPIO_Port GPIOA
#define CAN_S_Pin GPIO_PIN_10
#define CAN_S_GPIO_Port GPIOA
#define LEDRX_GPIO_Port GPIOA
#define LEDRX_Pin GPIO_PIN_6
#define LEDRX_Mode GPIO_MODE_OUTPUT_OD
#define LEDRX_Active_High 0
#define LEDRX_GPIO_Port GPIOA
#define LEDRX_Pin GPIO_PIN_6
#define LEDRX_Mode GPIO_MODE_OUTPUT_OD
#define LEDRX_Active_High 0
#define LEDTX_GPIO_Port GPIOA
#define LEDTX_Pin GPIO_PIN_7
#define LEDTX_Mode GPIO_MODE_OUTPUT_OD
#define LEDTX_Active_High 0
#define LEDTX_GPIO_Port GPIOA
#define LEDTX_Pin GPIO_PIN_7
#define LEDTX_Mode GPIO_MODE_OUTPUT_OD
#define LEDTX_Active_High 0
#define USB_GPIO_Port GPIOA
#define USB_Pin_DM GPIO_PIN_11
#define USB_Pin_DP GPIO_PIN_12
#define USB_GPIO_Port GPIOA
#define USB_Pin_DM GPIO_PIN_11
#define USB_Pin_DP GPIO_PIN_12
#else
#error please define BOARD

View File

@ -26,131 +26,131 @@ THE SOFTWARE.
#pragma once
#define u32 uint32_t
#define u8 uint8_t
#define u32 uint32_t
#define u8 uint8_t
#define GSUSB_ENDPOINT_IN 0x81
#define GSUSB_ENDPOINT_OUT 0x02
#define GSUSB_ENDPOINT_IN 0x81
#define GSUSB_ENDPOINT_OUT 0x02
#define GS_CAN_MODE_NORMAL 0
#define GS_CAN_MODE_LISTEN_ONLY (1<<0)
#define GS_CAN_MODE_LOOP_BACK (1<<1)
#define GS_CAN_MODE_TRIPLE_SAMPLE (1<<2)
#define GS_CAN_MODE_ONE_SHOT (1<<3)
#define GS_CAN_MODE_HW_TIMESTAMP (1<<4)
#define GS_CAN_MODE_NORMAL 0
#define GS_CAN_MODE_LISTEN_ONLY (1<<0)
#define GS_CAN_MODE_LOOP_BACK (1<<1)
#define GS_CAN_MODE_TRIPLE_SAMPLE (1<<2)
#define GS_CAN_MODE_ONE_SHOT (1<<3)
#define GS_CAN_MODE_HW_TIMESTAMP (1<<4)
/* #define GS_CAN_FEATURE_IDENTIFY (1<<5) */
/* #define GS_CAN_FEATURE_USER_ID (1<<6) */
#define GS_CAN_MODE_PAD_PKTS_TO_MAX_PKT_SIZE (1<<7)
#define GS_CAN_MODE_FD (1<<8) /* switch device to CAN-FD mode */
#define GS_CAN_MODE_PAD_PKTS_TO_MAX_PKT_SIZE (1<<7)
#define GS_CAN_MODE_FD (1<<8) /* switch device to CAN-FD mode */
/* #define GS_CAN_FEATURE_REQ_USB_QUIRK_LPC546XX (1<<9) */
/* #define GS_CAN_FEATURE_BT_CONST_EXT (1<<10) */
/* #define GS_CAN_FEATURE_TERMINATION (1<<11) */
#define GS_CAN_FEATURE_LISTEN_ONLY (1<<0)
#define GS_CAN_FEATURE_LOOP_BACK (1<<1)
#define GS_CAN_FEATURE_TRIPLE_SAMPLE (1<<2)
#define GS_CAN_FEATURE_ONE_SHOT (1<<3)
#define GS_CAN_FEATURE_HW_TIMESTAMP (1<<4)
#define GS_CAN_FEATURE_IDENTIFY (1<<5)
#define GS_CAN_FEATURE_USER_ID (1<<6)
#define GS_CAN_FEATURE_LISTEN_ONLY (1<<0)
#define GS_CAN_FEATURE_LOOP_BACK (1<<1)
#define GS_CAN_FEATURE_TRIPLE_SAMPLE (1<<2)
#define GS_CAN_FEATURE_ONE_SHOT (1<<3)
#define GS_CAN_FEATURE_HW_TIMESTAMP (1<<4)
#define GS_CAN_FEATURE_IDENTIFY (1<<5)
#define GS_CAN_FEATURE_USER_ID (1<<6)
#define GS_CAN_FEATURE_PAD_PKTS_TO_MAX_PKT_SIZE (1<<7)
#define GS_CAN_FEATURE_FD (1<<8) /* device supports CAN-FD */
#define GS_CAN_FEATURE_FD (1<<8) /* device supports CAN-FD */
/* request workaround for LPC546XX erratum USB.15:
* let host driver add a padding byte to each USB frame
*/
#define GS_CAN_FEATURE_REQ_USB_QUIRK_LPC546XX (1<<9)
#define GS_CAN_FEATURE_REQ_USB_QUIRK_LPC546XX (1<<9)
/* device supports separate bit timing constants for CAN-FD
* arbitration and data phase, see:
* GS_USB_BREQ_BT_CONST_EXT and struct gs_device_bt_const_extended
*/
#define GS_CAN_FEATURE_BT_CONST_EXT (1<<10)
#define GS_CAN_FEATURE_BT_CONST_EXT (1<<10)
/* device supports switchable termination, see:
* - GS_USB_BREQ_SET_TERMINATION
* - GS_USB_BREQ_GET_TERMINATION
* - struct gs_device_termination_state
*/
#define GS_CAN_FEATURE_TERMINATION (1<<11)
#define GS_CAN_FEATURE_TERMINATION (1<<11)
#define GS_CAN_FLAG_OVERFLOW (1<<0)
#define GS_CAN_FLAG_FD (1<<1) /* is a CAN-FD frame */
#define GS_CAN_FLAG_BRS (1<<2) /* bit rate switch (for CAN-FD frames) */
#define GS_CAN_FLAG_ESI (1<<3) /* error state indicator (for CAN-FD frames) */
#define GS_CAN_FLAG_OVERFLOW (1<<0)
#define GS_CAN_FLAG_FD (1<<1) /* is a CAN-FD frame */
#define GS_CAN_FLAG_BRS (1<<2) /* bit rate switch (for CAN-FD frames) */
#define GS_CAN_FLAG_ESI (1<<3) /* error state indicator (for CAN-FD frames) */
#define CAN_EFF_FLAG 0x80000000U /* EFF/SFF is set in the MSB */
#define CAN_RTR_FLAG 0x40000000U /* remote transmission request */
#define CAN_ERR_FLAG 0x20000000U /* error message frame */
#define CAN_EFF_FLAG 0x80000000U /* EFF/SFF is set in the MSB */
#define CAN_RTR_FLAG 0x40000000U /* remote transmission request */
#define CAN_ERR_FLAG 0x20000000U /* error message frame */
#define CAN_ERR_DLC 8 /* dlc for error message frames */
#define CAN_ERR_DLC 8 /* dlc for error message frames */
/* error class (mask) in can_id */
#define CAN_ERR_TX_TIMEOUT 0x00000001U /* TX timeout (by netdevice driver) */
#define CAN_ERR_LOSTARB 0x00000002U /* lost arbitration / data[0] */
#define CAN_ERR_CRTL 0x00000004U /* controller problems / data[1] */
#define CAN_ERR_PROT 0x00000008U /* protocol violations / data[2..3] */
#define CAN_ERR_TRX 0x00000010U /* transceiver status / data[4] */
#define CAN_ERR_ACK 0x00000020U /* received no ACK on transmission */
#define CAN_ERR_BUSOFF 0x00000040U /* bus off */
#define CAN_ERR_BUSERROR 0x00000080U /* bus error (may flood!) */
#define CAN_ERR_RESTARTED 0x00000100U /* controller restarted */
#define CAN_ERR_TX_TIMEOUT 0x00000001U /* TX timeout (by netdevice driver) */
#define CAN_ERR_LOSTARB 0x00000002U /* lost arbitration / data[0] */
#define CAN_ERR_CRTL 0x00000004U /* controller problems / data[1] */
#define CAN_ERR_PROT 0x00000008U /* protocol violations / data[2..3] */
#define CAN_ERR_TRX 0x00000010U /* transceiver status / data[4] */
#define CAN_ERR_ACK 0x00000020U /* received no ACK on transmission */
#define CAN_ERR_BUSOFF 0x00000040U /* bus off */
#define CAN_ERR_BUSERROR 0x00000080U /* bus error (may flood!) */
#define CAN_ERR_RESTARTED 0x00000100U /* controller restarted */
/* arbitration lost in bit ... / data[0] */
#define CAN_ERR_LOSTARB_UNSPEC 0x00 /* unspecified */
/* else bit number in bitstream */
#define CAN_ERR_LOSTARB_UNSPEC 0x00 /* unspecified */
/* else bit number in bitstream */
/* error status of CAN-controller / data[1] */
#define CAN_ERR_CRTL_UNSPEC 0x00 /* unspecified */
#define CAN_ERR_CRTL_UNSPEC 0x00 /* unspecified */
#define CAN_ERR_CRTL_RX_OVERFLOW 0x01 /* RX buffer overflow */
#define CAN_ERR_CRTL_TX_OVERFLOW 0x02 /* TX buffer overflow */
#define CAN_ERR_CRTL_RX_WARNING 0x04 /* reached warning level for RX errors */
#define CAN_ERR_CRTL_TX_WARNING 0x08 /* reached warning level for TX errors */
#define CAN_ERR_CRTL_RX_PASSIVE 0x10 /* reached error passive status RX */
#define CAN_ERR_CRTL_TX_PASSIVE 0x20 /* reached error passive status TX */
/* (at least one error counter exceeds */
/* the protocol-defined level of 127) */
#define CAN_ERR_CRTL_ACTIVE 0x40 /* recovered to error active state */
#define CAN_ERR_CRTL_RX_WARNING 0x04 /* reached warning level for RX errors */
#define CAN_ERR_CRTL_TX_WARNING 0x08 /* reached warning level for TX errors */
#define CAN_ERR_CRTL_RX_PASSIVE 0x10 /* reached error passive status RX */
#define CAN_ERR_CRTL_TX_PASSIVE 0x20 /* reached error passive status TX */
/* (at least one error counter exceeds */
/* the protocol-defined level of 127) */
#define CAN_ERR_CRTL_ACTIVE 0x40 /* recovered to error active state */
/* error in CAN protocol (type) / data[2] */
#define CAN_ERR_PROT_UNSPEC 0x00 /* unspecified */
#define CAN_ERR_PROT_BIT 0x01 /* single bit error */
#define CAN_ERR_PROT_FORM 0x02 /* frame format error */
#define CAN_ERR_PROT_STUFF 0x04 /* bit stuffing error */
#define CAN_ERR_PROT_BIT0 0x08 /* unable to send dominant bit */
#define CAN_ERR_PROT_BIT1 0x10 /* unable to send recessive bit */
#define CAN_ERR_PROT_OVERLOAD 0x20 /* bus overload */
#define CAN_ERR_PROT_ACTIVE 0x40 /* active error announcement */
#define CAN_ERR_PROT_TX 0x80 /* error occurred on transmission */
#define CAN_ERR_PROT_UNSPEC 0x00 /* unspecified */
#define CAN_ERR_PROT_BIT 0x01 /* single bit error */
#define CAN_ERR_PROT_FORM 0x02 /* frame format error */
#define CAN_ERR_PROT_STUFF 0x04 /* bit stuffing error */
#define CAN_ERR_PROT_BIT0 0x08 /* unable to send dominant bit */
#define CAN_ERR_PROT_BIT1 0x10 /* unable to send recessive bit */
#define CAN_ERR_PROT_OVERLOAD 0x20 /* bus overload */
#define CAN_ERR_PROT_ACTIVE 0x40 /* active error announcement */
#define CAN_ERR_PROT_TX 0x80 /* error occurred on transmission */
/* error in CAN protocol (location) / data[3] */
#define CAN_ERR_PROT_LOC_UNSPEC 0x00 /* unspecified */
#define CAN_ERR_PROT_LOC_SOF 0x03 /* start of frame */
#define CAN_ERR_PROT_LOC_UNSPEC 0x00 /* unspecified */
#define CAN_ERR_PROT_LOC_SOF 0x03 /* start of frame */
#define CAN_ERR_PROT_LOC_ID28_21 0x02 /* ID bits 28 - 21 (SFF: 10 - 3) */
#define CAN_ERR_PROT_LOC_ID20_18 0x06 /* ID bits 20 - 18 (SFF: 2 - 0 )*/
#define CAN_ERR_PROT_LOC_SRTR 0x04 /* substitute RTR (SFF: RTR) */
#define CAN_ERR_PROT_LOC_IDE 0x05 /* identifier extension */
#define CAN_ERR_PROT_LOC_SRTR 0x04 /* substitute RTR (SFF: RTR) */
#define CAN_ERR_PROT_LOC_IDE 0x05 /* identifier extension */
#define CAN_ERR_PROT_LOC_ID17_13 0x07 /* ID bits 17-13 */
#define CAN_ERR_PROT_LOC_ID12_05 0x0F /* ID bits 12-5 */
#define CAN_ERR_PROT_LOC_ID04_00 0x0E /* ID bits 4-0 */
#define CAN_ERR_PROT_LOC_RTR 0x0C /* RTR */
#define CAN_ERR_PROT_LOC_RES1 0x0D /* reserved bit 1 */
#define CAN_ERR_PROT_LOC_RES0 0x09 /* reserved bit 0 */
#define CAN_ERR_PROT_LOC_DLC 0x0B /* data length code */
#define CAN_ERR_PROT_LOC_DATA 0x0A /* data section */
#define CAN_ERR_PROT_LOC_RTR 0x0C /* RTR */
#define CAN_ERR_PROT_LOC_RES1 0x0D /* reserved bit 1 */
#define CAN_ERR_PROT_LOC_RES0 0x09 /* reserved bit 0 */
#define CAN_ERR_PROT_LOC_DLC 0x0B /* data length code */
#define CAN_ERR_PROT_LOC_DATA 0x0A /* data section */
#define CAN_ERR_PROT_LOC_CRC_SEQ 0x08 /* CRC sequence */
#define CAN_ERR_PROT_LOC_CRC_DEL 0x18 /* CRC delimiter */
#define CAN_ERR_PROT_LOC_ACK 0x19 /* ACK slot */
#define CAN_ERR_PROT_LOC_ACK 0x19 /* ACK slot */
#define CAN_ERR_PROT_LOC_ACK_DEL 0x1B /* ACK delimiter */
#define CAN_ERR_PROT_LOC_EOF 0x1A /* end of frame */
#define CAN_ERR_PROT_LOC_INTERM 0x12 /* intermission */
#define CAN_ERR_PROT_LOC_EOF 0x1A /* end of frame */
#define CAN_ERR_PROT_LOC_INTERM 0x12 /* intermission */
/* error status of CAN-transceiver / data[4] */
/* CANH CANL */
#define CAN_ERR_TRX_UNSPEC 0x00 /* 0000 0000 */
#define CAN_ERR_TRX_CANH_NO_WIRE 0x04 /* 0000 0100 */
#define CAN_ERR_TRX_UNSPEC 0x00 /* 0000 0000 */
#define CAN_ERR_TRX_CANH_NO_WIRE 0x04 /* 0000 0100 */
#define CAN_ERR_TRX_CANH_SHORT_TO_BAT 0x05 /* 0000 0101 */
#define CAN_ERR_TRX_CANH_SHORT_TO_VCC 0x06 /* 0000 0110 */
#define CAN_ERR_TRX_CANH_SHORT_TO_GND 0x07 /* 0000 0111 */
#define CAN_ERR_TRX_CANL_NO_WIRE 0x40 /* 0100 0000 */
#define CAN_ERR_TRX_CANL_NO_WIRE 0x40 /* 0100 0000 */
#define CAN_ERR_TRX_CANL_SHORT_TO_BAT 0x50 /* 0101 0000 */
#define CAN_ERR_TRX_CANL_SHORT_TO_VCC 0x60 /* 0110 0000 */
#define CAN_ERR_TRX_CANL_SHORT_TO_GND 0x70 /* 0111 0000 */

View File

@ -38,7 +38,7 @@ typedef enum {
} led_mode_t;
typedef enum {
led_rx = 0, //will also index into array led_state[]
led_rx = 0, //will also index into array led_state[]
led_tx
} led_num_t;
@ -72,7 +72,7 @@ void led_init(
led_data_t *leds,
void* led_rx_port, uint16_t led_rx_pin, bool led_rx_active_high,
void* led_tx_port, uint16_t led_tx_pin, bool led_tx_active_high
);
);
void led_set_mode(led_data_t *leds,led_mode_t mode);
void led_run_sequence(led_data_t *leds, const led_seq_step_t *sequence, int32_t num_repeat);
void led_indicate_trx(led_data_t *leds, led_num_t num);

View File

@ -35,26 +35,26 @@ THE SOFTWARE.
/* Define these here so they can be referenced in other files */
#define CAN_DATA_MAX_PACKET_SIZE 32 /* Endpoint IN & OUT Packet size */
#define CAN_CMD_PACKET_SIZE 64 /* Control Endpoint Packet size */
#define USB_CAN_CONFIG_DESC_SIZ 50
#define NUM_CAN_CHANNEL 1
#define USBD_GS_CAN_VENDOR_CODE 0x20
#define DFU_INTERFACE_NUM 1
#define DFU_INTERFACE_STR_INDEX 0xE0
#define CAN_DATA_MAX_PACKET_SIZE 32 /* Endpoint IN & OUT Packet size */
#define CAN_CMD_PACKET_SIZE 64 /* Control Endpoint Packet size */
#define USB_CAN_CONFIG_DESC_SIZ 50
#define NUM_CAN_CHANNEL 1
#define USBD_GS_CAN_VENDOR_CODE 0x20
#define DFU_INTERFACE_NUM 1
#define DFU_INTERFACE_STR_INDEX 0xE0
extern USBD_ClassTypeDef USBD_GS_CAN;
#if defined(STM32F0)
# define USB_INTERFACE USB
# define USB_INTERRUPT USB_IRQn
# define CAN_INTERFACE CAN
# define USB_INTERFACE USB
# define USB_INTERRUPT USB_IRQn
# define CAN_INTERFACE CAN
# define CAN_CLOCK_SPEED 48000000
#elif defined(STM32F4)
# define USB_INTERFACE USB_OTG_FS
# define USB_INTERRUPT OTG_FS_IRQn
# define CAN_INTERFACE CAN1
# define USB_INTERFACE USB_OTG_FS
# define USB_INTERRUPT OTG_FS_IRQn
# define CAN_INTERFACE CAN1
# define CAN_CLOCK_SPEED 42000000
// RX FIFO is defined in words, so divide bytes by 4

View File

@ -87,10 +87,10 @@ static inline void restore_irq(bool was_enabled)
* https://barrgroup.com/embedded-systems/how-to/define-assert-macro
*
*/
#define assert_basic(exp) \
if (exp) { \
} else \
assert_failed()
#define assert_basic(exp) \
if (exp) { \
} else \
assert_failed()
/** halt / set core to debug state with BKPT.
*

View File

@ -1,28 +1,28 @@
/*
The MIT License (MIT)
The MIT License (MIT)
Copyright (c) 2016 Hubert Denkmair
Copyright (c) 2016 Hubert Denkmair
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
*/
#include "can.h"
#include "config.h"
@ -86,11 +86,11 @@ void can_init(can_data_t *hcan, CAN_TypeDef *instance)
bool can_set_bittiming(can_data_t *hcan, uint16_t brp, uint8_t phase_seg1, uint8_t phase_seg2, uint8_t sjw)
{
if ( (brp>0) && (brp<=1024)
&& (phase_seg1>0) && (phase_seg1<=16)
&& (phase_seg2>0) && (phase_seg2<=8)
&& (sjw>0) && (sjw<=4)
) {
if ( (brp>0) && (brp<=1024)
&& (phase_seg1>0) && (phase_seg1<=16)
&& (phase_seg2>0) && (phase_seg2<=8)
&& (sjw>0) && (sjw<=4)
) {
hcan->brp = brp & 0x3FF;
hcan->phase_seg1 = phase_seg1;
hcan->phase_seg2 = phase_seg2;
@ -106,34 +106,34 @@ void can_enable(can_data_t *hcan, bool loop_back, bool listen_only, bool one_sho
CAN_TypeDef *can = hcan->instance;
uint32_t mcr = CAN_MCR_INRQ
| CAN_MCR_ABOM
| CAN_MCR_TXFP
| (one_shot ? CAN_MCR_NART : 0);
| CAN_MCR_ABOM
| CAN_MCR_TXFP
| (one_shot ? CAN_MCR_NART : 0);
uint32_t btr = ((uint32_t)(hcan->sjw-1)) << 24
| ((uint32_t)(hcan->phase_seg1-1)) << 16
| ((uint32_t)(hcan->phase_seg2-1)) << 20
| (hcan->brp - 1)
| (loop_back ? CAN_MODE_LOOPBACK : 0)
| (listen_only ? CAN_MODE_SILENT : 0);
| ((uint32_t)(hcan->phase_seg1-1)) << 16
| ((uint32_t)(hcan->phase_seg2-1)) << 20
| (hcan->brp - 1)
| (loop_back ? CAN_MODE_LOOPBACK : 0)
| (listen_only ? CAN_MODE_SILENT : 0);
// Reset CAN peripheral
can->MCR |= CAN_MCR_RESET;
while((can->MCR & CAN_MCR_RESET) != 0); // reset bit is set to zero after reset
while((can->MSR & CAN_MSR_SLAK) == 0); // should be in sleep mode after reset
while ((can->MCR & CAN_MCR_RESET) != 0); // reset bit is set to zero after reset
while ((can->MSR & CAN_MSR_SLAK) == 0); // should be in sleep mode after reset
// Completely reset while being of the bus
rcc_reset(can);
can->MCR |= CAN_MCR_INRQ ;
while((can->MSR & CAN_MSR_INAK) == 0);
can->MCR |= CAN_MCR_INRQ;
while ((can->MSR & CAN_MSR_INAK) == 0);
can->MCR = mcr;
can->BTR = btr;
can->MCR &= ~CAN_MCR_INRQ;
while((can->MSR & CAN_MSR_INAK) != 0);
while ((can->MSR & CAN_MSR_INAK) != 0);
uint32_t filter_bit = 0x00000001;
can->FMR |= CAN_FMR_FINIT;
@ -141,8 +141,8 @@ void can_enable(can_data_t *hcan, bool loop_back, bool listen_only, bool one_sho
can->FA1R &= ~filter_bit; // disable filter
can->FS1R |= filter_bit; // set to single 32-bit filter mode
can->FM1R &= ~filter_bit; // set filter mask mode for filter 0
can->sFilterRegister[0].FR1 = 0; // filter ID = 0
can->sFilterRegister[0].FR2 = 0; // filter Mask = 0
can->sFilterRegister[0].FR1 = 0; // filter ID = 0
can->sFilterRegister[0].FR2 = 0; // filter Mask = 0
can->FFA1R &= ~filter_bit; // assign filter 0 to FIFO 0
can->FA1R |= filter_bit; // enable filter
can->FMR &= ~CAN_FMR_FINIT;
@ -158,7 +158,7 @@ void can_disable(can_data_t *hcan)
#ifdef nCANSTBY_Pin
HAL_GPIO_WritePin(nCANSTBY_Port, nCANSTBY_Pin, GPIO_PIN_RESET);
#endif
can->MCR |= CAN_MCR_INRQ ; // send can controller into initialization mode
can->MCR |= CAN_MCR_INRQ; // send can controller into initialization mode
}
bool can_is_enabled(can_data_t *hcan)
@ -201,7 +201,7 @@ bool can_receive(can_data_t *hcan, struct gs_host_frame *rx_frame)
rx_frame->data[6] = (fifo->RDHR >> 16) & 0xFF;
rx_frame->data[7] = (fifo->RDHR >> 24) & 0xFF;
can->RF0R |= CAN_RF0R_RFOM0; // release FIFO
can->RF0R |= CAN_RF0R_RFOM0; // release FIFO
return true;
} else {
@ -233,7 +233,7 @@ bool can_send(can_data_t *hcan, struct gs_host_frame *frame)
/* first, clear transmission request */
mb->TIR &= CAN_TI0R_TXRQ;
if (frame->can_id & CAN_EFF_FLAG) { // extended id
if (frame->can_id & CAN_EFF_FLAG) { // extended id
mb->TIR = CAN_ID_EXT | (frame->can_id & 0x1FFFFFFF) << 3;
} else {
mb->TIR = (frame->can_id & 0x7FF) << 21;
@ -247,13 +247,13 @@ bool can_send(can_data_t *hcan, struct gs_host_frame *frame)
mb->TDTR |= frame->can_dlc & 0x0F;
mb->TDLR =
( frame->data[3] << 24 )
( frame->data[3] << 24 )
| ( frame->data[2] << 16 )
| ( frame->data[1] << 8 )
| ( frame->data[0] << 0 );
mb->TDHR =
( frame->data[7] << 24 )
( frame->data[7] << 24 )
| ( frame->data[6] << 16 )
| ( frame->data[5] << 8 )
| ( frame->data[4] << 0 );

View File

@ -30,8 +30,8 @@ THE SOFTWARE.
#define RESET_TO_BOOTLOADER_MAGIC_CODE 0xDEADBEEF
#define SYSMEM_STM32F042 0x1FFFC400
#define SYSMEM_STM32F072 0x1FFFC800
#define SYSMEM_STM32F042 0x1FFFC400
#define SYSMEM_STM32F072 0x1FFFC800
static uint32_t dfu_reset_to_bootloader_magic;
@ -80,7 +80,7 @@ static void dfu_hack_boot_pin_f042(void)
static void dfu_jump_to_bootloader(uint32_t sysmem_base)
{
void (*bootloader)(void) = (void (*)(void)) (*((uint32_t *) (sysmem_base + 4)));
void (*bootloader)(void) = (void (*)(void))(*((uint32_t *) (sysmem_base + 4)));
__set_MSP(*(__IO uint32_t*) sysmem_base);
bootloader();

View File

@ -86,13 +86,13 @@ void flash_flush(void)
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_SR_PGERR);
#elif defined(STM32F4)
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR |
FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR);
FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR);
#endif
uint32_t error = 0;
HAL_FLASHEx_Erase(&erase_pages, &error);
if (error==0xFFFFFFFF) { // erase finished successfully
HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, (uint32_t)&flash_data_rom.user_id[0], flash_data_ram.user_id[0]);
}
HAL_FLASH_Lock();
}

View File

@ -74,7 +74,7 @@ void gpio_init(void)
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(nCANSTBY_Port, &GPIO_InitStruct); //xceiver standby.
HAL_GPIO_Init(nCANSTBY_Port, &GPIO_InitStruct); //xceiver standby.
#endif
#if defined(BOARD_cannette)
@ -83,14 +83,14 @@ void gpio_init(void)
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(DCDCEN_Port, &GPIO_InitStruct); //start DCDC (TODO : wait until enumerated)
HAL_GPIO_Init(DCDCEN_Port, &GPIO_InitStruct); //start DCDC (TODO : wait until enumerated)
HAL_GPIO_WritePin(nSI86EN_Port, nSI86EN_Pin, GPIO_PIN_RESET);
GPIO_InitStruct.Pin = nSI86EN_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(nSI86EN_Port, &GPIO_InitStruct); //enable si86
HAL_GPIO_Init(nSI86EN_Port, &GPIO_InitStruct); //enable si86
#endif // BOARD_cannette
#if defined(BOARD_STM32F4_DevBoard)

View File

@ -30,13 +30,13 @@ THE SOFTWARE.
void NMI_Handler(void)
{
__asm__("BKPT");
__asm__ ("BKPT");
while (1);
}
void HardFault_Handler(void)
{
__asm__("BKPT");
__asm__ ("BKPT");
while (1);
}
@ -54,157 +54,157 @@ void USB_Handler(void)
void Default_Handler(void)
{
__asm__("BKPT");
__asm__ ("BKPT");
while (1);
}
extern void Reset_Handler(void);
typedef void(*pFunc)(void);
typedef void (*pFunc)(void);
extern uint32_t __StackTop;
#if defined(STM32F0)
__attribute__((used, section(".vectors")))
const pFunc InterruptVectorTable[48] = {
(pFunc)(&__StackTop), // initial stack pointer
Reset_Handler, // reset handler
NMI_Handler, // -14: NMI
HardFault_Handler, // -13: HardFault
0, // -12: MemManage_Handler
0, // -11: BusFault_Handler
0, // -10: UsageFault_Handler
0, //
0, //
0, //
0, //
0, // -5: SVC_Handler
0, // -4: DebugMon_Handler
0, //
0, // -2: PendSV
SysTick_Handler, // -1: SysTick
(pFunc)(&__StackTop), // initial stack pointer
Reset_Handler, // reset handler
NMI_Handler, // -14: NMI
HardFault_Handler, // -13: HardFault
0, // -12: MemManage_Handler
0, // -11: BusFault_Handler
0, // -10: UsageFault_Handler
0, //
0, //
0, //
0, //
0, // -5: SVC_Handler
0, // -4: DebugMon_Handler
0, //
0, // -2: PendSV
SysTick_Handler, // -1: SysTick
// External Interrupts
0, // int 0: WWDG
0, // int 1: PVD
0, // int 2: RTC
0, // int 3: FLASH
0, // int 4: RCC_CRS
0, // int 5: EXTI0_1
0, // int 6: EXTI2_3
0, // int 7: EXTI4_15
0, // int 8: TSC
0, // int 9: DMA_CH1
0, // int 10: DMA_CH2_3
0, // int 11: DMA_CH4_5_6_7
0, // int 12: ADC_COMP
0, // int 13: TIM1_BRK_UP_TRG_COM
0, // int 14: TIM1_CC
0, // int 15: TIM2
0, // int 16: TIM3
0, // int 17: TIM6_DAC
0, // int 18: TIM7
0, // int 19: TIM14
0, // int 20: TIM15
0, // int 21: TIM16
0, // int 22: TIM17
0, // int 23: I2C1
0, // int 24: I2C2
0, // int 25: SPI1
0, // int 26: SPI2
0, // int 27: USART1
0, // int 28: USART2
0, // int 29: USART3_4
0, // int 30: CEC_CAN
USB_Handler, // int 31: USB
0, // int 0: WWDG
0, // int 1: PVD
0, // int 2: RTC
0, // int 3: FLASH
0, // int 4: RCC_CRS
0, // int 5: EXTI0_1
0, // int 6: EXTI2_3
0, // int 7: EXTI4_15
0, // int 8: TSC
0, // int 9: DMA_CH1
0, // int 10: DMA_CH2_3
0, // int 11: DMA_CH4_5_6_7
0, // int 12: ADC_COMP
0, // int 13: TIM1_BRK_UP_TRG_COM
0, // int 14: TIM1_CC
0, // int 15: TIM2
0, // int 16: TIM3
0, // int 17: TIM6_DAC
0, // int 18: TIM7
0, // int 19: TIM14
0, // int 20: TIM15
0, // int 21: TIM16
0, // int 22: TIM17
0, // int 23: I2C1
0, // int 24: I2C2
0, // int 25: SPI1
0, // int 26: SPI2
0, // int 27: USART1
0, // int 28: USART2
0, // int 29: USART3_4
0, // int 30: CEC_CAN
USB_Handler, // int 31: USB
};
#elif defined(STM32F4)
__attribute__((used, section(".vectors")))
const pFunc InterruptVectorTable[84] = {
(pFunc)(&__StackTop), // initial stack pointer
Reset_Handler, // reset handler
NMI_Handler, // -14: NMI
HardFault_Handler, // -13: HardFault
0, // -12: MemManage_Handler
0, // -11: BusFault_Handler
0, // -10: UsageFault_Handler
0, //
0, //
0, //
0, //
0, // -5: SVC_Handler
0, // -4: DebugMon_Handler
0, //
0, // -2: PendSV
SysTick_Handler, // -1: SysTick
(pFunc)(&__StackTop), // initial stack pointer
Reset_Handler, // reset handler
NMI_Handler, // -14: NMI
HardFault_Handler, // -13: HardFault
0, // -12: MemManage_Handler
0, // -11: BusFault_Handler
0, // -10: UsageFault_Handler
0, //
0, //
0, //
0, //
0, // -5: SVC_Handler
0, // -4: DebugMon_Handler
0, //
0, // -2: PendSV
SysTick_Handler, // -1: SysTick
// External Interrupts
0, // int 0: WWDG
0, // int 1: PVD
0, // int 2: tamper and timestamp, EXTI line
0, // int 3: RTC
0, // int 4: FLASH
0, // int 5: RCC
0, // int 6: EXTI Line 0
0, // int 7: EXTI Line 1
0, // int 8: EXTI Line 2
0, // int 9: EXTI Line 3
0, // int 10: EXTI Line 4
0, // int 11: DMA Stream 0
0, // int 12: DMA Stream 1
0, // int 13: DMA Stream 2
0, // int 14: DMA Stream 3
0, // int 15: DMA Stream 4
0, // int 16: DMA Stream 5
0, // int 17: DMA Stream 6
0, // int 18: ADCs
0, // int 19: CAN1 TX
0, // int 20: CAN1 RX0
0, // int 21: CAN1 RX1
0, // int 22: CAN1 SCE
0, // int 23: External Line [9:5]s
0, // int 24: TIM1 Break and TIM9
0, // int 25: TIM1 Update and TIM10
0, // int 26: TIM1 Trigger and Commutation and TIM11
0, // int 27: TIM1 Capture Compare
0, // int 28: TIM2
0, // int 29: TIM3
0, // int 30: TIM4
0, // int 31: I2C1 Event
0, // int 32: I2C1 Error
0, // int 33: I2C2 Event
0, // int 34: I2C2 Error
0, // int 35: SPI1
0, // int 36: SPI2
0, // int 36: USART1
0, // int 37: USART2
0, // int 38: USART3
0, // int 39: External Line [15:10]s
0, // int 40: RTC Alarm (A and B), EXTI Line
0, // int 41: USB OTG FS Wakeup, EXTI Line
0, // int 42: TIM8 Break and TIM12
0, // int 43: TIM8 Update and TIM13
0, // int 44: TIM8 Trigger and Commutation and TIM14
0, // int 45: TIM8 Capture Compare
0, // int 46: DMA1 Stream7
0, // int 47: FSMC
0, // int 48: SDIO
0, // int 49: TIM5
0, // int 50: SPI3
0, // int 51: UART4
0, // int 52: UART5
0, // int 53: TIM6 and DAC1&2 underrun errors
0, // int 54: TIM7
0, // int 55: DMA2 Stream 0
0, // int 56: DMA2 Stream 1
0, // int 57: DMA2 Stream 2
0, // int 58: DMA2 Stream 3
0, // int 59: DMA2 Stream 4
0, // int 60: Ethernet
0, // int 61: Ethernet Wakeup, EXTI Line
0, // int 62: CAN2 TX
0, // int 63: CAN2 RX0
0, // int 64: CAN2 RX1
0, // int 65: CAN2 SCE
USB_Handler, // int 66: USB OTG FS
// don't need to define any interrupts after this one
0, // int 0: WWDG
0, // int 1: PVD
0, // int 2: tamper and timestamp, EXTI line
0, // int 3: RTC
0, // int 4: FLASH
0, // int 5: RCC
0, // int 6: EXTI Line 0
0, // int 7: EXTI Line 1
0, // int 8: EXTI Line 2
0, // int 9: EXTI Line 3
0, // int 10: EXTI Line 4
0, // int 11: DMA Stream 0
0, // int 12: DMA Stream 1
0, // int 13: DMA Stream 2
0, // int 14: DMA Stream 3
0, // int 15: DMA Stream 4
0, // int 16: DMA Stream 5
0, // int 17: DMA Stream 6
0, // int 18: ADCs
0, // int 19: CAN1 TX
0, // int 20: CAN1 RX0
0, // int 21: CAN1 RX1
0, // int 22: CAN1 SCE
0, // int 23: External Line [9:5]s
0, // int 24: TIM1 Break and TIM9
0, // int 25: TIM1 Update and TIM10
0, // int 26: TIM1 Trigger and Commutation and TIM11
0, // int 27: TIM1 Capture Compare
0, // int 28: TIM2
0, // int 29: TIM3
0, // int 30: TIM4
0, // int 31: I2C1 Event
0, // int 32: I2C1 Error
0, // int 33: I2C2 Event
0, // int 34: I2C2 Error
0, // int 35: SPI1
0, // int 36: SPI2
0, // int 36: USART1
0, // int 37: USART2
0, // int 38: USART3
0, // int 39: External Line [15:10]s
0, // int 40: RTC Alarm (A and B), EXTI Line
0, // int 41: USB OTG FS Wakeup, EXTI Line
0, // int 42: TIM8 Break and TIM12
0, // int 43: TIM8 Update and TIM13
0, // int 44: TIM8 Trigger and Commutation and TIM14
0, // int 45: TIM8 Capture Compare
0, // int 46: DMA1 Stream7
0, // int 47: FSMC
0, // int 48: SDIO
0, // int 49: TIM5
0, // int 50: SPI3
0, // int 51: UART4
0, // int 52: UART5
0, // int 53: TIM6 and DAC1&2 underrun errors
0, // int 54: TIM7
0, // int 55: DMA2 Stream 0
0, // int 56: DMA2 Stream 1
0, // int 57: DMA2 Stream 2
0, // int 58: DMA2 Stream 3
0, // int 59: DMA2 Stream 4
0, // int 60: Ethernet
0, // int 61: Ethernet Wakeup, EXTI Line
0, // int 62: CAN2 TX
0, // int 63: CAN2 RX0
0, // int 64: CAN2 RX1
0, // int 65: CAN2 SCE
USB_Handler, // int 66: USB OTG FS
// don't need to define any interrupts after this one
};
#endif

View File

@ -34,7 +34,7 @@ void led_init(
led_data_t *leds,
void* led_rx_port, uint16_t led_rx_pin, bool led_rx_active_high,
void* led_tx_port, uint16_t led_tx_pin, bool led_tx_active_high
) {
) {
memset(leds, 0, sizeof(led_data_t));
leds->led_state[led_rx].port = led_rx_port;
leds->led_state[led_rx].pin = led_rx_pin;
@ -67,7 +67,7 @@ static uint32_t led_set_sequence_step(led_data_t *leds, uint32_t step_num)
led_set(&leds->led_state[led_tx], step->state & 0x02);
uint32_t delta = 10 * step->time_in_10ms;
if (delta > INT32_MAX) {
delta = INT32_MAX; //clamp
delta = INT32_MAX; //clamp
}
leds->t_sequence_next = HAL_GetTick() + delta;
return delta;
@ -89,7 +89,7 @@ void led_indicate_trx(led_data_t *leds, led_num_t num)
led_state_t *led = &leds->led_state[num];
if ( SEQ_ISPASSED(now, led->on_until) &&
SEQ_ISPASSED(now, led->off_until) ) {
SEQ_ISPASSED(now, led->off_until) ) {
led->off_until = now + 30;
led->on_until = now + 45;
}

View File

@ -70,7 +70,7 @@ int main(void)
led_init(&hLED, LEDRX_GPIO_Port, LEDRX_Pin, LEDRX_Active_High, LEDTX_GPIO_Port, LEDTX_Pin, LEDTX_Active_High);
/* nice wake-up pattern */
for(uint8_t i=0; i<10; i++)
for (uint8_t i=0; i<10; i++)
{
HAL_GPIO_TogglePin(LEDRX_GPIO_Port, LEDRX_Pin);
HAL_Delay(50);
@ -86,7 +86,7 @@ int main(void)
q_frame_pool = queue_create(CAN_QUEUE_SIZE);
q_from_host = queue_create(CAN_QUEUE_SIZE);
q_to_host = queue_create(CAN_QUEUE_SIZE);
q_to_host = queue_create(CAN_QUEUE_SIZE);
assert_basic(q_frame_pool && q_from_host && q_to_host);
struct gs_host_frame *msgbuf = calloc(CAN_QUEUE_SIZE, sizeof(struct gs_host_frame));
@ -191,7 +191,7 @@ void SystemClock_Config(void)
#if defined(STM32F0)
RCC_PeriphCLKInitTypeDef PeriphClkInit;
RCC_CRSInitTypeDef RCC_CRSInitStruct;
RCC_CRSInitTypeDef RCC_CRSInitStruct;
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48;
RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
@ -258,7 +258,7 @@ void send_to_host(void)
{
struct gs_host_frame *frame = queue_pop_front(q_to_host);
if(!frame)
if (!frame)
return;
if (USBD_GS_CAN_SendFrame(&hUSB, frame) == USBD_OK) {

View File

@ -1,17 +1,17 @@
#include <stdint.h>
#include <stddef.h>
typedef struct _copy_table_t
typedef struct _copy_table_t
{
uint32_t const* src;
uint32_t* dest;
uint32_t wlen;
uint32_t wlen;
} copy_table_t;
typedef struct _zero_table_t
{
uint32_t* dest;
uint32_t wlen;
uint32_t wlen;
} zero_table_t;
extern const copy_table_t __copy_table_start__;
@ -49,6 +49,6 @@ void Reset_Handler(void)
void _exit(int code)
{
(void) code;
__asm__("BKPT");
__asm__ ("BKPT");
while (1);
}

View File

@ -32,7 +32,7 @@ PCD_HandleTypeDef hpcd_USB_FS;
void HAL_PCD_MspInit(PCD_HandleTypeDef* hpcd)
{
if(hpcd->Instance==USB_INTERFACE) {
if (hpcd->Instance==USB_INTERFACE) {
#if defined(USB)
__HAL_RCC_USB_CLK_ENABLE();
@ -46,7 +46,7 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef* hpcd)
void HAL_PCD_MspDeInit(PCD_HandleTypeDef* hpcd)
{
if(hpcd->Instance==USB_INTERFACE) {
if (hpcd->Instance==USB_INTERFACE) {
#if defined(USB)
__HAL_RCC_USB_CLK_DISABLE();
#elif defined(USB_OTG_FS)
@ -142,10 +142,10 @@ USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev)
* 0x158 - 0x1D7 (128 bytes) EP1 OUT (buffer 2)
*/
#if defined(USB)
HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x00 , PCD_SNG_BUF, 0x18);
HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x80 , PCD_SNG_BUF, 0x58);
HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x81 , PCD_SNG_BUF, 0x98);
HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x02 , PCD_DBL_BUF, 0x00D80158);
HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData, 0x00, PCD_SNG_BUF, 0x18);
HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData, 0x80, PCD_SNG_BUF, 0x58);
HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData, 0x81, PCD_SNG_BUF, 0x98);
HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData, 0x02, PCD_DBL_BUF, 0x00D80158);
#elif defined(USB_OTG_FS)
HAL_PCDEx_SetRxFiFo((PCD_HandleTypeDef*)pdev->pData, USB_RX_FIFO_SIZE); // shared RX FIFO
HAL_PCDEx_SetTxFiFo((PCD_HandleTypeDef*)pdev->pData, 0U, 64U / 4U); // 0x80, 64 bytes (div by 4 for words)

View File

@ -40,7 +40,7 @@ static uint8_t *USBD_FS_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t
#ifdef USB_SUPPORT_USER_STRING_DESC
uint8_t *USBD_FS_USRStringDesc(USBD_SpeedTypeDef speed, uint8_t idx, uint16_t *length);
#endif /* USB_SUPPORT_USER_STRING_DESC */
#endif /* USB_SUPPORT_USER_STRING_DESC */
const USBD_DescriptorsTypeDef FS_Desc = {
USBD_FS_DeviceDescriptor,
@ -74,7 +74,7 @@ static const uint8_t USBD_FS_DeviceDesc[USB_LEN_DEV_DESC] = {
USBD_IDX_PRODUCT_STR, /* Index of product string */
USBD_IDX_SERIAL_STR, /* Index of serial number string */
USBD_MAX_NUM_CONFIGURATION /* bNumConfigurations */
} ;
};
/* USB Standard Device Descriptor */
static const uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] =
@ -121,7 +121,7 @@ uint8_t *USBD_FS_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
UNUSED(speed);
hex32(buf , *(uint32_t*)(UID_BASE ));
hex32(buf, *(uint32_t*)(UID_BASE ));
hex32(buf + 8, *(uint32_t*)(UID_BASE + 4));
hex32(buf + 16, *(uint32_t*)(UID_BASE + 8));

View File

@ -211,12 +211,12 @@ static const uint8_t USBD_MS_COMP_ID_FEATURE_DESC[] = {
/* Microsoft Extended Properties Feature Descriptor */
static const uint8_t USBD_MS_EXT_PROP_FEATURE_DESC[] = {
0x92, 0x00, 0x00, 0x00, /* length */
0x00, 0x01, /* version 1.0 */
0x00, 0x01, /* version 1.0 */
0x05, 0x00, /* descr index (0x0005) */
0x01, 0x00, /* number of sections */
0x88, 0x00, 0x00, 0x00, /* property section size */
0x07, 0x00, 0x00, 0x00, /* property data type 7: Unicode REG_MULTI_SZ */
0x2a, 0x00, /* property name length */
0x2a, 0x00, /* property name length */
0x44, 0x00, 0x65, 0x00, /* property name "DeviceInterfaceGUIDs" */
0x76, 0x00, 0x69, 0x00,
@ -315,7 +315,7 @@ static uint8_t USBD_GS_CAN_Start(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
UNUSED(cfgidx);
assert_basic(pdev->pClassData);
USBD_LL_OpenEP(pdev, GSUSB_ENDPOINT_IN, USBD_EP_TYPE_BULK, CAN_DATA_MAX_PACKET_SIZE);
USBD_LL_OpenEP(pdev, GSUSB_ENDPOINT_IN, USBD_EP_TYPE_BULK, CAN_DATA_MAX_PACKET_SIZE);
USBD_LL_OpenEP(pdev, GSUSB_ENDPOINT_OUT, USBD_EP_TYPE_BULK, CAN_DATA_MAX_PACKET_SIZE);
USBD_GS_CAN_PrepareReceive(pdev);
@ -407,11 +407,11 @@ static uint8_t USBD_GS_CAN_EP0_RxReady(USBD_HandleTypeDef *pdev) {
hcan->pad_pkts_to_max_pkt_size = (mode->flags & GS_CAN_MODE_PAD_PKTS_TO_MAX_PKT_SIZE) != 0;
can_enable(ch,
(mode->flags & GS_CAN_MODE_LOOP_BACK) != 0,
(mode->flags & GS_CAN_MODE_LISTEN_ONLY) != 0,
(mode->flags & GS_CAN_MODE_ONE_SHOT) != 0
// triple sampling not supported on bxCAN
);
(mode->flags & GS_CAN_MODE_LOOP_BACK) != 0,
(mode->flags & GS_CAN_MODE_LISTEN_ONLY) != 0,
(mode->flags & GS_CAN_MODE_ONE_SHOT) != 0
// triple sampling not supported on bxCAN
);
led_set_mode(hcan->leds, led_mode_normal);
}
@ -427,7 +427,7 @@ static uint8_t USBD_GS_CAN_EP0_RxReady(USBD_HandleTypeDef *pdev) {
timing->prop_seg + timing->phase_seg1,
timing->phase_seg2,
timing->sjw
);
);
}
break;
@ -521,9 +521,9 @@ static uint8_t USBD_GS_CAN_Vendor_Request(USBD_HandleTypeDef *pdev, USBD_SetupRe
if (
(req_type == 0x01) // class request
&& (req_rcpt == 0x01) // recipient: interface
&& (req->wIndex == DFU_INTERFACE_NUM)
) {
&& (req_rcpt == 0x01) // recipient: interface
&& (req->wIndex == DFU_INTERFACE_NUM)
) {
return USBD_GS_CAN_DFU_Request(pdev, req);
} else {
return USBD_GS_CAN_Config_Request(pdev, req);
@ -677,7 +677,7 @@ uint8_t USBD_GS_CAN_SendFrame(USBD_HandleTypeDef *pdev, struct gs_host_frame *fr
send_addr = (uint8_t *)frame;
if(hcan->pad_pkts_to_max_pkt_size){
if (hcan->pad_pkts_to_max_pkt_size) {
// When talking to WinUSB it seems to help a lot if the
// size of packet you send equals the max packet size.
// In this mode, fill packets out to max packet size and
@ -727,18 +727,18 @@ void USBD_GS_CAN_SuspendCallback(USBD_HandleTypeDef *pdev)
// Disable CAN and go off bus on USB suspend
USBD_GS_CAN_HandleTypeDef *hcan = (USBD_GS_CAN_HandleTypeDef*) pdev->pClassData;
if(hcan != NULL)
if (hcan != NULL)
{
for(uint32_t i=0; i<NUM_CAN_CHANNEL; i++)
for (uint32_t i=0; i<NUM_CAN_CHANNEL; i++)
{
if(hcan->channels[i] != NULL)
if (hcan->channels[i] != NULL)
can_disable(hcan->channels[i]);
}
}
if(hcan != NULL && hcan->leds != NULL)
if (hcan != NULL && hcan->leds != NULL)
led_set_mode(hcan->leds, led_mode_off);
is_usb_suspend_cb = true;
}

3147
uncrustify.cfg Normal file

File diff suppressed because it is too large Load Diff