This commit is contained in:
pathletboy 2015-11-23 13:24:08 +08:00
commit 1f0c6ad9d5
8 changed files with 120 additions and 21 deletions

View File

@ -15,6 +15,7 @@
#include <board.h>
#include <rtthread.h>
#include <rtdevice.h>
#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

View File

@ -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);

View File

@ -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;
}
@ -1173,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;

View File

@ -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_*/

View File

@ -15,6 +15,7 @@
#include <rthw.h>
#include <rtdevice.h>
#include <board.h>
#include <gpio.h>
#ifdef RT_USING_PIN

View File

@ -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

View File

@ -14,7 +14,7 @@
<TargetCommonOption>
<Device>STM32F103ZE</Device>
<Vendor>STMicroelectronics</Vendor>
<PackID>Keil.STM32F1xx_DFP.1.0.5</PackID>
<PackID>Keil.STM32F1xx_DFP.1.1.0</PackID>
<PackURL>http://www.keil.com/pack/</PackURL>
<Cpu>IROM(0x08000000,0x80000) IRAM(0x20000000,0x10000) CPUTYPE("Cortex-M3") CLOCK(12000000) ELITTLE</Cpu>
<FlashUtilSpec></FlashUtilSpec>
@ -37,8 +37,8 @@
<BinPath></BinPath>
<IncludePath></IncludePath>
<LibPath></LibPath>
<RegisterFilePath>ST\STM32F10x\</RegisterFilePath>
<DBRegisterFilePath>ST\STM32F10x\</DBRegisterFilePath>
<RegisterFilePath></RegisterFilePath>
<DBRegisterFilePath></DBRegisterFilePath>
<TargetStatus>
<Error>0</Error>
<ExitCodeStop>0</ExitCodeStop>
@ -84,6 +84,8 @@
<UserProg2Name></UserProg2Name>
<UserProg1Dos16Mode>0</UserProg1Dos16Mode>
<UserProg2Dos16Mode>0</UserProg2Dos16Mode>
<nStopA1X>0</nStopA1X>
<nStopA2X>0</nStopA2X>
</AfterMake>
<SelectedForBatchBuild>0</SelectedForBatchBuild>
<SVCSIdString></SVCSIdString>
@ -106,13 +108,13 @@
</CommonProperty>
<DllOption>
<SimDllName>SARMCM3.DLL</SimDllName>
<SimDllArguments></SimDllArguments>
<SimDlgDll>DARMSTM.DLL</SimDlgDll>
<SimDlgDllArguments>-pSTM32F103ZE</SimDlgDllArguments>
<SimDllArguments> -REMAP</SimDllArguments>
<SimDlgDll>DCM.DLL</SimDlgDll>
<SimDlgDllArguments>-pCM3</SimDlgDllArguments>
<TargetDllName>SARMCM3.DLL</TargetDllName>
<TargetDllArguments></TargetDllArguments>
<TargetDlgDll>TARMSTM.DLL</TargetDlgDll>
<TargetDlgDllArguments>-pSTM32F103ZE</TargetDlgDllArguments>
<TargetDlgDll>TCM.DLL</TargetDlgDll>
<TargetDlgDllArguments>-pCM3</TargetDlgDllArguments>
</DllOption>
<DebugOption>
<OPTHX>
@ -147,7 +149,7 @@
<RestoreSysVw>1</RestoreSysVw>
</Target>
<RunDebugAfterBuild>0</RunDebugAfterBuild>
<TargetSelection>6</TargetSelection>
<TargetSelection>1</TargetSelection>
<SimDlls>
<CpuDll></CpuDll>
<CpuDllArguments></CpuDllArguments>
@ -161,7 +163,7 @@
<PeripheralDll></PeripheralDll>
<PeripheralDllArguments></PeripheralDllArguments>
<InitializationFile></InitializationFile>
<Driver>Segger\JL2CM3.dll</Driver>
<Driver>BIN\UL2CM3.DLL</Driver>
</TargetDlls>
</DebugOption>
<Utilities>
@ -171,10 +173,10 @@
<RunIndependent>0</RunIndependent>
<UpdateFlashBeforeDebugging>1</UpdateFlashBeforeDebugging>
<Capability>1</Capability>
<DriverSelection>4099</DriverSelection>
<DriverSelection>4096</DriverSelection>
</Flash1>
<bUseTDR>1</bUseTDR>
<Flash2>Segger\JL2CM3.dll</Flash2>
<Flash2>BIN\UL2CM3.DLL</Flash2>
<Flash3>"" ()</Flash3>
<Flash4></Flash4>
<pFcarmOut></pFcarmOut>
@ -359,11 +361,13 @@
<wLevel>0</wLevel>
<uThumb>0</uThumb>
<uSurpInc>0</uSurpInc>
<uC99>0</uC99>
<uC99>1</uC99>
<useXO>0</useXO>
<v6Lang>0</v6Lang>
<v6LangP>0</v6LangP>
<VariousControls>
<MiscControls></MiscControls>
<Define>STM32F10X_HD, USE_STDPERIPH_DRIVER</Define>
<Define>USE_STDPERIPH_DRIVER</Define>
<Undefine></Undefine>
<IncludePath>.;..\..\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</IncludePath>
</VariousControls>
@ -418,6 +422,11 @@
<FileType>1</FileType>
<FilePath>applications\startup.c</FilePath>
</File>
<File>
<FileName>canapp.c</FileName>
<FileType>1</FileType>
<FilePath>.\applications\canapp.c</FilePath>
</File>
</Files>
</Group>
<Group>
@ -443,6 +452,16 @@
<FileType>1</FileType>
<FilePath>drivers\usart.c</FilePath>
</File>
<File>
<FileName>bxcan.c</FileName>
<FileType>1</FileType>
<FilePath>.\drivers\bxcan.c</FilePath>
</File>
<File>
<FileName>gpio.c</FileName>
<FileType>1</FileType>
<FilePath>.\drivers\gpio.c</FilePath>
</File>
</Files>
</Group>
<Group>
@ -708,6 +727,16 @@
<FileType>1</FileType>
<FilePath>..\..\components\drivers\src\workqueue.c</FilePath>
</File>
<File>
<FileName>pin.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\components\drivers\misc\pin.c</FilePath>
</File>
<File>
<FileName>can.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\components\drivers\can\can.c</FilePath>
</File>
</Files>
</Group>
<Group>
@ -786,7 +815,7 @@
<File>
<FileName>components.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\components\init\components.c</FilePath>
<FilePath>..\..\src\components.c</FilePath>
</File>
</Files>
</Group>

View File

@ -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 */