CAN Driver for STM8
Moderators: RoccoMarco, lbednarz, tfAteba
CAN Driver for STM8
Hello again.
from my previous question about integrate Chibi Os with existing firmware, I now try to customize to work with hal from Chibi OS but I could not found CAN driver for STM8.
Dose CAN driver for STM 8 existing?
Thank
Saran
from my previous question about integrate Chibi Os with existing firmware, I now try to customize to work with hal from Chibi OS but I could not found CAN driver for STM8.
Dose CAN driver for STM 8 existing?
Thank
Saran
Re: CAN Driver for STM8
one more question I create simple thread for toggle port like this
while (TRUE) {
palClearPad(GPIOB, 0);
chThdSleepMilliseconds(5);
palSetPad(GPIOB, 0);
chThdSleepMilliseconds(5);
}
I expect port will toggle every 5 milli second. but I saw in scope that port toggle every 4 millisecond
I use internal clock (HSI) 16 MHz
I made OBD application which time is quite critical, how can I calibrate this?
Thank you.
while (TRUE) {
palClearPad(GPIOB, 0);
chThdSleepMilliseconds(5);
palSetPad(GPIOB, 0);
chThdSleepMilliseconds(5);
}
I expect port will toggle every 5 milli second. but I saw in scope that port toggle every 4 millisecond
I use internal clock (HSI) 16 MHz
I made OBD application which time is quite critical, how can I calibrate this?
Thank you.
- Giovanni
- Site Admin
- Posts: 14895
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: CAN Driver for STM8
Thanks for reporting this.
This is most likely a bug in the timer initialization routine in the STM8 board.c files not a problem in the kernel itself. I will make some tests and fix it in the next release.
You may edit the initialization in board.c or use 6 as interval as temporary workaround.
Giovanni
This is most likely a bug in the timer initialization routine in the STM8 board.c files not a problem in the kernel itself. I will make some tests and fix it in the next release.
You may edit the initialization in board.c or use 6 as interval as temporary workaround.
Giovanni
- Giovanni
- Site Admin
- Posts: 14895
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: CAN Driver for STM8
About the CAN driver, I will add one after the 2.2.0 release, it should be similar to the STM32 driver.
My plan is to implement all the drivers for the STM8 platform, right now only HAL, PAL, Serial and SPI are implemented.
Giovanni
My plan is to implement all the drivers for the STM8 platform, right now only HAL, PAL, Serial and SPI are implemented.
Giovanni
Re: CAN Driver for STM8
Sorry for disturbing again.
I could not found interval or something look similar to interval in board.c could you please give me more detail?
Thank you.
saran
I could not found interval or something look similar to interval in board.c could you please give me more detail?
Thank you.
saran
- Giovanni
- Site Admin
- Posts: 14895
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: CAN Driver for STM8
Search this line:
Change it this way:
Then verify if this fixes the problem.
BTW, did you set CH_FREQUENCY to 1000? if I remember well it is 100 in the demos.
Giovanni
Code: Select all
#define TIM2_ARR ((TIM2_CLOCK / CH_FREQUENCY) - 1)
Change it this way:
Code: Select all
#define TIM2_ARR (TIM2_CLOCK / CH_FREQUENCY)
Then verify if this fixes the problem.
BTW, did you set CH_FREQUENCY to 1000? if I remember well it is 100 in the demos.
Giovanni
Re: CAN Driver for STM8
thanks Giovanni,
after change TIM2_ARR and ch Frequency to 1000, got correct timing, Thanks
Regarding CAN Driver, I will try to use ST Can lib for the moment. I don't have enough knowledge to make change on your OS
Saran
after change TIM2_ARR and ch Frequency to 1000, got correct timing, Thanks
Regarding CAN Driver, I will try to use ST Can lib for the moment. I don't have enough knowledge to make change on your OS
Saran
- Giovanni
- Site Admin
- Posts: 14895
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: CAN Driver for STM8
I am not entirely convinced about this issue Saran.
Could you please try to revert the change to TIM2_ARR and just keep the change to CH_FREQUENCY? there is something that just does not sound right with this TIM2_ARR thing.
Anyway I will make some specific tests in the weekend about this and then I will post here again, please keep an eye on this thread.
About the CAN driver, it will be one of the first things after the 2.2.0 release but if you need something soon then it is a good idea to use the ST lib, it should not hard to implement, I made a CAN driver using the ST lib on the STM32 too and it worked without problems under ChibiOS/RT.
Giovanni
Could you please try to revert the change to TIM2_ARR and just keep the change to CH_FREQUENCY? there is something that just does not sound right with this TIM2_ARR thing.
Anyway I will make some specific tests in the weekend about this and then I will post here again, please keep an eye on this thread.
About the CAN driver, it will be one of the first things after the 2.2.0 release but if you need something soon then it is a good idea to use the ST lib, it should not hard to implement, I made a CAN driver using the ST lib on the STM32 too and it worked without problems under ChibiOS/RT.
Giovanni
- Giovanni
- Site Admin
- Posts: 14895
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: CAN Driver for STM8
Hi Saran,
I performed some tests, the problem was that CH_FREQUENCY was set to 100 instead of 1000. The TIM2_ARR calculation is correct in the released code.
Just a note, you stated that you need very precise 5mS pulses.
There are two problems with the code you posted:
You can fix the problem with the first pulse by rewriting the loop as follow:
By putting the chThdSleepMilliseconds() call at the beginning you synchronize the thread with the tick timer, all generated pulses will be exactly 5mS wide.
Note that you may also use a virtual timer for pulses generation and save the RAM required by a thread.
Good luck with your project.
Giovanni
I performed some tests, the problem was that CH_FREQUENCY was set to 100 instead of 1000. The TIM2_ARR calculation is correct in the released code.
Just a note, you stated that you need very precise 5mS pulses.
There are two problems with the code you posted:
- The code is correct but the first pulse generated can be anywhere between 4 and 5mS large, following pulses are all exactly 5mS large. The cause of this is that you are not necessarily synchronized with a tick when you enter the loop.
- If you have higher priority threads then the pulse can have jitter, I recommend to give the highest priority to that thread.
You can fix the problem with the first pulse by rewriting the loop as follow:
Code: Select all
while (TRUE) {
chThdSleepMilliseconds(5);
palClearPad(GPIOB, 0);
chThdSleepMilliseconds(5);
palSetPad(GPIOB, 0);
}
By putting the chThdSleepMilliseconds() call at the beginning you synchronize the thread with the tick timer, all generated pulses will be exactly 5mS wide.
Note that you may also use a virtual timer for pulses generation and save the RAM required by a thread.
Good luck with your project.
Giovanni
Re: CAN Driver for STM8
Saran,
I just wanted to let you know that 8 months ago I was working on porting a CAN driver for an STM8 project, but unfortunately I was pulled from that project and haven't been able to finish it. If you want to take a look, it is in ChibiOS's SVN under branches/stm8_hal, or browse online here: http://chibios.svn.sourceforge.net/view ... orms/STM8/
The code appeared to be working at the time, but it has not been compiled for nor tested on any recent versions of ChibiOS.
- Brian
I just wanted to let you know that 8 months ago I was working on porting a CAN driver for an STM8 project, but unfortunately I was pulled from that project and haven't been able to finish it. If you want to take a look, it is in ChibiOS's SVN under branches/stm8_hal, or browse online here: http://chibios.svn.sourceforge.net/view ... orms/STM8/
The code appeared to be working at the time, but it has not been compiled for nor tested on any recent versions of ChibiOS.
- Brian