I was able to get the loopback mode working with this thread in the STM32 forums, but I'd rather be using ChibiOS
CAN2 on STM32F4-Discovery
Moderator: RoccoMarco
Re: CAN2 on STM32F4-Discovery
I believe the clock is a slave.
I was able to get the loopback mode working with this thread in the STM32 forums, but I'd rather be using ChibiOS
I was able to get the loopback mode working with this thread in the STM32 forums, but I'd rather be using ChibiOS
- Attachments
-
- can2.patch.zip
- Unified diff
- (6.81 KiB) Downloaded 626 times
- Giovanni
- Site Admin
- Posts: 14892
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 996 times
Re: CAN2 on STM32F4-Discovery
I am looking into this. I decided to remove filters from the configuration and implement a custom API for that (probably taking it from the FW library).
Giovanni
Giovanni
- Giovanni
- Site Admin
- Posts: 14892
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 996 times
Re: CAN2 on STM32F4-Discovery
Hi,
Good news, it works
The STM32F4xx demo now activates both CANs. Could you make some testing on the driver? especially the new API that allows to setup the filters. Note that the filters setup must happen before calling canStart(). Now the configuration structure is simplified, filters are no more handled there.
Giovanni
Good news, it works
The STM32F4xx demo now activates both CANs. Could you make some testing on the driver? especially the new API that allows to setup the filters. Note that the filters setup must happen before calling canStart(). Now the configuration structure is simplified, filters are no more handled there.
Giovanni
Re: CAN2 on STM32F4-Discovery
Giovanni, you are dedicated to your passion and it is clear that this is your passion. Thank you for your help!
I will absolutely test the filtering as it will most certainly be required in my anticipated application. I'll report my results as soon as I have a chance.
I will absolutely test the filtering as it will most certainly be required in my anticipated application. I'll report my results as soon as I have a chance.
Re: CAN2 on STM32F4-Discovery
Hi, i search in the forum about CAN filters.
There is some API to configure the filters on the CAN bus? I found start, transmit, receive functions and examples, but I cant find some way to configure the filters like address filter for many MCU conected trough CAN.
Thanks Giovanni for your good work!
There is some API to configure the filters on the CAN bus? I found start, transmit, receive functions and examples, but I cant find some way to configure the filters like address filter for many MCU conected trough CAN.
Thanks Giovanni for your good work!
- Giovanni
- Site Admin
- Posts: 14892
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 996 times
Re: CAN2 on STM32F4-Discovery
Hi,
CAN filters are mapped exactly as described in the reference manual of the STM32, you have to create an array of filters that the driver copies into the registers on initialization.
Giovanni
CAN filters are mapped exactly as described in the reference manual of the STM32, you have to create an array of filters that the driver copies into the registers on initialization.
Giovanni
Re: CAN2 on STM32F4-Discovery
Hi, what function programs the filters, canStart?, I found inside can_lld this API
canSTM32SetFilters(uint32_t can2sb, uint32_t num, const CANFilter *cfp)
but seems that it set a filter in the bank filter but no specifies if the filter is in identifier mask mode or identifier list mode, how can I configure that?
Can post a very short example configuring one filter whit identifier list mode and setting up the first filter in the bank 0?
canSTM32SetFilters(uint32_t can2sb, uint32_t num, const CANFilter *cfp)
but seems that it set a filter in the bank filter but no specifies if the filter is in identifier mask mode or identifier list mode, how can I configure that?
Can post a very short example configuring one filter whit identifier list mode and setting up the first filter in the bank 0?
- Giovanni
- Site Admin
- Posts: 14892
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 996 times
Re: CAN2 on STM32F4-Discovery
The filter modes are defined in the CANFilter structure:
Giovanni
Code: Select all
/**
* @brief CAN filter.
* @note Refer to the STM32 reference manual for info about filters.
*/
typedef struct {
/**
* @brief Number of the filter to be programmed.
*/
uint32_t filter;
/**
* @brief Filter mode.
* @note This bit represent the CAN_FM1R register bit associated to this
* filter (0=mask mode, 1=list mode).
*/
uint32_t mode:1;
/**
* @brief Filter scale.
* @note This bit represent the CAN_FS1R register bit associated to this
* filter (0=16 bits mode, 1=32 bits mode).
*/
uint32_t scale:1;
/**
* @brief Filter mode.
* @note This bit represent the CAN_FFA1R register bit associated to this
* filter, must be set to zero in this version of the driver.
*/
uint32_t assignment:1;
/**
* @brief Filter register 1 (identifier).
*/
uint32_t register1;
/**
* @brief Filter register 2 (mask/identifier depending on mode=0/1).
*/
uint32_t register2;
} CANFilter;
Giovanni
Re: CAN2 on STM32F4-Discovery
Thanks a lot!
I was looking for the structure in http://chibios.sourceforge.net/html/can ... ource.html and I saw there empty, because is specific for STM32F1.
Now I will try to config
I was looking for the structure in http://chibios.sourceforge.net/html/can ... ource.html and I saw there empty, because is specific for STM32F1.
Now I will try to config
Re: CAN2 on STM32F4-Discovery
Hi.
You say that the driver initialize the filters if I have an array, but I only found in the code that:
inside can_lld.c at the function can_lld_init:
it is called by halInit, but the second parameter is 0 and in the code of the function i found:
for this reason the filter never takes my array, i think if i use the API canSTM32SetFilters, I will can program it, but the function is not visible from main.c, is there a problem? or I need to include can_lld.h at main?
You say that the driver initialize the filters if I have an array, but I only found in the code that:
inside can_lld.c at the function can_lld_init:
Code: Select all
/* Filters initialization.*/
#if STM32_HAS_CAN2
can_lld_set_filters(STM32_CAN_MAX_FILTERS / 2, 0, NULL);
#else
can_lld_set_filters(STM32_CAN_MAX_FILTERS, 0, NULL);
#endif
it is called by halInit, but the second parameter is 0 and in the code of the function i found:
Code: Select all
/**
* @brief Programs the filters.
*
* @param[in] can2sb number of the first filter assigned to CAN2
* @param[in] num number of entries in the filters array, if zero then
* a default filter is programmed
* @param[in] cfp pointer to the filters array, can be @p NULL if
* (num == 0)
*
* @notapi
*/
for this reason the filter never takes my array, i think if i use the API canSTM32SetFilters, I will can program it, but the function is not visible from main.c, is there a problem? or I need to include can_lld.h at main?