From 33de63fbe26f2c6b292cf71608bf9a6ee7b5859b Mon Sep 17 00:00:00 2001 From: "Aubr.Cool" Date: Wed, 28 Oct 2015 16:26:32 +0800 Subject: [PATCH 1/2] correct compile error when using can --- bsp/stm32f10x/applications/canapp.c | 5 ++- bsp/stm32f10x/drivers/board.h | 1 + bsp/stm32f10x/drivers/bxcan.c | 12 ++++++ bsp/stm32f10x/drivers/bxcan.h | 37 +++++++++++++++++ bsp/stm32f10x/drivers/gpio.c | 1 + bsp/stm32f10x/drivers/gpio.h | 11 ++++++ bsp/stm32f10x/project.uvprojx | 61 +++++++++++++++++++++-------- bsp/stm32f10x/rtconfig.h | 7 ++++ 8 files changed, 117 insertions(+), 18 deletions(-) diff --git a/bsp/stm32f10x/applications/canapp.c b/bsp/stm32f10x/applications/canapp.c index 9789bc6c0..d5294250b 100644 --- a/bsp/stm32f10x/applications/canapp.c +++ b/bsp/stm32f10x/applications/canapp.c @@ -15,6 +15,7 @@ #include #include #include +#include "gpio.h" #ifdef RT_USING_CAN #define CANRT1 8 #define CANERR1 9 @@ -28,8 +29,8 @@ static struct canledtype { #ifdef USING_BXCAN1 { - {CANRT1, PIN_MODE_OUTPUT_OD,}, - {CANERR1, PIN_MODE_OUTPUT_OD,}, + {CANRT1, PIN_MODE_OUTPUT,}, + {CANERR1, PIN_MODE_OUTPUT,}, }, #endif /*USING_BXCAN1*/ #ifdef USING_BXCAN2 diff --git a/bsp/stm32f10x/drivers/board.h b/bsp/stm32f10x/drivers/board.h index 0fa68651b..ea55b782f 100644 --- a/bsp/stm32f10x/drivers/board.h +++ b/bsp/stm32f10x/drivers/board.h @@ -43,6 +43,7 @@ #define RT_USING_UART1 #define RT_USING_UART2 #define RT_USING_UART3 +#define USING_BXCAN1 void rt_hw_board_init(void); diff --git a/bsp/stm32f10x/drivers/bxcan.c b/bsp/stm32f10x/drivers/bxcan.c index 59daea593..28849f7cd 100644 --- a/bsp/stm32f10x/drivers/bxcan.c +++ b/bsp/stm32f10x/drivers/bxcan.c @@ -27,7 +27,12 @@ #define BX_CAN_FMRNUMBER 28 #define BX_CAN2_FMRSTART 14 #endif +#ifdef STM32F10X_HD +#undef USING_BXCAN2 +#define CAN1_RX0_IRQn USB_LP_CAN1_RX0_IRQn +#define CAN1_TX_IRQn USB_HP_CAN1_TX_IRQn +#endif #define BX_CAN_MAX_FILTERS (BX_CAN_FMRNUMBER * 4) #define BX_CAN_MAX_FILTER_MASKS BX_CAN_MAX_FILTERS #define BX_CAN_FILTER_MAX_ARRAY_SIZE ((BX_CAN_MAX_FILTERS + 32 - 1) / 32) @@ -148,6 +153,7 @@ static void bxcan1_filter_init(struct rt_can_device *can) } calcfiltermasks(pbxcan); } +#ifdef USING_BXCAN2 static void bxcan2_filter_init(struct rt_can_device *can) { rt_uint32_t i; @@ -234,6 +240,8 @@ static void bxcan2_filter_init(struct rt_can_device *can) } calcfiltermasks(pbxcan); } +#endif + #define BS1SHIFT 16 #define BS2SHIFT 20 #define RRESCLSHIFT 0 @@ -320,6 +328,7 @@ static void bxcan1_hw_init(void) NVIC_InitStructure.NVIC_IRQChannel = CAN1_TX_IRQn; NVIC_Init(&NVIC_InitStructure); } +#ifdef USING_BXCAN2 static void bxcan2_hw_init(void) { GPIO_InitTypeDef GPIO_InitStructure; @@ -345,6 +354,7 @@ static void bxcan2_hw_init(void) NVIC_InitStructure.NVIC_IRQChannel = CAN2_TX_IRQn; NVIC_Init(&NVIC_InitStructure); } +#endif static inline rt_err_t bxcan_enter_init(CAN_TypeDef *pcan) { uint32_t wait_ack = 0x00000000; @@ -1010,9 +1020,11 @@ static rt_err_t configure(struct rt_can_device *can, struct can_configure *cfg) } else { +#ifdef USING_BXCAN2 bxcan2_hw_init(); bxcan_init(pbxcan, cfg->baud_rate, can->config.mode); bxcan2_filter_init(can); +#endif } return RT_EOK; } diff --git a/bsp/stm32f10x/drivers/bxcan.h b/bsp/stm32f10x/drivers/bxcan.h index 7ef77bde1..d2bdc4821 100644 --- a/bsp/stm32f10x/drivers/bxcan.h +++ b/bsp/stm32f10x/drivers/bxcan.h @@ -14,4 +14,41 @@ #ifndef BXCAN_H_ #define BXCAN_H_ +/* CAN Master Control Register bits */ + +#define MCR_DBF ((uint32_t)0x00010000) /* software master reset */ + +/* CAN Mailbox Transmit Request */ +#define TMIDxR_TXRQ ((uint32_t)0x00000001) /* Transmit mailbox request */ + +/* CAN Filter Master Register bits */ +#define FMR_FINIT ((uint32_t)0x00000001) /* Filter init mode */ + +/* Time out for INAK bit */ +#define INAK_TIMEOUT ((uint32_t)0x0000FFFF) +/* Time out for SLAK bit */ +#define SLAK_TIMEOUT ((uint32_t)0x0000FFFF) + + + +/* Flags in TSR register */ +#define CAN_FLAGS_TSR ((uint32_t)0x08000000) +/* Flags in RF1R register */ +#define CAN_FLAGS_RF1R ((uint32_t)0x04000000) +/* Flags in RF0R register */ +#define CAN_FLAGS_RF0R ((uint32_t)0x02000000) +/* Flags in MSR register */ +#define CAN_FLAGS_MSR ((uint32_t)0x01000000) +/* Flags in ESR register */ +#define CAN_FLAGS_ESR ((uint32_t)0x00F00000) + +/* Mailboxes definition */ +#define CAN_TXMAILBOX_0 ((uint8_t)0x00) +#define CAN_TXMAILBOX_1 ((uint8_t)0x01) +#define CAN_TXMAILBOX_2 ((uint8_t)0x02) + + + +#define CAN_MODE_MASK ((uint32_t) 0x00000003) + #endif /*BXCAN_H_*/ diff --git a/bsp/stm32f10x/drivers/gpio.c b/bsp/stm32f10x/drivers/gpio.c index 6e4683541..9a1b70745 100644 --- a/bsp/stm32f10x/drivers/gpio.c +++ b/bsp/stm32f10x/drivers/gpio.c @@ -15,6 +15,7 @@ #include #include #include +#include #ifdef RT_USING_PIN diff --git a/bsp/stm32f10x/drivers/gpio.h b/bsp/stm32f10x/drivers/gpio.h index a4947b100..03b744b33 100644 --- a/bsp/stm32f10x/drivers/gpio.h +++ b/bsp/stm32f10x/drivers/gpio.h @@ -14,6 +14,17 @@ #ifndef GPIO_H__ #define GPIO_H__ + +struct stm32_hw_pin_userdata +{ + int pin; + uint32_t mode; +}; + +#define PIN_USERDATA_END {-1,0} + +extern struct stm32_hw_pin_userdata stm32_pins[]; + int stm32_hw_pin_init(void); #endif diff --git a/bsp/stm32f10x/project.uvprojx b/bsp/stm32f10x/project.uvprojx index b9ffe2105..ec401a6ee 100644 --- a/bsp/stm32f10x/project.uvprojx +++ b/bsp/stm32f10x/project.uvprojx @@ -14,7 +14,7 @@ STM32F103ZE STMicroelectronics - Keil.STM32F1xx_DFP.1.0.5 + Keil.STM32F1xx_DFP.1.1.0 http://www.keil.com/pack/ IROM(0x08000000,0x80000) IRAM(0x20000000,0x10000) CPUTYPE("Cortex-M3") CLOCK(12000000) ELITTLE @@ -37,8 +37,8 @@ - ST\STM32F10x\ - ST\STM32F10x\ + + 0 0 @@ -84,6 +84,8 @@ 0 0 + 0 + 0 0 @@ -106,13 +108,13 @@ SARMCM3.DLL - - DARMSTM.DLL - -pSTM32F103ZE + -REMAP + DCM.DLL + -pCM3 SARMCM3.DLL - TARMSTM.DLL - -pSTM32F103ZE + TCM.DLL + -pCM3 @@ -147,7 +149,7 @@ 1 0 - 6 + 1 @@ -161,7 +163,7 @@ - Segger\JL2CM3.dll + BIN\UL2CM3.DLL @@ -171,10 +173,10 @@ 0 1 1 - 4099 + 4096 1 - Segger\JL2CM3.dll + BIN\UL2CM3.DLL "" () @@ -359,11 +361,13 @@ 0 0 0 - 0 + 1 0 + 0 + 0 - STM32F10X_HD, USE_STDPERIPH_DRIVER + USE_STDPERIPH_DRIVER .;..\..\components\CMSIS\Include;..\..\components\drivers\include;..\..\components\finsh;..\..\components\init;..\..\include;..\..\libcpu\arm\common;..\..\libcpu\arm\cortex-m3;Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x;Libraries\STM32F10x_StdPeriph_Driver\inc;applications;drivers @@ -398,7 +402,7 @@ - --keep __fsym_* --keep __vsym_* --keep __rt_init* + --keep __fsym_* --keep __vsym_* --keep __rt_init* @@ -418,6 +422,11 @@ 1 applications\startup.c + + canapp.c + 1 + .\applications\canapp.c + @@ -443,6 +452,16 @@ 1 drivers\usart.c + + bxcan.c + 1 + .\drivers\bxcan.c + + + gpio.c + 1 + .\drivers\gpio.c + @@ -708,6 +727,16 @@ 1 ..\..\components\drivers\src\workqueue.c + + pin.c + 1 + ..\..\components\drivers\misc\pin.c + + + can.c + 1 + ..\..\components\drivers\can\can.c + @@ -786,7 +815,7 @@ components.c 1 - ..\..\components\init\components.c + ..\..\src\components.c diff --git a/bsp/stm32f10x/rtconfig.h b/bsp/stm32f10x/rtconfig.h index 6e1aee4ea..f44884600 100644 --- a/bsp/stm32f10x/rtconfig.h +++ b/bsp/stm32f10x/rtconfig.h @@ -80,6 +80,13 @@ #define FINSH_USING_SYMTAB #define FINSH_USING_DESCRIPTION +#define RT_USING_PIN + +#define RT_USING_CAN + +#define RT_CAN_USING_BUS_HOOK + +#define RT_CAN_USING_HDR /* SECTION: device filesystem */ /* #define RT_USING_DFS */ From b2d55d2c8c7819a4ee4ef694b8431fe65e675209 Mon Sep 17 00:00:00 2001 From: "Aubr.Cool" Date: Thu, 19 Nov 2015 13:45:14 +0800 Subject: [PATCH 2/2] correct stm32f10x can sendmsg rtr flag error --- bsp/stm32f10x/drivers/bxcan.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bsp/stm32f10x/drivers/bxcan.c b/bsp/stm32f10x/drivers/bxcan.c index 28849f7cd..e19d97112 100644 --- a/bsp/stm32f10x/drivers/bxcan.c +++ b/bsp/stm32f10x/drivers/bxcan.c @@ -1185,14 +1185,14 @@ static int sendmsg(struct rt_can_device *can, const void *buf, rt_uint32_t boxno { assert_param(IS_CAN_STDID(pmsg->id)); pbxcan->sTxMailBox[boxno].TIR |= ((pmsg->id << 21) | \ - pmsg->rtr); + (pmsg->rtr << 1)); } else { assert_param(IS_CAN_EXTID(pmsg->id)); pbxcan->sTxMailBox[boxno].TIR |= ((pmsg->id << 3) | \ - pmsg->ide << 2 | \ - pmsg->rtr); + (pmsg->ide << 2) | \ + (pmsg->rtr << 1)); } pmsg->len &= (uint8_t)0x0000000F;