* [ECOS] CAN on STM32 - No transmitting
@ 2010-01-04 17:24 Bernhard Gebert
0 siblings, 0 replies; 2+ messages in thread
From: Bernhard Gebert @ 2010-01-04 17:24 UTC (permalink / raw)
To: ecos-discuss
Hello,
working with eCos 3.0 on STM32F103 single chip, my next problem is
CAN-related.
To keep the beginning as simple as possible, I decided to write an
example without eCos to test my hardware (and maybe my basic knowledge :-)).
I built an example with GCC (C++) running on my hardware without any
problems, now I want to port it to eCos. It uses an older version of the
ST peripheral lib.
I want to access the CAN-bus without a driver but directly from my
example app.
Now my problem:
Polling telegrams is possible from FIFO0, but when I enqueue a Telegram,
it never gets sent; after writing all three send buffers, the chip goes
bus-off.
Using an oscilloscope, i found out there is nothing at the output pins.
As I am able to receive correctly, and the same hw with the same code
can transmit, it might be a small bug.
Can you help me?
Brg,
Bernhard
The basic code:
void RCC_Configuration()
{
/* HCLK = SYSCLK */
RCC_HCLKConfig(RCC_SYSCLK_Div1);
/* PCLK2 = HCLK */
RCC_PCLK2Config(RCC_HCLK_Div1);
/* PCLK1 = HCLK/2 */
RCC_PCLK1Config(RCC_HCLK_Div2);
/* Enable PLL */
RCC_PLLCmd(ENABLE);
/* GPIO clock enable */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO |RCC_APB2Periph_GPIOD,
ENABLE); // CAN is D.0 and D.1
/* CAN1 Periph clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN, ENABLE);
}
void GPIO_Configuration(void)
{
#define GPIO_Remap2_CAN1 ((unsigned int)0x001D6000)
#define RCC_APB2Periph_GPIO_CAN RCC_APB2Periph_GPIOD
#define GPIO_Remap_CAN GPIO_Remap2_CAN1
#define GPIO_CAN GPIOD
#define GPIO_Pin_CAN_RX GPIO_Pin_0
#define GPIO_Pin_CAN_TX GPIO_Pin_1
GPIO_InitTypeDef GPIO_InitStructure;
/* Configure CAN pin: RX */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_CAN_RX;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIO_CAN, &GPIO_InitStructure);
/* Configure CAN pin: TX */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_CAN_TX;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIO_CAN, &GPIO_InitStructure);
GPIO_PinRemapConfig(GPIO_Remap_CAN , ENABLE);
}
void CAN_Config(void)
{
CAN_InitTypeDef CAN_InitStructure;
CAN_FilterInitTypeDef CAN_FilterInitStructure;
/* CAN register init */
CAN_DeInit();
CAN_StructInit(&CAN_InitStructure);
/* CAN cell init */
CAN_InitStructure.CAN_TTCM = DISABLE;
CAN_InitStructure.CAN_ABOM = DISABLE;
CAN_InitStructure.CAN_AWUM = DISABLE;
CAN_InitStructure.CAN_NART = DISABLE;
CAN_InitStructure.CAN_RFLM = DISABLE;
CAN_InitStructure.CAN_TXFP = DISABLE;
CAN_InitStructure.CAN_Mode = CAN_Mode_Normal;
CAN_InitStructure.CAN_SJW = CAN_SJW_1tq;
CAN_InitStructure.CAN_BS1 = CAN_BS1_3tq;
CAN_InitStructure.CAN_BS2 = CAN_BS2_5tq;
CAN_InitStructure.CAN_Prescaler = 16;//should result in ~250 kB
if(CAN_Init(&CAN_InitStructure) != CANINITOK)
{
diag_printf("CAN_Config() failed!\r\n");
}
else
{
diag_printf("CAN_Config() succeeded.\r\n");
}
/* CAN filter init */
CAN_FilterInitStructure.CAN_FilterNumber=0;
CAN_FilterInitStructure.CAN_FilterMode=CAN_FilterMode_IdMask;
CAN_FilterInitStructure.CAN_FilterScale=CAN_FilterScale_32bit;
CAN_FilterInitStructure.CAN_FilterIdHigh=0x0000;
CAN_FilterInitStructure.CAN_FilterIdLow=0x0000;
CAN_FilterInitStructure.CAN_FilterMaskIdHigh=0x0000;
CAN_FilterInitStructure.CAN_FilterMaskIdLow=0x0000;
CAN_FilterInitStructure.CAN_FilterFIFOAssignment=0;
CAN_FilterInitStructure.CAN_FilterActivation=ENABLE;
CAN_FilterInit(&CAN_FilterInitStructure);
}
void CCanPort::Init (void)
{
static int i = 0;
RCC_Configuration();
GPIO_Configuration();
CAN_Config();
...
CAN_Receive(CAN_FIFO0, &RxMessage);
CAN_Transmit(&TxMessage) ;
}
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [ECOS] CAN on STM32 - No transmitting
[not found] <OFB1744DA1.0504A02B-ON862576A1.00641E65-862576A1.00642C98@continental-corporation.com>
@ 2010-01-04 18:30 ` Bernhard Gebert
0 siblings, 0 replies; 2+ messages in thread
From: Bernhard Gebert @ 2010-01-04 18:30 UTC (permalink / raw)
To: roman.rycerz, ecos-discuss
As I wrote, the same hardware is running without eCos.
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-01-04 18:30 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-01-04 17:24 [ECOS] CAN on STM32 - No transmitting Bernhard Gebert
[not found] <OFB1744DA1.0504A02B-ON862576A1.00641E65-862576A1.00642C98@continental-corporation.com>
2010-01-04 18:30 ` Bernhard Gebert
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).