ok, so I made a fork and committed the files I had. I am not sure how to “switch” the existing checkout to my fork so I tried to ensure I got all my changes copied over to the forked copy. I am a subversion user… this git stuff is just wierd…lol
Anyways my code is here:
Can someone familiar with particle driver development take a look and tell me if I am headed in the correct direction.
haha! I used to also be an avid subversion user. But once you eventually internalize how git works, you’ll wonder why all CVSs weren’t built like that! I wouldn’t go back to SVN or any other non-distributed CVS now.
@Bspranger I’d love to help you out but I’m not familiar with it yet either. I’ve got some big plans for this so I’ll let you know when my photon arrives and I get started with it. I think you are probably more familiar with CAN then I am anyway but I’m keen to get this up and running in the near future so hopefully we can collaborate and I can help you where possible to finish off the libraries.
So which file should I be adding the actual CAN interrupts into. I know that they need to be defined as weak so that the driver can replace the definitions with the real interrupt routines. However, things don’t seem to line up with the reference manual.
@Bspranger I’ve looked over your approach and at a high level it looks great! (I don’t have a lot of time to completely scrutinize it though and the devil is in the details). If it’s compiling as is, you’re doing good. If you need any special GPIO configuration an edit to the gpio_hal.c’s HAL_Pin_Mode() may be necessary. For the interrupts… the interrupt vector table for the Photon has been named by the WICED SDK, as it has configured the startup file in C. The names are slightly different than the default STM32 startup file done in assembly. Here’s a listing of the function names:
So I was building via netbeans and I am not sure it was actually compiling everything. So I started to compile via command prompts and I am getting an error.
src/photon/hal_dynalib_export.c
In file included from ./inc/hal_dynalib_concurrent.h:25:0,
from src/photon/hal_dynalib_export.c:35: ./inc/concurrent_hal.h:189:23: fatal error: bits/gthr.h: No such file or directory #include <bits/gthr.h>
I have modified hal_dynalib_export.c to add #include “can_hal.h”, but I don’t think this is causing the issue.
So… I might have the driver mostly implemented however I haven’t tried it on hardware yet, so there could be a bunch of testing yet.
I have a really dumb question and need help. Now that I have the kernel (my fork) compiling with the CAN driver, how do I actually build an application so that it uses my “new” kernel?
I have been building my applications via particle cli.
I’d love to help, but I’m not sure how to answer that. Maybe you could post your code to a github repo so we can take a look and advise on how to build an app around it?
@Bspranger I think what you are asking is how to compile locally with a test application that uses your “CAN” fork of the firmware repo…
Here’s the way to ensure a clean build for the Photon, with modular firmware (Photon in DFU mode):
~code/firmware/modules $ make clean all -s PLATFORM=photon COMPILE_LTO=n APP=tinker program-dfu PARTICLE_DEVELOP=1
You can replace APP=tinker with a folder of your choice sitting along side of
firmware/user/applications/tinker/
For example, add your files here:
firmware/user/applications/can/
firmware/user/applications/can/myCanApp.cpp (main application with setup() and loop() )
firmware/user/applications/can/myLibrary.cpp (optional)
firmware/user/applications/can/myLibrary.h (optional)
Make sure to include these things in your myCanApp.cpp (these are normally taken care of by the preprocessor in the Build IDE):
#include "application.h"
// include all prototypes for new functions
Build with:
~code/firmware/modules $ make clean all -s PLATFORM=photon COMPILE_LTO=n APP=can program-dfu PARTICLE_DEVELOP=1
To iterate more quickly you can build the system and user application as a monolithic firmware image that gets programmed in one shot. This speeds up compile and flashing times by a factor of 2. You will not be able to iterate on just the user application after programming as monolithic though.
Here’s the way to ensure a clean build for the Photon, with monolithic firmware (Photon in DFU mode):
~code/firmware/main $ make clean all -s PLATFORM=photon COMPILE_LTO=n APP=tinker program-dfu MODULAR=n PARTICLE_DEVELOP=1
It ends up being the same as that CLI command, but the low level event is that both methods invoke dfu-util with the correct memory addresses needed to place the system and user modules in the correct place in flash.
After you get the modular system firmware running on your Photon, you can iterated just the user application in modular form with this command:
~code/firmware/main $ make clean all -s PLATFORM=photon COMPILE_LTO=n APP=tinker program-dfu PARTICLE_DEVELOP=1
But I tend to avoid it because if I forget that I'm tweaking something in system firmware, the change won't be pulled in by just recompiling and flashing the user application. So either wait for a clean build of all modules from the modules directory, or build as monolithic from the main directory (as mentioned in the previous post)
../build/target/hal/platform-6n/\libhal.a(hal_dynalib_export.o):(.rodata.dynalib_hal_concurrent+0x0): multiple definition of `dynalib_hal_concurrent'
../build/target/hal/platform-6n/\libhal.a(hal_dynalib_export.o):(.rodata.dynalib_hal_concurrent+0x0): first defined here
../build/target/hal/platform-6n/\libhal.a(hal_dynalib_export.o):(.rodata.dynalib_hal_wlan+0x0): multiple definition of `dynalib_hal_wlan'
../build/target/hal/platform-6n/\libhal.a(hal_dynalib_export.o):(.rodata.dynalib_hal_wlan+0x0): first defined here
../build/target/hal/platform-6n/\libhal.a(hal_dynalib_export.o):(.rodata.dynalib_hal_usart+0x0): multiple definition of `dynalib_hal_usart'
../build/target/hal/platform-6n/\libhal.a(hal_dynalib_export.o):(.rodata.dynalib_hal_usart+0x0): first defined here
../build/target/hal/platform-6n/\libhal.a(hal_dynalib_export.o):(.rodata.dynalib_hal_spi+0x0): multiple definition of `dynalib_hal_spi'
../build/target/hal/platform-6n/\libhal.a(hal_dynalib_export.o):(.rodata.dynalib_hal_spi+0x0): first defined here
../build/target/hal/platform-6n/\libhal.a(hal_dynalib_export.o):(.rodata.dynalib_hal_socket+0x0): multiple definition of `dynalib_hal_socket'
../build/target/hal/platform-6n/\libhal.a(hal_dynalib_export.o):(.rodata.dynalib_hal_socket+0x0): first defined here
../build/target/hal/platform-6n/\libhal.a(hal_dynalib_export.o):(.rodata.dynalib_hal_peripherals+0x0): multiple definition of `dynalib_hal_peripherals'
../build/target/hal/platform-6n/\libhal.a(hal_dynalib_export.o):(.rodata.dynalib_hal_peripherals+0x0): first defined here
../build/target/hal/platform-6n/\libhal.a(hal_dynalib_export.o):(.rodata.dynalib_hal_ota+0x0): multiple definition of `dynalib_hal_ota'
../build/target/hal/platform-6n/\libhal.a(hal_dynalib_export.o):(.rodata.dynalib_hal_ota+0x0): first defined here
../build/target/hal/platform-6n/\libhal.a(hal_dynalib_export.o):(.rodata.dynalib_hal_i2c+0x0): multiple definition of `dynalib_hal_i2c'
../build/target/hal/platform-6n/\libhal.a(hal_dynalib_export.o):(.rodata.dynalib_hal_i2c+0x0): first defined here
../build/target/hal/platform-6n/\libhal.a(hal_dynalib_export.o):(.rodata.dynalib_hal_gpio+0x0): multiple definition of `dynalib_hal_gpio'
../build/target/hal/platform-6n/\libhal.a(hal_dynalib_export.o):(.rodata.dynalib_hal_gpio+0x0): first defined here
../build/target/hal/platform-6n/\libhal.a(hal_dynalib_export.o):(.rodata.dynalib_hal_core+0x0): multiple definition of `dynalib_hal_core'
../build/target/hal/platform-6n/\libhal.a(hal_dynalib_export.o):(.rodata.dynalib_hal_core+0x0): first defined here
../build/target/hal/platform-6n/\libhal.a(hal_dynalib_export.o):(.rodata.dynalib_hal+0x0): multiple definition of `dynalib_hal'
../build/target/hal/platform-6n/\libhal.a(hal_dynalib_export.o):(.rodata.dynalib_hal+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
make: *** [../build/target/main/platform-6/can.elf] Error 1
I removed the file:
firmware\hal\src\photon\hal_dynalib_export.c
and then it built. So I am not sure if this was the correct thing to do but I get an executable…
I still haven’t had a chance to get this on hardware but I have now been able to compile an application with the kernel modifications. So one step closer, until I actually try it on the hardware… lol
Interesting… you must have started working on this before modular for electron was implemented. The file firmware\hal\src\photon\hal_dynalib_export.c was moved to firmware\hal\src\stm32f2xx\hal_dynalib_export.c and later renamed to .cpp
I’m not sure why you would still have both files present, but something is not updating in your fork correctly. I would try to rebase your commits against the latest develop branch, but it might be easier to just manually edit a fresh clone of develop to ensure all of your code is there.
I had another hour on hardware today but I didn’t make anymore progress. Still not receiving messages (I suspect the pin configuration for the rx, but it looks correct).
TX messages look wrong. I double checked myour code and didn’t see anything.
Need a bigger block of consecutive time and also need to get JTAG running so I can verify the registers.
I have used eclipse with the stm32f2xx along time ago (openocd ), what is everyone using here?