Where should I put my own functions on a FRDM-KL46z Bareboard Project?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Where should I put my own functions on a FRDM-KL46z Bareboard Project?

Jump to solution
1,239 Views
kiven
Contributor II

I just got my KL46Z, and Ive been noticing that in the main.c file there are a lot of comments telling me not to edit this and that part of the code, also I can't just put code where I want, so where do I write my functions? I'm gonna need them to simplify my code.

I set Processor expert, OpenSDA, Bareboard for the project options (if You need that info).

Example:

void operationExample(void){

BLAH BLAH BLAH;

}

Thank you for your time.

Any help is apreciated, also with my english :smileyhappy:

Tags (2)
1 Solution
910 Views
adriancano
NXP Employee
NXP Employee

Hi Kiven,

You can see in the image below how to manage your own function in processor expert code. Write your function in any other part out from the main function, then you have to add the prototype of the function just like a global variable. You can use your function in any part of your code, I hope the image explains all clearly.

My_Function PE.png

Where says "Do not write your code here" it is because this for the use of PE, just a security measure. If you write your code there every-time you generate new code with Processor Expert all the code that is written there will be erased.

I hope this information can help you.

-----------------------------------------------------------------------------------------------------------------------

Note: If this post answers your question, please click the Correct Answer button. It would be nice!

-----------------------------------------------------------------------------------------------------------------------

*************************************************************************************************************

Hola Kevin,

La imagen te muestra cómo manejar el uso de tus propias funciones. Primero debes de escribir la función en cualquier parte fuera de main, después tienes que agregar el prototipo de la función como si agregaras una variable global. Puedes usar tu función en cualquier parte del código, espero que la imagen explique todo con detalle.

Donde dice "Do not write your code here" es porque esto es uso exclusivo de PE, como una medida de seguridad. Si escribes código ahí cada vez que generes nuevo código con Processor Expert ese código se borrará.

Espero que esta información te ayude.

-----------------------------------------------------------------------------------------------------------------------

Nota: Si esta respuesta responde tu pregunta, porfavor dale Click en el botón Correct Answer. Muchas gracias!

-----------------------------------------------------------------------------------------------------------------------

View solution in original post

6 Replies
911 Views
adriancano
NXP Employee
NXP Employee

Hi Kiven,

You can see in the image below how to manage your own function in processor expert code. Write your function in any other part out from the main function, then you have to add the prototype of the function just like a global variable. You can use your function in any part of your code, I hope the image explains all clearly.

My_Function PE.png

Where says "Do not write your code here" it is because this for the use of PE, just a security measure. If you write your code there every-time you generate new code with Processor Expert all the code that is written there will be erased.

I hope this information can help you.

-----------------------------------------------------------------------------------------------------------------------

Note: If this post answers your question, please click the Correct Answer button. It would be nice!

-----------------------------------------------------------------------------------------------------------------------

*************************************************************************************************************

Hola Kevin,

La imagen te muestra cómo manejar el uso de tus propias funciones. Primero debes de escribir la función en cualquier parte fuera de main, después tienes que agregar el prototipo de la función como si agregaras una variable global. Puedes usar tu función en cualquier parte del código, espero que la imagen explique todo con detalle.

Donde dice "Do not write your code here" es porque esto es uso exclusivo de PE, como una medida de seguridad. Si escribes código ahí cada vez que generes nuevo código con Processor Expert ese código se borrará.

Espero que esta información te ayude.

-----------------------------------------------------------------------------------------------------------------------

Nota: Si esta respuesta responde tu pregunta, porfavor dale Click en el botón Correct Answer. Muchas gracias!

-----------------------------------------------------------------------------------------------------------------------

910 Views
kiven
Contributor II

Muchísimas gracias! Es exactamente lo que buscaba!

Aprecio tu respuesta. Hay alguna manera de mantenernos en contacto? soy nuevo en esto y me gustaría contar con alguien que pudiera resolver una que otra pregunta, claro, si es que quieres y puedes. Gracias de todas formas!

Saludos!

0 Kudos
910 Views
ankur_vcns_apps
NXP Employee
NXP Employee

Hi Kiven,

When you generate a bareboard project using Processor expert, you would generally find a processorexpert.c file containing the main() function.

/*lint -save  -e970 Disable MISRA rule (6.3) checking. */

int main(void)

/*lint -restore Enable MISRA rule (6.3) checking. */

{

  /* Write your local variable definition here */

------------------------------------------------------------------------------------------------------------------------------------------you can add your local variable definitions here

  /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/

  PE_low_level_init();

  /*** End of Processor Expert internal initialization.                    ***/

  /* Write your code here */

  /* For example: for(;;) { } */

  /*** Don't write any code pass this line, or it will be deleted during code generation. ***/

  /*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/

  #ifdef PEX_RTOS_START

    PEX_RTOS_START();                  /* Startup of the selected RTOS. Macro is defined by the RTOS component. */

  #endif

  /*** End of RTOS startup code.  ***/

  /*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/

  for(;;){}             ---------------------------------------------------------------------------------------------------------------you can write your code here

  /*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/

} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/

Hope this solves what you were looking for. :smileyhappy:

910 Views
kiven
Contributor II

Hey, thank you for your response.

I wanted to know where should i put my functions, their prototypes and all that stuff.

I experimented and found that you can declare and define them below the include list just like a normal C file.

Thank you, tho! :smileygrin:

Muchas gracias, desde México.

0 Kudos
910 Views
ankur_vcns_apps
NXP Employee
NXP Employee

Hi Kiven,

For sure you can work like a normal C file. Only point to be taken care is that if your functions are defined below from where they are called then you would have to declare those functions at the start. For eg.

int sum (int a, int b);

main

{

  int var1, var2, result;

  result = sum (var1, var2);

}

int sum(int a, int b)

{

     int result;

     result= a+b;

     return result ;

}

this way you wont find any issue. However if the function is not declared at the start, compiler may give error.

Regards,

Ankur

0 Kudos
910 Views
Wlodek_D_
Senior Contributor II

Hello,

Thank you for your post, however please consider moving it to the right community place (e.g. CodeWarrior Development Tools or Kinetis Microcontrollers ) to get it visible for active members.

For details please see general advice Where to post a Discussion?

Thank you for using Freescale Community.