SDK functions always require register base address 🥴

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

SDK functions always require register base address 🥴

1,039 Views
danielholala
Senior Contributor II

Hi there,

for quite some time I've been wondering why most of the SDK functions require the register base address of a module.I find this cumbersome.

Example:

  • SCTIMER_Init ( SCT_Type * base, const sctimer_config_t * config) 
  • FLEXCOMM_Init (void *base, FLEXCOMM_PERIPH_T periph)

It would be much nicer if I just had to enter the index of the module instance or 0 if the module has only one instance.

Particularly as FLEXCOMM_Init()  iterates over base addresses of all module instances in order to find the index. That's basically 🥴

Why don't you design a more user friendly API?

 

0 Kudos
Reply
2 Replies

1,026 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

Your issue is related with programming style and sdk architecture.

for example, for USART_Init(), we define first parameter as below for USART1-2

USART_Init(USART0, &config, kCLOCK_Flexcomm0);

USART_Init(USART1, &config, kCLOCK_Flexcomm1);

USART_Init(USART2, &config, kCLOCK_Flexcomm2);

This is clear for programmer write and read.

 

 

 

0 Kudos
Reply

1,020 Views
danielholala
Senior Contributor II

Thanks for the example that nicely illustrates what I meant.

The function declaration is:

status_t USART_Init ( USART_Type * base,
const usart_config_t * config,
uint32_t srcClock_Hz )

 

A) Driver documentation incomplete?

I could not find any information in SDK API reference manual whether I have to initialize Flexcom before calling USART_Init().

I had to check the source code to figure that USART_Init() does indeed initialize Flexcom.

I think this fact should mentioned in the SDK documentation.

B) Specific information missing?

I assume that the clock frequencies configured in Clocks tool are available programmatically. However, I could not find a function to retrieve the correct value for srcClock. I assume that srcClock should be the value that I configured using the Clocks tool, i.e. FXCOM0_clock. I tried  CLOCK_GetFlexCommClkFreq(0) but that did not work, see here

C) Function signature 

The function signature requires the use of a register base address although the driver "knows" the base address (see fsl_flexcomm.c ). So why does every programmer have to enter it? The instance number would be more appropriate here in my opinion. Using the instance id (as in CLOCK_GetFlexCommClkFreq(0)) is a much clearer approach.

Thanks.

 

 

 

0 Kudos
Reply