migrate S12ZVM-EFP example code to MTRCKTSPNZVML31 evaluation board

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

migrate S12ZVM-EFP example code to MTRCKTSPNZVML31 evaluation board

Jump to solution
1,449 Views
NoahXu
Contributor III

hello, support team 

i followed AN5330 to migrate, i finished  all steps in chapter 4 ,but still got problems.

can you help to debug if the function and LIN comm is ok?

is there any diffrence between L31 version and  L128/L64/L32 not mentioned in AN5330?

remarks :i changed the cpmu.c and pim .c from original , if useless pls use the original code.

thanks

 

0 Kudos
1 Solution
1,311 Views
RadekS
NXP Employee
NXP Employee

Hi NoahXu,

This obviously looks like you defined the interrupt vector twice and they overlap.

The source project has a bit of complicated interrupt vectors definitions due to compatibility with CW and Cosmic compilers. But the main vector table _vectab[] is located in vector.c file.

As I can see in the code, you added ISRs definitions via interrupt keyword and interrupt number like:
interrupt VectorNumber_Vtim0ch3 void TIM0chan3_ISR(void)

As a result, the TIM0 channel 3 interrupt vector is defined twice.

So, you have to either modify newly added interrupts to syntax used by original project (use only "INTERRUPT" keyword, they will be part of _vectab,...) or you have to abadon the _vectab vector table and rewrite original ISRs to style that you used in your modifications (keyword "interrupt" plus vector number). Optionally you may define the vector number in prm linker file intead of C code.

The might be always only one definition for each of interrupt vector.

Advantage of vector table is that it covers also the unexpected interrupt situation while independent interupt vectors definition is more simple to understood. 
As I already mentioned, the source vector table definition is prepared also for Cosmic compiler while the "interrupt" keyword meaning is CodeWarrior compiler specific.

Please be also aware that the memory overlaping warning is disabled by default. For more details: https://community.nxp.com/t5/S12-MagniV-Microcontrollers/S12Z-constant-variable-code-allocation-in-C...

I hope it helps you.
BR

RadekS

View solution in original post

0 Kudos
10 Replies
1,383 Views
NoahXu
Contributor III

Hi, Radek  thanks again for your post.

I imported the SW project to code warrior 11, it seems all  the AMMC lib not included in the sw package, so i copied the AMMCLIB_v1.1.14 to the project and updated the include path in the properties.

however i got many errors after build .Interesting thing is i already include the lib, but the IDE hint is :"the file'gdflib.h' cannot be opened".

is it caused by the code warrior version? if yes can you post the link to download?i only found the V11 and also in the previous version i found V10 for eTPU . 

NoahXu_0-1690897152307.png

 

0 Kudos
1,353 Views
RadekS
NXP Employee
NXP Employee

Hi NoahXu,
you are right, the sw project does not contain the AMMCLib inside the project.
The error means that AMMCLib was not included properly. 


The AMMCLib in the source project is linked from the default folder C:\\NXP\AMMCLIB\MC9S12ZVM_AMMCLIB_v1.1.xx
where xx may vary according to your AMMCLib installation.
The latest AMMCLib (currently 1.1.33; you may download also previous versions) may be downloaded from nxp.com/AMMCLib
The path to the library must be updated on three places in project settings (in Linker, Compiler, Assembler sections). See highlighted positions on picture:

RadekS_0-1690904028701.png

just double-click on the path and rewrite the number 27 to version that you installed into default location.
The API should be fully compatible across AMMCLib versions. So, you should be able to use almost any version.  

Hint: I would like to recommend also clean project before building everytime when you import any project (there might be files in FLASH folder that cause problem with paths). Optionaly you may delete the FLASH folder and Refresh (F5) the project.
It seems that I forgot to clean the FLASH folder prior sharing.

 

BR

RadekS

 

0 Kudos
1,326 Views
NoahXu
Contributor III

Morning,Radek  thanks for your solution, i compiled the code with success result.

when i go into the next step which is LIN stack integration, i found another issue:

"INF: block 00FFFE10-00FFFFFF ...
INF: Calculated CRC-16 does not match block. (File = $8E62, Device = $FB36)
ERR: Error verifying flash of device
ERR: Error occured during Flash programming."

i checked the linker file according to the address "00FFFE10-00FFFFFF" and it seems the interrupt vectors are set wrong with  my project, but i cannot find why. can you help to check again for the issue?

 

 

0 Kudos
1,312 Views
RadekS
NXP Employee
NXP Employee

Hi NoahXu,

This obviously looks like you defined the interrupt vector twice and they overlap.

The source project has a bit of complicated interrupt vectors definitions due to compatibility with CW and Cosmic compilers. But the main vector table _vectab[] is located in vector.c file.

As I can see in the code, you added ISRs definitions via interrupt keyword and interrupt number like:
interrupt VectorNumber_Vtim0ch3 void TIM0chan3_ISR(void)

As a result, the TIM0 channel 3 interrupt vector is defined twice.

So, you have to either modify newly added interrupts to syntax used by original project (use only "INTERRUPT" keyword, they will be part of _vectab,...) or you have to abadon the _vectab vector table and rewrite original ISRs to style that you used in your modifications (keyword "interrupt" plus vector number). Optionally you may define the vector number in prm linker file intead of C code.

The might be always only one definition for each of interrupt vector.

Advantage of vector table is that it covers also the unexpected interrupt situation while independent interupt vectors definition is more simple to understood. 
As I already mentioned, the source vector table definition is prepared also for Cosmic compiler while the "interrupt" keyword meaning is CodeWarrior compiler specific.

Please be also aware that the memory overlaping warning is disabled by default. For more details: https://community.nxp.com/t5/S12-MagniV-Microcontrollers/S12Z-constant-variable-code-allocation-in-C...

I hope it helps you.
BR

RadekS

0 Kudos
1,299 Views
NoahXu
Contributor III

Hi,Radek
thanks for your reminder, the complie is success.
i use this style syntax"interrupt VectorNumber_Vtim0ch3 void TIM0chan3_ISR(void)" for all interrupts and also comment out the line "//vector INTO OSVECTORS; /* OSEK */" in linker file . is it ok?

the second question is that the lin message cannot sent out. the project is based on AN5327_SW_CW10+LIN STACK_S12_4_6_6, the evaluation board is MTRCKTSPNZVML31. currently :complie success, but no lin message sent out (i use canoe to schedule the lin table). can you kindly check the code?

0 Kudos
1,416 Views
RadekS
NXP Employee
NXP Employee

Hi NoahXu,

I ported sw project to S12ZVML31 some time ago, but I didn't follow the AN5330. I would like to also highlight, that I didn't work with EFP project, but with AN5327SW.


Here are some hints for project modifications, that might be useful for you:

  • I would like to recommend creating new bareboard project for S12ZVML31 as a source project for mc9s12zvml31.h and mc9s12zvml31.c files.
  • The AN5327 wouldn’t fit into 4kB of RAM. So we have to optimize the code, for example by removing the FreeMASTER
    • #include "freemaster.h"
    • FMSTR_Init();
    • FMSTR_Poll();
    • FMSTR_Recorder();
    • Whole TSA table definition starting from FMSTR_TSA_TABLE_BEGIN(S12ZVM_PMSM) and ends by FMSTR_TSA_TABLE_LIST_END()
    • At MC9S12ZVML128_PMSM.c comment-out lines:
    • At motor_structure.h comment out:
  • Edit the S12zvm.prm linker file (you may look at mc9s12zvml31.prm in S12ZVML31 source project)
    • New RAM range will be: RAM           = READ_WRITE  0x001000 TO 0x001FFF;  //S12ZVML31 range
    • New ROM range will be: ROM           = READ_ONLY   0xFF8000 TO 0xFFFDFF;  //S12ZVML31 range
  • Link to S12ZVML31 MCU
    • Copy the mc9s12zvml31.h and mc9s12zvml31.c from S12ZVML31 source project to the AN5327 project
    • Now you may either edit appropriate c and h files and replace all includes to the new header files (clean way) or you may backup the mc9s12zvml128 version c and h files and rename mc9s12zvml31.h and mc9s12zvml31.c files as mc9s12zvml128.h and mc9s12zvml128.c (fast way)
    • If you choose the fast way in the previous step, do not forget to edit the new version of mc9s12zvml128.c and modify the line with the header file include  
  • You may implement dual step alignment in in the StateAlign() function:

 

/*+++++++++++++++ dual state alignment improvement +++++++++++++++ */
//Old code:
//    drvFOC.uDQReq.f16Arg1      = drvFOC.alignVoltage;
//    drvFOC.uDQReq.f16Arg2      = FRAC16(0);
//New code:
    if (drvFOC.alignCntr>(tU16)(drvFOC.alignCntrInit*ALIGN_D_FACTOR))
    {
        drvFOC.uDQReq.f16Arg1      = FRAC16(0);
        drvFOC.uDQReq.f16Arg2      = drvFOC.alignVoltage;
    }
    else
    {
        drvFOC.uDQReq.f16Arg1      = drvFOC.alignVoltage;
        drvFOC.uDQReq.f16Arg2      = FRAC16(0);
    }
/*+++++++++++++++ dual state alignment improvement end +++++++++++++++ */​

 

  • Since S12ZVML31 applications are mostly LIN based and do not use external oscilator, the clock init needs to be modified to PEI mode. For example:
    void cpmu_init(void)
    {
    	// Wait for stable supply after power up
    	while (GDUF_GLVLSF)
    		GDUF_GLVLSF = 1;
    	
    	CPMUSYNR = 0x00;
    	
    	CPMUPOSTDIV_POSTDIV = 0;	
    	CPMUREFDIV = 0;	
    	//CPMUSYNR = 0xF1;	// 100MHz VCO output
    	CPMUSYNR = 0x67;	// 80MHz VCO output
    	CPMUIFLG = 0xFF;  // clear all flags, especially LOCKIF and OSCIF
    
    //	CPMUREFDIV_REFDIV = 3;		// 4MHz => 1MHz
    //	CPMUREFDIV_REFFRQ = 0;		// 0 for 1MHz - 2MHz
    //	CPMUSYNR_SYNDIV = 49; 		// 100 MHz VCO output
    //	CPMUSYNR_VCOFRQ = 3;
    //	CPMUPOSTDIV_POSTDIV = 0;	// 100MHz
    //
    //	CPMUOSC_OSCE = 1;
    //
    	CPMUHTCTL_VSEL = 0;	//Voltage Access Select Bit
    	CPMUHTCTL_HTE = 1;	//High Temperature Sensor/Bandgap Voltage Enable Bit
    //
    //	// Wait for oscillator to start up (UPOSC=1) and PLL to lock (LOCK=1).
    //	while (CPMUIFLG_UPOSC == 0) {};
    	while (CPMUIFLG_LOCK == 0) {};
    	   while(CPMUCLKS != 0b10000000)            // After writing CPMUCLKS register, it is strongly recommended to read  
    	       {                                    // back CPMUCLKS register to make sure that write of PLLSEL,
    	                                            // RTIOSCSEL, COPOSCSEL0 and COPOSCSEL1 was successful.
    	          CPMUCLKS = 0b10000000;                   
    	                    /* ||||||||-------- COPOSCSEL0 - COP Clock Select 0
    	                       |||||||--------- RTIOSCSEL - RTI Clock Select
    	                       ||||||---------- PCE - COP Enable During Pseudo Stop Bit
    	                       |||||----------- PRE - RTI Enable During Pseudo Stop Bit
    	                       ||||------------ COPOSCSEL1 - COP Clock Select 1
    	                       |||------------- CSAD - COP in Stop Mode ACLK Disable
    	                       ||-------------- PSTP   - Pseudo Stop Bit
    	                       |--------------- PLLSEL - PLL Select Bit
    	                    */
    	       }
    	CPMURFLG  = 0x60; 	//Clear PORF and LVRF
    }​
  • You may implement also improved startup in focSlowLoop() function:
    /*++++++++++++ Improved motor startup code update ++++++++++++*/ 	
    	// Speed FO control mode
    //  Obsolete code:
    //	if(cntrState.usrControl.FOCcontrolMode == speedControl)
    //		drvFOC.currentLoop.pIDQReq->f16Arg2         	= GFLIB_ControllerPIpAW(drvFOC.pospeControl.wRotElErr,&drvFOC.speedPI);
    //  New code:
    	if(cntrState.usrControl.FOCcontrolMode == speedControl)
    	{
    	    if(pos_mode == sensorless1)
    	    {
    	        // In Speed control and sensorless mode, FOC Outer Loop (Speed Loop & Field Weakening) output is interconnected with FOC Inner Loop (Current Loop) input
     	        drvFOC.currentLoop.pIDQReq->f16Arg1         	= FRAC16(0.0);
    	        drvFOC.currentLoop.pIDQReq->f16Arg2         	= GFLIB_ControllerPIpAW(drvFOC.pospeControl.wRotElErr,&drvFOC.speedPI);
    	    }
    	else
    	    {
    	        // In Speed control and force/tracking mode, required d-axis current is set to Start-up current and q-axis current is set to 0
    	        drvFOC.currentLoop.pIDQReq->f16Arg1         	= drvFOC.pospeOpenLoop.iQUpperLimit;
    	        drvFOC.currentLoop.pIDQReq->f16Arg2         	= FRAC16(0.0);
    	    }
    	}
    /*++++++++++++ Improved motor startup code update end ++++++++++++*/ ​
  • If you use your own design with different transistors, you may also reach issue with dead-time (the time delay between we disable the top transistor and enabling the bottom transistor or in the opposite way).
    For editing, go to pmf_init() function in pmf.c file and increase the dead time value in PMFDTMA register. I tried for example value 60 (0.6us) instead of 20 (0.2us). The right value must be set according measurement on all three phases on target pcb (plus some margin).

 

 

After building project, you may edit the debug Configuration. Here is described fast way by editing the current debug Configuration.

  • Go to Target Settings and edit the Connection

RadekS_0-1690883500898.png

  • Edit the Target

RadekS_1-1690883520885.png

  • Select S12ZVML31 Target type

RadekS_2-1690883543464.png

Of course, you may create your own Debug Configuration instead of it.

I hope it helps you.

Best regards

RadekS

0 Kudos
1,410 Views
NoahXu
Contributor III
Hi,Radek thanks for your fast response.
can you post here your S12ZVML31 version SW which based on AN5327SW ?
0 Kudos
1,332 Views
Junjie
NXP Employee
NXP Employee

Hi @NoahXu 

      S12ZVM- EFP was devekoped by GPIS china AE team, you can also connect to me (junjie.lai@nxp.com) If there are some problems about EFP project porting later. Thank you!

BR

Junjie

0 Kudos
1,321 Views
NoahXu
Contributor III
Hi, Junjie do you have the EFP project based on S12ZVML31? can you post here?
0 Kudos
1,403 Views
RadekS
NXP Employee
NXP Employee

It is already a year old project - so, without a warranty, just for reference.

I hope it helps you.

BR

RadekS

0 Kudos