-
Notifications
You must be signed in to change notification settings - Fork 86
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
How to add CAN bus protocol to GRBL source code so that it communicate with multiple devices? #179
Comments
It should have an impact in that a top level CAN bus API/HAL should be declared/added to the core making it easy to write plugin code that can work across multiple drivers. |
I want to burn grblHAL on one development board, which can receive/send data to the CAN bus, and the other two boards are responsible for sending/receiving data from the CAN bus. |
I had an initial go at a CAN bus plugin, and the underlying driver support for STM32F4 and H7. I will rebase & publish my CAN driver branches for review, and see what Terje thinks of the approach.. |
How should I use it for CAN bus communication?Is there any instruction manual I can use? |
Not yet I'm afraid. There is a very basic my_plugin example that simply printfs received message id's, and sends a test message on each realtime report. I plan to add some more usage examples to the plugin moving forwards. @terjeio fyi - I've rebased & pushed can driver branches to my F4 & H7 repos.. |
In addition to adding canbus.c, canbus.h, canbus_ids.h files, what other files need to be added? When I compile, an error is reported and the can.h file is required. |
Yes, you'll need the underlying CAN driver support for your platform. My repo with the F4 code is linked in previous comment, however please note it's not been reviewed yet, and may all change before/if it's accepted upstream. |
How long does it take to use it, or when can you review it? |
Could you give me the underlying CAN driver support ? I am using the STM32F4 platform. I am very need it.Thank you for your help!!! |
Although I am a student, I can sponsor you a cup of coffee as a reward and thanks for your help.Can you give me your sponsorship information? |
Sorry, I do not have any... The error about can.h is not found is due to you having the wrong version of the source? It should be in the Inc folder, and can.c in the Src folder. If not there clone this repo (the can branch) instead of the official grblHAL repo. I have started looking into adding can support, likely moving the plugin part of the code into the core. And I think the plugin should be made a bit more flexible, e.g with filtering and callback support thus removing the need for polling. |
Thank you for your help. |
This comment was marked as off-topic.
This comment was marked as off-topic.
Here is my take on how a CAN API can be added to the core, tested with the F7xx driver. It uses weak functions for the low level driver functions and filters associated with client callbacks for simpler(?) code. To get all messages to one callback use a single filter with both id and mask set to 0. BTW here is a link to STM32 code with advanced filtering implemented that might be useful. |
Thanks, am travelling for a couple of days this week, but will check it out. As an aside, I notice you've (correctly) commented out the printf() statements I left scattered about for debugging. Is there (or could there be) a standard debug output macro that I should be using? I see other projects using DBG_LOG() or similar that get #defined to whatever output backend is most appropriate. |
can.zip has a lot error,when I put it into my project. |
Here is a new version - added some missing includes and improved filter registration. I forgot to mention that the GPIO port and pins has to be declared in the board map, an example:
@mr-huang-mou |
Maybe you need to modify the baud rate parameters, because the APB1 clock is 42MHz |
Yes and no. If there is a free serial stream it can be used, enable in config.h., this makes two output functions available. I guess I should wrap a BTW I am unsure why
Which driver/board? I am currently testing with a F412 (SuperLongBoard - 25MHz) and a F756 (Nucleo144 - 54MHz), additional clock setups has to be added for other boards that has different APB1 clock frequencies. This may take some time if I am to do it myself, if you can add (or modify) the needed code yourself that would be nice. |
Yeah I've just been using printf() to output any debug info over SWO when running under a debugger, I guess it would be nice to have a standard macro that could wrap whatever output option is wanted? A disadvantage of my current approach is that there is always the printf() formatting overhead, even if it's not sent anywhere. Was thinking that a macro could be #defined to nothing unless there is actually a chosen output backend?
I don't think that was the case in my original code (unless I made a mistake - quite possible). Was supposed to be that can_get() was either called in interrupt context from the rx fifo callback, or from the polling loop of the canbus plugin?
I haven't had a chance to look at the new code carefully yet, but happy to take your lead. My original intent was just to have some flexibility over when received data was moved from the hw fifo buffer into the drivers ringbuffer, was perhaps unnecessary.
My initial 45MHz for the F4 driver code came from testing on a F446 Nucleo. Will confess I didn't check APB1 frequencies on other supported boards. Happy to work out some more timings for the F4 variants... |
I am currently testing with a F407(42MHz).I modified the prescaler and TimeSeg1 to correct the baud rate.At first I didn't know why my board couldn't communication with my other boards,so I checked the board I was using,but the configuration was still F407,so I looked at the APB1 and found that my other boards were different from your APB1.I just modified a little bit based on your code,and the subsequent complete version was still your support.Thanks for your help!!! |
Another thing is how to receive data. In my test, I can't know whether my board receives the data sent by other boards. I use an oscilloscope to detect that there is data on the receiving pin PA11, but the receiving interrupt function does not process the data. |
Something like this? Cannot remember now if it ever worked.
My bad, you are correct. But since inserting messages in the receive buffer can be safely done from an interrupt context (as long as there is only one source) then I see no reason for continuously polling for them (at a high frequency). My default is to instead post a task to the foreground process when a message is received, which reduces the polling overhead. But IMO better just to insert the message directly into the buffer and leave the interrupt on.
Have you tried with setting the filter mask to 0? |
Yes, that works here for getting the LwIP output over SWO, or even simpler approach;
Though I appreciate can all get a bit more complicated ;)
Yep, agreed.
I've done some basic testing on an F4 Nucleo board now, and is working here (once timings defined correctly). I'll get the H7 driver (FDCAN peripheral) ported across to the same structure, and then update the control panel plugin to use the new format. |
I have already committed the canbus code, to follow in the next commit is printf style debug output, either to the |
Hi @terjeio Just updating the H7 support & noticed a couple of things in the core code? In
And in
|
Oops - getting sloppy with my coding... Fix comitted.
Correct, filters/callbacks will be lost - have to find a way to just change the baud rate. For now I just output a message. |
For info, have pushed the updated CAN support for the H7 driver. Will confess I was struggling to follow the fmi/bank filter logic for the bxCAN peripheral, seems easier for FDCAN (unless I'm missing something, but appears to work as expected). Thanks for adding the debug output, am now wondering how it can be used for something other than serial streams (i.e. SWO or Segger RTT backends), will open a separate conversation to save getting too off topic here. |
|
Without access to the rest of your code it is impossible to tell.
The baud rate is set with $399 using an id for the different rates:
To set it to 500000 you have to use |
Will joining the CAN bus protocol have any impact on the GRBL source code?
The text was updated successfully, but these errors were encountered: