can reseved problem Topic is solved

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

Moderators: RoccoMarco, barthess

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

can reseved problem

Postby asdasdasd » Wed Mar 31, 2021 1:39 pm

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: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: can reseved problem

Postby Giovanni » Wed Mar 31, 2021 1:42 pm

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: 823
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 12 times
Been thanked: 135 times

Re: can reseved problem

Postby steved » Wed Mar 31, 2021 1:58 pm

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: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: can reseved problem

Postby Giovanni » Wed Mar 31, 2021 1:59 pm

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

Postby asdasdasd » Thu Apr 01, 2021 9:37 am

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: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: can reseved problem  Topic is solved

Postby Giovanni » Thu Apr 01, 2021 10:44 am

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

Postby asdasdasd » Thu Apr 01, 2021 10:51 am

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: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: can reseved problem

Postby Giovanni » Thu Apr 01, 2021 11:10 am

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

Giovanni

rew
Posts: 380
Joined: Sat Jul 19, 2014 12:59 pm
Has thanked: 2 times
Been thanked: 13 times

Re: can reseved problem

Postby rew » Sun Apr 04, 2021 5:55 pm

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.


Return to “STM32 Support”

Who is online

Users browsing this forum: No registered users and 12 guests