FRDM-KL03Z in KDS: Difference between BWR & WR?

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

FRDM-KL03Z in KDS: Difference between BWR & WR?

Jump to solution
964 Views
sarastout-grand
Contributor III

In writing to the various registers, there appears to be two ways to do it, using BWR and WR. The same is true when reading from them. An example:

TPM_BWR_CONF_CSOO(tpmbase, 0);

TPM_WR_CONF_CSOO(tpmbase, 0);

What is the difference between these two lines? I don't see a difference in the debugger.

Thanks!

Sara

0 Kudos
1 Solution
854 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Sara Stout-Grandy,

    Now let me tell you the details:

TPM_BWR_CONF_CSOO(tpmbase, 0);

TPM_WR_CONF_CSOO(tpmbase, 0);

All the above code is used to set the CSOO bit to a new value.

(1)TPM_WR_CONF_CSOO(tpmbase, 0);

#define TPM_WR_CONF_CSOO(base, value) (TPM_WR_CONF(base, (TPM_RD_CONF(base) & ~TPM_CONF_CSOO_MASK) | TPM_CONF_CSOO(value)))

#define TPM_WR_CONF(base, value) (TPM_CONF_REG(base) = (value))

Use normal C code to define the TPMx_CONF[CSOO] bit to a new value.

(2)TPM_WR_CONF_CSOO(tpmbase, 0);

#define TPM_BWR_CONF_CSOO(base, value) (BME_BFI32(&TPM_CONF_REG(base), ((uint32_t)(value) << TPM_CONF_CSOO_SHIFT), TPM_CONF_CSOO_SHIFT, TPM_CONF_CSOO_WIDTH))

#define BME_BFI32(addr, wdata, bit, width) (*(volatile uint32_t*)((uintptr_t)addr | BME_BFI_MASK(bit,width)) = wdata)

Use the BME code BFI function to define TPMx_CONF[CSOO] bit to a new value.

Normally, use BME code will caused less time than the Normal C code, you can run the KL25 BME code find the detail difference:

http://www.nxp.com/assets/downloads/data/en/lab-test-software/KL25_SC.exe 

Folder: kl25_sc_rev10\klxx-sc-baremetal\build\iar\LQRUG_bme_ex1

pastedImage_2.png

You can find, use the normally C, the same function will caused 0x1b systick counts, but use the BFI code, it only caused 0x16 sysick counts.

In conclusion, BME code save cpu execution time.

Wish it helps you!


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

View solution in original post

0 Kudos
5 Replies
854 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Sar Stout-Grandy,

   Could you tell me where you find these two lines? The official code?

TPM_BWR_CONF_CSOO(tpmbase, 0);

TPM_WR_CONF_CSOO(tpmbase, 0);

You can open the function definition to check the difference.

You also can post these two function definition.


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
854 Views
sarastout-grand
Contributor III

Hi Kerry,

These functions come from inside the MKL03Z4_extension.h file which is found in the C:\Freescale\KSDK_1.3.0\platform\devices\MKL03Z4\include directory. The way I understand it, these are the functions that you use if you don’t want to use the predefined higher level functions and would rather update the registers and bits yourself.

It appears that the BWR and BRD uses the BME macros to set the register instead of a direct setting of the register. Not sure what the difference is.

Any ideas?

Thanks,

Sara

Sara Stout-Grandy, M.Eng., Ph.D., P.Eng.

Senior Hardware Designer

20 Angus Morton Dr., Bedford,

NS, Canada, B4B 0L9

902-450-1700, x278

0 Kudos
855 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Sara Stout-Grandy,

    Now let me tell you the details:

TPM_BWR_CONF_CSOO(tpmbase, 0);

TPM_WR_CONF_CSOO(tpmbase, 0);

All the above code is used to set the CSOO bit to a new value.

(1)TPM_WR_CONF_CSOO(tpmbase, 0);

#define TPM_WR_CONF_CSOO(base, value) (TPM_WR_CONF(base, (TPM_RD_CONF(base) & ~TPM_CONF_CSOO_MASK) | TPM_CONF_CSOO(value)))

#define TPM_WR_CONF(base, value) (TPM_CONF_REG(base) = (value))

Use normal C code to define the TPMx_CONF[CSOO] bit to a new value.

(2)TPM_WR_CONF_CSOO(tpmbase, 0);

#define TPM_BWR_CONF_CSOO(base, value) (BME_BFI32(&TPM_CONF_REG(base), ((uint32_t)(value) << TPM_CONF_CSOO_SHIFT), TPM_CONF_CSOO_SHIFT, TPM_CONF_CSOO_WIDTH))

#define BME_BFI32(addr, wdata, bit, width) (*(volatile uint32_t*)((uintptr_t)addr | BME_BFI_MASK(bit,width)) = wdata)

Use the BME code BFI function to define TPMx_CONF[CSOO] bit to a new value.

Normally, use BME code will caused less time than the Normal C code, you can run the KL25 BME code find the detail difference:

http://www.nxp.com/assets/downloads/data/en/lab-test-software/KL25_SC.exe 

Folder: kl25_sc_rev10\klxx-sc-baremetal\build\iar\LQRUG_bme_ex1

pastedImage_2.png

You can find, use the normally C, the same function will caused 0x1b systick counts, but use the BFI code, it only caused 0x16 sysick counts.

In conclusion, BME code save cpu execution time.

Wish it helps you!


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
854 Views
sarastout-grand
Contributor III

Thanks Kerry, that helps greatly! I now understand.

Sara

Sara Stout-Grandy, M.Eng., Ph.D., P.Eng.

Senior Hardware Designer

20 Angus Morton Dr., Bedford,

NS, Canada, B4B 0L9

902-450-1700, x278

0 Kudos
854 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Sara Stout-Grandy,

   OK, if your question is solved, please help to mark the correct answer, just to close this question.

  Thank you!


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos