MCXN547 SC Timer0 SDK driver Issue

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

MCXN547 SC Timer0 SDK driver Issue

81 Views
JawaharA
Contributor I

I am using MCXN547VKL MCU and SDK version 26.06.00. 

Context: I am using SCT timer0  to generate two different PWM waveform using the COUNTER in split mode, CONFIG[UNIFY] = 0; i.e COUNT_L for one PWM generator and COUNT_H for another PWM generator.

The issue: When I load the COUNTER_H with the driver API "SCTIMER_SetCOUNTValue(SCT0,kSCTIMER_Counter_H,0U);" , Bus Fault occurs. 

I traced the issue to SDK driver code. The driver code uses 32 bit write to write both COUNT_H and COUNT_L instead of 16 bit write to COUNT_H alone. While the COUNT_H is being written COUNT_L was running and this caused bus fault. I modified the SDK driver code to use 16 bit write and the bus fault did not occur. I have attached the driver code and marked with colours, the code line which was causing the problem and the fix. If this is really the problem, the SDK driver can be updated. - Thanks

 

/*!

* @brief Set the value of counter.

*

* The function is to set the value of Count register, Writing to the COUNT_L, COUNT_H, or unified register

* is only allowed when the corresponding counter is halted (HALT bits are set to 1 in the CTRL register).

*

* @param base SCTimer peripheral base address

* @param whichCounter SCTimer counter to use. In 16-bit mode, we can select Counter_L and Counter_H,

* In 32-bit mode, we can select Counter_U.

* @param value the counter value update to the COUNT register.

*/

static inline void SCTIMER_SetCOUNTValue(SCT_Type *base, sctimer_counter_t whichCounter, uint32_t value)

{

SCTIMER_StopTimer(base, (uint32_t)whichCounter);

switch (whichCounter)

{

case kSCTIMER_Counter_L:

assert(value <= 0xFFFFU);

assert(0U == (base->CONFIG & SCT_CONFIG_UNIFY_MASK));

/* Use Counter_L bits when user wants to setup the Low counter */

base->COUNT_ACCESS16BIT.COUNTL = (uint16_t)value;

break;

 

case kSCTIMER_Counter_H:

assert(value <= 0xFFFFU);

assert(0U == (base->CONFIG & SCT_CONFIG_UNIFY_MASK));

/* Use Counter_H bits when user wants to setup the High counter */

// base->COUNT = (uint32_t)base->COUNT_ACCESS16BIT.COUNTL | SCT_COUNT_CTR_H(value);

base->COUNT_ACCESS16BIT.COUNTH = (uint16_t)value; //the fix

break;

 

case kSCTIMER_Counter_U:

assert(1U == (base->CONFIG & SCT_CONFIG_UNIFY_MASK));

/* Use both Counter_L/Counter_H bits when counter is operating in 32-bit mode (unify counter). */

base->COUNT = value;

break;

 

default:

/* Fix the MISRA C-2012 issue rule 16.4. */

break;

}

 

SCTIMER_StartTimer(base, (uint32_t)whichCounter);

}

Labels (1)
0 Kudos
Reply
1 Reply

2 Views
Harry_Zhang
NXP Employee
NXP Employee

Hi @JawaharA 

Thank you for your feedback. Your analysis of the cause of the Bus Fault is correct: updating COUNT_H uses a 32-bit write to the COUNT register, but the current function halts only the H counter. If the L counter is still running, this write access triggers an SCT bus error.

However, changing the access to a 16-bit write to COUNTH is not compliant with the SCT hardware access requirements, because COUNT_H must be written as a word together with COUNT_L . The correct software solution is to halt both the L and H counters before performing the 32-bit write to COUNT , and then restore their previous running states afterward. We recommend reviewing and updating the SDK accordingly rather than using a separate 16-bit write to COUNT_H .

Harry_Zhang_0-1790589981399.png

 

BR

Harry

0 Kudos
Reply
%3CLINGO-SUB%20id%3D%22lingo-sub-2416496%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3EMCXN547%20SC%20Timer0%20SDK%20driver%20Issue%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2416496%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EI%20am%20using%20MCXN547VKL%20MCU%20and%20SDK%20version%2026.06.00.%26nbsp%3B%3C%2FP%3E%3CP%3EContext%3A%20I%20am%20using%20SCT%20timer0%26nbsp%3B%20to%20generate%20two%20different%20PWM%20waveform%20using%20the%20COUNTER%20in%20split%20mode%2C%20CONFIG%5BUNIFY%5D%20%3D%200%3B%20i.e%20COUNT_L%20for%20one%20PWM%20generator%20and%20COUNT_H%20for%20another%20PWM%20generator.%3C%2FP%3E%3CP%3EThe%20issue%3A%20When%20I%20load%20the%20COUNTER_H%20with%20the%20driver%20API%20%22%3CSPAN%3ESCTIMER_SetCOUNTValue(SCT0%2CkSCTIMER_Counter_H%2C0U)%3B%22%20%2C%20Bus%20Fault%20occurs.%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3EI%20traced%20the%20issue%20to%20SDK%20driver%20code.%20The%20driver%20code%20uses%2032%20bit%20write%20to%20write%20both%20COUNT_H%20and%20COUNT_L%20instead%20of%2016%20bit%20write%20to%20COUNT_H%20alone.%20While%20the%20COUNT_H%20is%20being%20written%20COUNT_L%20was%20running%20and%20this%20caused%20bus%20fault.%20I%20modified%20the%20SDK%20driver%20code%20to%20use%2016%20bit%20write%20and%20the%20bus%20fault%20did%20not%20occur.%20I%20have%20attached%20the%20driver%20code%20and%20marked%20with%20colours%2C%20the%20code%20line%20which%20was%20causing%20the%20problem%20and%20the%20fix.%20If%20this%20is%20really%20the%20problem%2C%20the%20SDK%20driver%20can%20be%20updated.%20-%20Thanks%3C%2FSPAN%3E%3C%2FP%3E%3CBR%20%2F%3E%3CDIV%3E%3CDIV%3E%3CP%3E%3CFONT%20size%3D%222%22%3E%3CSPAN%3E%2F*!%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20size%3D%222%22%3E%3CSPAN%3E*%20%40brief%20Set%20the%20value%20of%20counter.%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20size%3D%222%22%3E%3CSPAN%3E*%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20size%3D%222%22%3E%3CSPAN%3E*%20The%20function%20is%20to%20set%20the%20value%20of%20Count%20register%2C%20Writing%20to%20the%20COUNT_L%2C%20COUNT_H%2C%20or%20unified%20register%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20size%3D%222%22%3E%3CSPAN%3E*%20is%20only%20allowed%20when%20the%20corresponding%20counter%20is%20halted%20(HALT%20bits%20are%20set%20to%201%20in%20the%20CTRL%20register).%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20size%3D%222%22%3E%3CSPAN%3E*%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20size%3D%222%22%3E%3CSPAN%3E*%20%40%3C%2FSPAN%3E%3CSPAN%3Eparam%3C%2FSPAN%3E%3CSPAN%3E%20base%20SCTimer%20peripheral%20base%20address%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20size%3D%222%22%3E%3CSPAN%3E*%20%40%3C%2FSPAN%3E%3CSPAN%3Eparam%3C%2FSPAN%3E%3CSPAN%3E%20whichCounter%20SCTimer%20counter%20to%20use.%20In%2016-bit%20mode%2C%20we%20can%20select%20Counter_L%20and%20Counter_H%2C%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20size%3D%222%22%3E%3CSPAN%3E*%20In%2032-bit%20mode%2C%20we%20can%20select%20Counter_U.%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20size%3D%222%22%3E%3CSPAN%3E*%20%40%3C%2FSPAN%3E%3CSPAN%3Eparam%3C%2FSPAN%3E%3CSPAN%3E%20value%20the%20counter%20value%20update%20to%20the%20COUNT%20register.%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20size%3D%222%22%3E%3CSPAN%3E*%2F%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20size%3D%222%22%3E%3CSPAN%3Estatic%3C%2FSPAN%3E%20%3CSPAN%3Einline%3C%2FSPAN%3E%20%3CSPAN%3Evoid%3C%2FSPAN%3E%20%3CSPAN%3ESCTIMER_SetCOUNTValue%3C%2FSPAN%3E%3CSPAN%3E(%3C%2FSPAN%3E%3CSPAN%3ESCT_Type%3C%2FSPAN%3E%3CSPAN%3E%20*base%2C%20%3C%2FSPAN%3E%3CSPAN%3Esctimer_counter_t%3C%2FSPAN%3E%3CSPAN%3E%20whichCounter%2C%20%3C%2FSPAN%3E%3CSPAN%3Euint32_t%3C%2FSPAN%3E%3CSPAN%3E%20value)%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20size%3D%222%22%3E%3CSPAN%3E%7B%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20size%3D%222%22%3E%3CSPAN%3ESCTIMER_StopTimer(base%2C%20(%3C%2FSPAN%3E%3CSPAN%3Euint32_t%3C%2FSPAN%3E%3CSPAN%3E)whichCounter)%3B%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20size%3D%222%22%3E%3CSPAN%3Eswitch%3C%2FSPAN%3E%3CSPAN%3E%20(whichCounter)%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20size%3D%222%22%3E%3CSPAN%3E%7B%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20size%3D%222%22%3E%3CSPAN%3Ecase%3C%2FSPAN%3E%20%3CSPAN%3EkSCTIMER_Counter_L%3C%2FSPAN%3E%3CSPAN%3E%3A%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20size%3D%222%22%3E%3CSPAN%3Eassert(value%20%26lt%3B%3D%200xFFFFU)%3B%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20size%3D%222%22%3E%3CSPAN%3Eassert(0U%20%3D%3D%20(base-%26gt%3B%3C%2FSPAN%3E%3CSPAN%3ECONFIG%3C%2FSPAN%3E%3CSPAN%3E%20%26amp%3B%20SCT_CONFIG_UNIFY_MASK))%3B%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20size%3D%222%22%3E%3CSPAN%3E%2F*%20Use%20Counter_L%20bits%20when%20user%20wants%20to%20setup%20the%20Low%20counter%20*%2F%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20size%3D%222%22%3E%3CSPAN%3Ebase-%26gt%3B%3C%2FSPAN%3E%3CSPAN%3ECOUNT_ACCESS16BIT%3C%2FSPAN%3E%3CSPAN%3E.%3C%2FSPAN%3E%3CSPAN%3ECOUNTL%3C%2FSPAN%3E%3CSPAN%3E%20%3D%20(%3C%2FSPAN%3E%3CSPAN%3Euint16_t%3C%2FSPAN%3E%3CSPAN%3E)value%3B%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20size%3D%222%22%3E%3CSPAN%3Ebreak%3C%2FSPAN%3E%3CSPAN%3E%3B%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CFONT%20size%3D%222%22%3E%3CSPAN%3Ecase%3C%2FSPAN%3E%20%3CSPAN%3EkSCTIMER_Counter_H%3C%2FSPAN%3E%3CSPAN%3E%3A%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20size%3D%222%22%3E%3CSPAN%3Eassert(value%20%26lt%3B%3D%200xFFFFU)%3B%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20size%3D%222%22%3E%3CSPAN%3Eassert(0U%20%3D%3D%20(base-%26gt%3B%3C%2FSPAN%3E%3CSPAN%3ECONFIG%3C%2FSPAN%3E%3CSPAN%3E%20%26amp%3B%20SCT_CONFIG_UNIFY_MASK))%3B%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20size%3D%222%22%3E%3CSPAN%3E%2F*%20Use%20Counter_H%20bits%20when%20user%20wants%20to%20setup%20the%20High%20counter%20*%2F%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20size%3D%222%22%20color%3D%22%23FF0000%22%3E%3CSPAN%3E%2F%2F%20base-%26gt%3BCOUNT%20%3D%20(uint32_t)base-%26gt%3BCOUNT_ACCESS16BIT.COUNTL%20%7C%20SCT_COUNT_CTR_H(value)%3B%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20size%3D%222%22%20color%3D%22%2300FF00%22%3E%3CSPAN%3Ebase-%26gt%3B%3C%2FSPAN%3E%3CSPAN%3ECOUNT_ACCESS16BIT%3C%2FSPAN%3E%3CSPAN%3E.%3C%2FSPAN%3E%3CSPAN%3ECOUNTH%3C%2FSPAN%3E%3CSPAN%3E%20%3D%20(%3C%2FSPAN%3E%3CSPAN%3Euint16_t%3C%2FSPAN%3E%3CSPAN%3E)value%3B%20%2F%2Fthe%20fix%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20size%3D%222%22%3E%3CSPAN%3Ebreak%3C%2FSPAN%3E%3CSPAN%3E%3B%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CFONT%20size%3D%222%22%3E%3CSPAN%3Ecase%3C%2FSPAN%3E%20%3CSPAN%3EkSCTIMER_Counter_U%3C%2FSPAN%3E%3CSPAN%3E%3A%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20size%3D%222%22%3E%3CSPAN%3Eassert(1U%20%3D%3D%20(base-%26gt%3B%3C%2FSPAN%3E%3CSPAN%3ECONFIG%3C%2FSPAN%3E%3CSPAN%3E%20%26amp%3B%20SCT_CONFIG_UNIFY_MASK))%3B%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20size%3D%222%22%3E%3CSPAN%3E%2F*%20Use%20both%20Counter_L%2FCounter_H%20bits%20when%20counter%20is%20operating%20in%2032-bit%20mode%20(unify%20counter).%20*%2F%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20size%3D%222%22%3E%3CSPAN%3Ebase-%26gt%3B%3C%2FSPAN%3E%3CSPAN%3ECOUNT%3C%2FSPAN%3E%3CSPAN%3E%20%3D%20value%3B%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20size%3D%222%22%3E%3CSPAN%3Ebreak%3C%2FSPAN%3E%3CSPAN%3E%3B%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CFONT%20size%3D%222%22%3E%3CSPAN%3Edefault%3C%2FSPAN%3E%3CSPAN%3E%3A%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20size%3D%222%22%3E%3CSPAN%3E%2F*%20Fix%20the%20MISRA%20C-2012%20issue%20rule%2016.4.%20*%2F%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20size%3D%222%22%3E%3CSPAN%3Ebreak%3C%2FSPAN%3E%3CSPAN%3E%3B%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20size%3D%222%22%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CFONT%20size%3D%222%22%3E%3CSPAN%3ESCTIMER_StartTimer(base%2C%20(%3C%2FSPAN%3E%3CSPAN%3Euint32_t%3C%2FSPAN%3E%3CSPAN%3E)whichCounter)%3B%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20size%3D%222%22%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FP%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2416496%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CLINGO-LABEL%3EClock%7CTimers%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E