-
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
Open
RobertPHeller
wants to merge
11
commits into
bakerstu:master
Choose a base branch
from
RobertPHeller:heller-stm32-multiple-can
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Modify Stm32Can to support multiple CAN interfaces on ST Micro MCUs that have multiple CAN IFs #816
RobertPHeller
wants to merge
11
commits into
bakerstu:master
from
RobertPHeller:heller-stm32-multiple-can
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
atanisoft
reviewed
Jan 31, 2025
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
|
bakerstu
reviewed
Feb 3, 2025
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
|
…o select the IF, instead of using the pathname.
OK, I made all of the mods Stuart asked for and I just tested on a STM32F7 board and it all works. |
…o select the IF, instead of using the pathname.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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