-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modify Stm32Can to support multiple CAN interfaces on ST Micro MCUs that have multiple CAN IFs #816
base: master
Are you sure you want to change the base?
Modify Stm32Can to support multiple CAN interfaces on ST Micro MCUs that have multiple CAN IFs #816
Conversation
Opps! Fixed.
At Fri, 31 Jan 2025 13:56:38 -0800 bakerstu/openmrn ***@***.***> wrote:
…
@atanisoft commented on this pull request.
> @@ -542,6 +634,41 @@ void can1_sce_interrupt_handler(void)
Stm32Can::instances[0]->sce_interrupt_handler();
}
+<<<<<<< HEAD
looks like a merge artifact snuck in.
--
Robert Heller -- Cell: 413-658-7953 GV: 978-633-5364
Deepwoods Software -- Custom Software Services
http://www.deepsoft.com/ -- Linux Administration Services
***@***.*** -- Webhosting Services
|
instances[index] = this; | ||
switch (index) | ||
{ | ||
case 0: /* CAN1... */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The style guidelines require case labels to be indented four spaces.
/** Default constructor. | ||
*/ | ||
Stm32Can(); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the extra empty line. Only one empty line required for spacing.
@@ -103,13 +132,58 @@ Stm32Can::Stm32Can(const char *name) | |||
: Can(name) | |||
, state_(CAN_STATE_STOPPED) | |||
{ | |||
/* only one instance allowed */ | |||
HASSERT(instances[0] == NULL); | |||
/* Get dev num (digit at the end of the devname). */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like that we have programmatically tied the device "name" to the hardware instance. As far as I recall, we don't have any such tie anywhere else in the device file system. I think it makes since to instead pass the hardware references in (base address and interrupt number), similar to what we do in the Tiva driver:
TivaCan::TivaCan(const char *name, unsigned long base, uint32_t interrupt) |
I strongly encourage that with the addition of these parameters, either we have an overloaded constructor that is backwards compatible fixed to the first CAN instance, or we use "default" values for the parameters to point to the first CAN instance. That way we don't break other existing uses.
@@ -45,6 +45,12 @@ | |||
|
|||
#include "stm32f_hal_conf.hxx" | |||
|
|||
// Max possible number of CAN ifs across the whole STM32 -- the constructor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please turn this into a Doxygen style comment with three slashes.
@@ -91,11 +97,17 @@ private: | |||
static unsigned int intCount; | |||
|
|||
uint8_t state_; ///< present bus state | |||
|
|||
|
|||
CAN_TypeDef *can_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add Doxygen comments for these members.
// will calculate the actual max for the specific chip compiling for | ||
#define MAXCANIFS 3 | ||
|
||
//struct CAN_TypeDef; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this dead code?
@@ -36,6 +36,7 @@ | |||
#include "Stm32Can.hxx" | |||
|
|||
#include <stdint.h> | |||
#include <string.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This include might be able to be removed if the programatic select of device instance by name is also removed.
At Sun, 02 Feb 2025 16:16:26 -0800 bakerstu/openmrn ***@***.***> wrote:
@bakerstu commented on this pull request.
>
- instances[0] = this;
+ instances[index] = this;
+ switch (index)
+ {
+ case 0: /* CAN1... */
The style guidelines require case labels to be indented four spaces.
OK, easy fix. (My editor has a different auto-indent process for switch
labels...)
> /** Default constructor.
*/
Stm32Can();
-
+
Remove the extra empty line. Only one empty line required for spacing.
OK.
> @@ -103,13 +132,58 @@ Stm32Can::Stm32Can(const char *name)
: Can(name)
, state_(CAN_STATE_STOPPED)
{
- /* only one instance allowed */
- HASSERT(instances[0] == NULL);
+ /* Get dev num (digit at the end of the devname). */
I don't like that we have programmatically tied the device "name" to the hardware instance. As far as I recall, we don't have any such tie anywhere else in the device file system. I think it makes since to instead pass the hardware references in (base address and interrupt number), similar to what we do in the Tiva driver: https://github.com/bakerstu/openmrn/blob/e35c58d4aba4b9d5a4dc355684a2eb1c87008f01/src/freertos_drivers/ti/TivaCan.cxx#L58
I just picked the "Linux" way of naming devices -- on the Linux SBCs that I
have with multiple CAN IFs (Beagle boards), the devices are named can0, can1,
etc. I can fix this in the consstructor, but I'll keep the path names the
same, since they are used elsewhere.
I strongly encourage that with the addition of these parameters, either we have an overloaded constructor that is backwards compatible fixed to the first CAN instance, or we use "default" values for the parameters to point to the first CAN instance. That way we don't break other existing uses.
OK, I can do this.
> @@ -45,6 +45,12 @@
#include "stm32f_hal_conf.hxx"
+// Max possible number of CAN ifs across the whole STM32 -- the constructor
Easy fix/
Please turn this into a Doxygen style comment with three slashes.
> @@ -91,11 +97,17 @@ private:
static unsigned int intCount;
uint8_t state_; ///< present bus state
-
+
+ CAN_TypeDef *can_;
Please add Doxygen comments for these members.
OK.
> @@ -45,6 +45,12 @@
#include "stm32f_hal_conf.hxx"
+// Max possible number of CAN ifs across the whole STM32 -- the constructor
+// will calculate the actual max for the specific chip compiling for
+#define MAXCANIFS 3
+
+//struct CAN_TypeDef;
Is this dead code?
I think so, The original had a single instance of the CAN_TypeDef struct
outside of the class, but the new version has it as a instance variable.
> @@ -36,6 +36,7 @@
#include "Stm32Can.hxx"
#include <stdint.h>
+#include <string.h>
This include might be able to be removed if the programatic select of device instance by name is also removed.
OK, I'll check that.
…--
Robert Heller -- Cell: 413-658-7953 GV: 978-633-5364
Deepwoods Software -- Custom Software Services
http://www.deepsoft.com/ -- Linux Administration Services
***@***.*** -- Webhosting Services
|
This is a modification to the Stm32Can that allows for multiple CAN IFs running on those ST Micro MCUs that have multiple CAN IFs. When the class is instanciated, the trailing digit in the path name determines which CAN IF this instance is for. If the path ends in '0', CAN1 (or the only) interface is used, if it ends in '1', CAN2 is used (if it exists), and if the path ends in '2', CAN3 is used.
Typical usage:
In HwInit.cxx:
Later:
and:
Then in main.cxx:
I have tested this:
https://github.com/RobertPHeller/RPi-RRCircuits/tree/master/STM32F767ZI_LCC_PNET_Router