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:
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?
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.
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 )
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.
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.
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.