You are viewing a static version of the site. Enable JavaScript to benefit from the
full functionality of this site and enable such things as forum posting.
MAX32 board: Migrating complex MPLABX project to UECIDE
Janez:
I have a open source project for CANopen communication, which is working with PIC32 and Microchip tools:
https://github.com/CANopenNode/CANopenPIC
I recently found UECIDE and I'm wondering, if it could be possible to use this tool for my project. I would like to compile it with Uecide and load it to MAX32 board via USB. It is a pure c project and doesn't require external libraries. I need some hints.
matt:
It can be possible, yes, but slightly tricky. The problem being that UECIDE is currently geared towards the Arduino paradigm: having a core with lots of "standard" code, and a program + libraries that uses that code.
Most of the time you can just use the standard chipKIT core and compiler as all the normal header files from XC32 are available and already included for you - you just don't have a main()
function, instead use setup()
, and the core timer has an interrupt attached that deals with millis()
and delay()
and such like - you might like to disable that interrupt. That's another point, too - the chipKIT's interrupt system is different to the XC32 one - you create ISRs with the __USER_ISR
macro and then use a set of special functions to hook them in.
Depending on the complexity of your code that may be all that's needed.
matt:
I did at one point create the "Raw PIC32" core for chipkit-less compiling. It's in the repo, but whether it actually works or does anything these days (we have had changes in the compiler since then I think) I don't know.
Janez:
Actually the core code, CANopenNode is microcontroller independent. CANopenPIC is contains only a "driver" for PIC32 and MPLABX with CAN interface to CANopenNode..
CANopenNode inside PIC32 runs inside two "threads": slower code runs inside main loop, realtime code runs inside 1ms timer interrupt. But it could be possible to both run inside one "thread". Besides that interrupt is used for CAN reception and transmission.
Actually I would prefer to use Arduino paradigm with CANopenNode and Uecide, but I don't have deeper experience with Arduino. MAX32 cold be a good starting point of using CANopenNode inside Arduino ecosystem. Actually CANopen standard could be quite useful for connecting multiple boards into reliable and configurable network.
As I said, I don't have deeper knowledge with Arduino ecosystem and for my personal usage MPLABX is OK. But if someone from Arduino or Uecide world is ready to cooperate, I would like to prepare example for it.
matt:
I've just been having a flick through the CANOpenNode git repo. It looks pretty straight forward. The 1ms timer thread would be an ideal candidate for the core timer scheduler system in chipKIT.
As for the rest of it, it should pretty much just drop into your project as c and header files with minimal changes. I guess you could create a wrapper "library" around it to make it more self contained.
Janez:
Thank you for your information.
This is the main file for PIC32 board and mplabx:
https://github.com/CANopenNode/CANopenPIC/blob/master/PIC32/main_PIC32.c
There is:
"int main (void){}" function for configuration and endless loop for time non critical code.
Timer interrupt with 1ms execution for fast realtime functions.
"void __ISR(_CAN_1_VECTOR, IPL5SOFT) CO_CAN1InterruptHandler(void)" for CAN reception and transmission.
Can you give a quick hint about basic organization of these functions, so I could quickly start experimenting. Is there something special with interrupts?
matt:
For Arduino the bits of main()
that run once at startup go in setup()
. Anything that runs repeatedly goes in loop()
. Basically you're given a pre-defined main()
that is essentially:
void main() {
setup();
while (1) {
loop();
}
}
There's other stuff in there that runs before setup()
to configure stuff, but that's essentially it.
You could stick to using the timer for the 1ms tick if that's simpler. I wrote a document all about the chipKIT interrupt system: https://chipkit.net/wp-content/uploads/2016/02/MajenkoTech-AN1132-Working-with-chipKIT-Interrupts.pdf
matt:
Bits like this:
/* Enable system multi vectored interrupts */
INTCONbits.MVEC = 1;
__builtin_enable_interrupts();
/* Disable JTAG and trace port */
DDPCONbits.JTAGEN = 0;
DDPCONbits.TROEN = 0;
are already taken care of for you. All the chip initialization and stuff can be omitted.
Janez:
Thank you, I will try that.