Question of debug in KDS IDE

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

Question of debug in KDS IDE

Jump to solution
846 Views
guohuoping
Contributor II

I create a project in KDS, and it use MK10DX256VLH7. Now, I have a question to ask for your help.

I use PE to initial a SPI component, which involve Input interrupt and Output interrupt,and at the initial progress, PE auto enable SPI component also.Then, I define two variables, spi_tx_fin and spi_rx_fin. In the project, PE create two event functions, void SPI_OnBlockReceived(LDD_TUserData *UserDataPtr) and void SPI_OnBlockSent(LDD_TUserData *UserDataPtr). For the convenience of polling SPI transmit and/or receive progress success or not, I write the code: spi_tx_fin = Yesand spi_rx_fin = Yes  (Macro: Yes=1, No=0) in the two event functions respectively. Afterward, I define another function MotorInit(), which call function  LDD_TError SPI_SendBlock(LDD_TDeviceData *DeviceDataPtr, LDD_TData *BufferPtr, uint16_t Size) generated by PE to transmit data on the SPI module. The code as follows:

motor.c :

union TAG_IF_CONFIGURATION_429{

  struct IF_CONFIGURATION_429{

  uint32 INV_REF : 1;

  uint32 SDO_INT : 1;

  uint32 STEP_HALF : 1;

  uint32 INV_STP : 1;

  uint32 INV_DIR : 1;

  uint32 EN_SD : 1;

  uint32 POS_COMP_SEL_0 : 1;

  uint32 POS_COMP_SEL_1 : 1;

  uint32 EN_REFR : 1;

  uint32 RESERVE : 15;

  uint32 RW : 1;

  uint32 JDX : 4;

  uint32 smda : 2;

  uint32 RRS : 1;

  }if_configuration_429;

  uint8 buffer[4];

}if_configuration_429;

MotorInit()

{

  if_configuration_429.if_configuration_429.INV_REF = 0;

  .....

  spi_tx_fin = No;

  SPI_SendBlock(pSPI,if_configuration_429.buffer,4);

  while(spi_tx_fin == No);

   .....

}

 

Event.c :

void SPI_OnBlockSent(LDD_TUserData *UserDataPtr)

{

  /* Write your code here ... */

  spi_tx_fin = Yes;

}

 

Unfortunately, when debug program, the progress was blocked here while(spi_tx_fin == No); I checked the debug progress and was sure in the event function void SPI_OnBlockSent(LDD_TUserData *UserDataPtr) the variable spi_tx_fin was set Yes

 

By the way, I offer my project to you. Thank you!

16634_16634.bmpos.bmp

Above picture is about the build optimization level -Os, it is that debug progress was blocked here while(spi_tx_fin == No);

 

Now, the below picture is about the build optimization level None(-O0), it is that debug progress was ok sometime.

16633_16633.bmpdebug picture.bmp

消息编辑者为:guo huoping One picture added

 

消息编辑者为:guo huoping Edit my question again! Wait your answer sincerely! Thank you!

Original Attachment has been moved to: workspace.kds.rar

Labels (1)
0 Kudos
1 Solution
550 Views
adriancano
NXP Employee
NXP Employee

Hi Guo,

Indeed all the callbacks (functions included in the events.c file) are called just before the processor services the Interrupt Routine (ISR); in those ISR the Processor Expert code handles the interrupt flags and perform some actions before calling the callback, this means that when the code reaches the callback function the interrupt was already serviced, and this means that there are not hardware issues and the interrupt is being serviced.

Please check the next link to see what are the differences between optimizations. Optimization Levels - GNAT User's Guide

I will include here part of the text for your reference.

Without any optimization option, the compiler's goal is to reduce the cost of compilation and to make debugging produce the expected results. Statements are independent: if you stop the program with a breakpoint between statements, you can then assign a new value to any variable or change the program counter to any other statement in the subprogram and get exactly the results you would expect from the source code.

Turning on optimization makes the compiler attempt to improve the performance and/or code size at the expense of compilation time and possibly the ability to debug the program.


This implies that the optimization will reduce the ability to debug the program.


I am not quite sure about this behavior but maybe this could be reason. You can try using a volatile variable for the callback flags.


In events.c declare:

volatile uint8_t spi_tx_fin = 0;


In main.c declare it as external:

extern volatile uint8_t spi_tx_fin;

Hope this information can help you.

Best Regards,
Adrian Sanchez Cano
Technical Support Engineer
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

View solution in original post

0 Kudos
4 Replies
550 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hi guo,

I suggest you enable the interrupt even if you don't use .

or  before read receive data , use the function of "SS1_Main(slaveDevData);" about this function , you can find on file of "SS1.C".

Hope it helps!

Alice

0 Kudos
550 Views
guohuoping
Contributor II

Hi Alice,

In my project, I have enabled the interrupt. Also, I have saw the debug progress run in the interrupt function PE_ISR(SPI_Interrupt), and sure the function void SPI_OnBlockSent(LDD_TUserData *UserDataPtr) was called from the interrupt function. I was confused that the debug progress blocked in the interrupt when the project build optimization level was set -Os and it seemed the program thread not return and blocked on the line: while(spi_tx_fin == No);. How ever, the program thread could return from the interrupt when the build optimization level was set -None(-O0) and not blocked on the line:while(spi_tx_fin == No). I hope you can download the project I provided and test it.

Thank you for response! I sincerely wait for your success answer.

Guo Huoping

0 Kudos
551 Views
adriancano
NXP Employee
NXP Employee

Hi Guo,

Indeed all the callbacks (functions included in the events.c file) are called just before the processor services the Interrupt Routine (ISR); in those ISR the Processor Expert code handles the interrupt flags and perform some actions before calling the callback, this means that when the code reaches the callback function the interrupt was already serviced, and this means that there are not hardware issues and the interrupt is being serviced.

Please check the next link to see what are the differences between optimizations. Optimization Levels - GNAT User's Guide

I will include here part of the text for your reference.

Without any optimization option, the compiler's goal is to reduce the cost of compilation and to make debugging produce the expected results. Statements are independent: if you stop the program with a breakpoint between statements, you can then assign a new value to any variable or change the program counter to any other statement in the subprogram and get exactly the results you would expect from the source code.

Turning on optimization makes the compiler attempt to improve the performance and/or code size at the expense of compilation time and possibly the ability to debug the program.


This implies that the optimization will reduce the ability to debug the program.


I am not quite sure about this behavior but maybe this could be reason. You can try using a volatile variable for the callback flags.


In events.c declare:

volatile uint8_t spi_tx_fin = 0;


In main.c declare it as external:

extern volatile uint8_t spi_tx_fin;

Hope this information can help you.

Best Regards,
Adrian Sanchez Cano
Technical Support Engineer
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
550 Views
guohuoping
Contributor II

Thank you!

I got your advice, and the answer is correct!

0 Kudos