can reseved problem Topic is solved

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
asdasdasd
Posts: 7
Joined: Tue Feb 09, 2021 12:20 pm
Has thanked: 6 times

can reseved problem

Post by asdasdasd »

Hi all ,
I am using stm32f103 with chibios v20,
I have modified can example to communicate with can radar, but i have problem in received packet .
when i have received a msg more than three packet the first three packet is OK and others sequence become wrong .?
any suggestion ?

best regards,
asd
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: can reseved problem

Post by Giovanni »

Hard to tell without looking at the actual traffic, most of the work is done by the peripheral in HW, the driver itself is very thin.

Few questions:
- Are you emptying the RX queues when you get a CAN event? you need to read until it is empty.
- Do you get CAN errors?

Giovanni
steved
Posts: 834
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 12 times
Been thanked: 138 times

Re: can reseved problem

Post by steved »

It could be significant that the CAN hardware has three receive buffers.
Maybe you are not emptying the receive buffer fast enough?



(And how is this a "small change request"?)
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: can reseved problem

Post by Giovanni »

steved wrote:(And how is this a "small change request"?)


Right, moving.
asdasdasd
Posts: 7
Joined: Tue Feb 09, 2021 12:20 pm
Has thanked: 6 times

Re: can reseved problem

Post by asdasdasd »

Giovanni wrote:Hard to tell without looking at the actual traffic, most of the work is done by the peripheral in HW, the driver itself is very thin.

Few questions:
- Are you emptying the RX queues when you get a CAN event? you need to read until it is empty.
- Do you get CAN errors?

Giovanni


I am using this received msg

Code: Select all

/*
 * Receiver thread.
 */
static THD_WORKING_AREA(can_rx_wa, 256);
static THD_FUNCTION(can_rx, p) {
  event_listener_t el;
  CANRxFrame rxmsg;

  (void)p;
  chRegSetThreadName("receiver");
  chEvtRegister(&CAND1.rxfull_event, &el, 0);
  while (true) {
    if (chEvtWaitAnyTimeout(ALL_EVENTS, TIME_MS2I(100)) == 0)
      continue;
    while (canReceive(&CAND1, CAN_ANY_MAILBOX, &rxmsg, TIME_IMMEDIATE) == MSG_OK) {
      /* Process message.*/
      chprintf(chp,"EID %x",rxmsg);
      palTogglePad(IOPORT3, GPIOC_LED);
    }
  }
  chEvtUnregister(&CAND1.rxfull_event, &el);
}


The can packet is(500packet)Sequences (16us time between packet)
I think the time of reading is slowly ,
stm32f103 speed is 72MHz
can speed 1000K
but i don't know how to read faster?
and how can i set can callback function?
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: can reseved problem

Post by Giovanni »

Try removing the chprintf(), that is slowing down the loop for sure because it is bound by the serial port speed.

Giovanni
asdasdasd
Posts: 7
Joined: Tue Feb 09, 2021 12:20 pm
Has thanked: 6 times

Re: can reseved problem

Post by asdasdasd »

Giovanni wrote:Try removing the chprintf(), that is slowing down the loop for sure because it is bound by the serial port speed.

Giovanni


thanks for replay :
i will test it,
if I set CAN_ENFORCE_USE_CALLBACKS TRUE, can i have faster speed?
and how can i use callback function?
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: can reseved problem

Post by Giovanni »

You would not gain much and it is more complex to use.

Giovanni
rew
Posts: 383
Joined: Sat Jul 19, 2014 12:59 pm
Has thanked: 2 times
Been thanked: 14 times

Re: can reseved problem

Post by rew »

asdasdasd wrote:i will test it,
if I set CAN_ENFORCE_USE_CALLBACKS TRUE, can i have faster speed?
If what you want is to really print the incoming packets, you have to first do the math: Is that theoretically possible. To me it looks as if you are running out of time to print the packet summary with the first packet.

You are printing 12 characters per message. If you send them at 9600 baud, that's about 1ms per character or 12 ms for the whole packet dump. With packets coming in every 16 us, that is about 1000x too slow..... You might be running at 38400 or 115200, but still that would be about 300 or 100 times too slow.

The USB should be able to handle it, but then your PC might be telling the USB device: "please hold off a moment" and then things go wrong.
Post Reply