Jump to content
  • 0

Mixing C and Assembly with Arduino IDE for Chipkit UC32


rfuller

Question

Good morning,

Is there a way to mix C with assembly code for the UC32 when using Arduino IDE? Document AT1886 describes how to accomplish this for Atmel chips, but I am wondering if the same thing is possible for the Chipkit devices since they use PIC microcontrollers?

Here is some more background:

I am writing a program for the UC32, and have an assembly program for the PIC32MX340 that I want to call. The assembly function has several arguments, as well as an output. I am wondering if there is any documentation for how to pass data to an assembly program from C? Additionally, which compiler does Arduino IDE use for the Chipkit UC32? It would help if I could find that information.

Thanks,

 

Ryan

Link to comment
Share on other sites

6 answers to this question

Recommended Posts

Hello rfuller,

I was not able to get Majenko's suggestions to work either. I have not had any success with calling an assembly file from the Arduino IDE. One alternative way to resolve this is to have the assembly inline like in the PICxel library here. So it might take some time to make it work this way but i know that it will work this way.

cheers,

Jon

Link to comment
Share on other sites

JPeyron,

Thank you for your input. I have managed to get my code working and wanted to provide an update.

I tried Majenko's suggestion again, this time updating all of my libraries, and it worked! In order to mix C and assembly (.S) files I did the following:

1. Declare the assembly function in the C code using the following syntax: extern "C" {int assembly_algorithm_1(int);};

2. Place the .S file in the same folder as the sketch.

3. Use the following template for assembly functions:

 

#include <xc.h>

    .text
    .set noreorder
 
//----------------------------------------------------------------------------------------------
// Assembly Algorithm 1
//----------------------------------------------------------------------------------------------
    .global assembly_algorithm_1
    .ent assembly_algorithm_1
    assembly_algorithm_1:

        // Code goes here

        // Return to calling function
        JR    ra
        NOP
        
    .end assembly_algorithm_1

The document Majenko provided a link to also has information about how deal with function argument s and return values.

My code now works, so thank you Majenko and JPeyron for your help!

Regards,

Ryan

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...