Page 1 of 1

No CAN frame received for increasing bit rates

Posted: Wed Jan 14, 2015 1:06 pm
by emvee
Hi,

I am using the STM32F429 Discovery's CAN interfaces to send and receive CAN frames. Particularly, CAN1 (transmitter) and CAN2 (received) are connected via two corresponding transcievers (MCP2551) and an appropriate bus. The communication is ok for very low datarates (roughly about 4 kbs), which is confirmed by the blinking led linked to the receiver thread, but as soon as I increase the datarate (5kbs are enough!) no frames are received anymore. By debugging and inspecting the registers I can notice that the micro's Mailbox data register (CAN2_RDL0R | CAN2_RDH0R) actually hold down the sent frame and the Receive error counter in the Error status register (CAN2_ESR) is increased. This last thing does not happen when the communication is ok. I guess there is some low level control which prevents the frame to be pulled up in the protocol stack and stored in the variable designated "rxmsg" (you can find the corresponding code below), but I can't figure out where, I mean, at least in the code this is not clear to me: I checked the receiver thread but the code evaluation does not keep going on after the "continue" statement even if the condition in the corresponding "if" statement is TRUE (that is (chEvtWaitAnyTimeout(ALL_EVENTS, MS2ST(100)) == 0) = TRUE).

What am I doing wrong? Thank you very much.

The receiver thread is basicly that you can find in the tutorial:

Code: Select all

static msg_t can_rx(void *p) {
  struct can_instance *cip = p;
  CANRxFrame rxmsg;
  EventListener el;

  (void)p;
  chRegSetThreadName("receiver");
  chEvtRegister(&cip->canp->rxfull_event, &el, 0);
  while(!chThdShouldTerminate()) {
    if (chEvtWaitAnyTimeout(ALL_EVENTS, MS2ST(100)) == 0)
      continue;

      while (canReceive(cip->canp, CAN_ANY_MAILBOX,
                            &rxmsg, TIME_IMMEDIATE) == 0) {

            /* Process message.*/
            palTogglePad(GPIOG, cip->led);
            }
  }
  chEvtUnregister(&cip->canp->rxfull_event, &el);
  return 0;
}


I use ChibiOs 2.6.6.

Re: No CAN frame received for increasing bit rates

Posted: Wed Jan 14, 2015 1:32 pm
by Giovanni
Hi,

It is like interrupts are not being served so the thread goes in timeout. The provided demos work also at high datarate so there must be something in your project or hardware.

Do you have debug options enabled in chconf.h? assertions and state checker could reveal some errors.

Giovanni

Re: No CAN frame received for increasing bit rates

Posted: Wed Jan 14, 2015 2:17 pm
by emvee
Hi,

thank you for the response. The only debug option in chconf.h set to TRUE is CH_DBG_THREADS_PROFILING. Actually I am a newbie in microcontrollers and embedded programming so, sorry in advance for the stupid questions I will probably ask you :). However, being your code very clear it is also very clear to me that there is nothing but hidden and out-of-my-current-skills things that prevent it to work with "high" datarates.

Regards,
emVee

Re: No CAN frame received for increasing bit rates

Posted: Wed Jan 14, 2015 7:30 pm
by Giovanni
I don't see obvious problems in the code you posted, unfortunately lot of non-obvious things can cause the problem, something quite common doing embedded systems...

Are you able to run the unmodified CAN demo? I would focus on the changes done to the example code, it would be a good idea to reintroduce the changes one by one.

Giovanni

Re: No CAN frame received for increasing bit rates

Posted: Thu Jan 15, 2015 11:36 am
by emvee
Hi,

I tried to run the original code and it worked. So I managed to figure out that the problem was a mix of bad settings scattered around.

Thank you very much and regards,
emVee

Re: No CAN frame received for increasing bit rates

Posted: Thu Jan 22, 2015 3:22 pm
by emvee
Hi again.

I noticed an odd behavior after my last reply and I wanted to let you know.
Facing the fact that a 500kb/s CAN communication could be setup even though with some rx errors but with a 50 kb/s communication NO frames were received at all (very very counterintuitive) I struggled a bit finally concluding that it was a configuration issue. So, just to give a try, I remapped the can2 TX and RX pins from gpiob 13 and 12 to gpiob 6 and 5 (no other change) and now it works like a charm (no receiving errors).

I checked the board.chfg to make sure nothing was preventing gpiob 12 and 13 to work properly but everything looked ok. I also doublechecked with stm32cubeMX, by reproducing the gpio mapping given by board.chfg but gpiob 12 and 13 were enabled to be mapped for can2 with no confilcts and other issues.

From the stm32f4 reference manual/datasheet nothing let me think about some limitations in using gpiob 13 and 12 for can2. I am using ChibiStudio_Preview7 (I noticed you put a new version on the internet) and the corresponding version of ChibiOs.

I cannot figure out what could it be while it is useful to me to understand. By now it looks like a software issue. Do you think it is something related with my code?

Thank you and regards,
emVee

Re: No CAN frame received for increasing bit rates

Posted: Thu Jan 22, 2015 3:31 pm
by Giovanni
Hi,

I would first check in the ST erratas, it is possible you are hitting something.

Giovanni

Re: No CAN frame received for increasing bit rates

Posted: Thu Jan 22, 2015 4:04 pm
by emvee
I checked the erratas http://www.st.com/web/en/resource/technical/document/errata_sheet/DM00068628.pdf and there is some issue with pa12 (which I map to can1 actually, that is to the transmitter while my problem is at receiver side). It says that the data stored in the flash could be corrupted when pa12 is in alternate but this does not affect pbxx behavior, nor the can controllers however (the flash memory does not take part in the implementation of the can stack, right?). So, at least for my understanging and knowledge of the stm32f429 discovery there's nothing hardware producing the odd behavior I noticed.

emVee

Re: No CAN frame received for increasing bit rates

Posted: Thu Jan 22, 2015 11:40 pm
by alex31
Beware that on discovery boards, and particularly on 429 one, most of the pins are already affected
to components on the board.

gpiob 13 and 12 are connected to on board usb, and this connection should probably electrically perturb the signal.

You can use stm tool stmcubemx (freely downloadable) to see what is actually connected, recent versions have configuration for
discovery board. Select board selector, then choose you board. You will see that on 429, the are very few off
the 144 pins available for external connection.

for linux users, stmcubemx works nice with wine.

you can find at olimex a bunch of cards like h405, h407, e407 where most of the pins are free.

Alexandre

Re: No CAN frame received for increasing bit rates

Posted: Fri Jan 30, 2015 11:30 am
by emvee
gpiob 13 and 12 are connected to on board usb, and this connection should probably electrically perturb the signal.


Yep, you're right!

You can use stm tool stmcubemx (freely downloadable) to see what is actually connected, recent versions have configuration for
discovery board. Select board selector, then choose you board. You will see that on 429, the are very few off
the 144 pins available for external connection.


Probably the version I have is old that's why I didn't notice anything while trying to replicate the pin mapping.

Regards,
emVee