Using ADC16_DRV_Init in MQX, KDS 3.1, KSDK 1.3

cancel
Showing results for 
Search instead for 
Did you mean: 

Using ADC16_DRV_Init in MQX, KDS 3.1, KSDK 1.3

Jump to solution
522 Views
wildhorsemusic
Contributor III

Hello,  I started with the dac_adc_demo application in C:\Freescale\KSDK_1.3.0\examples\frdmk64f\demo_apps.  I made a number of changes to the demo and everything worked great.  Once I got a comfort level with some of the workings of the ADC/DAC drivers, I moved parts of the code into an MQX project, since that is the end goal.

Now, I get Hard Fault's when I try to initialize members of the standard ADC structures in the fsl_adc16_driver.h.

I am using the same related code as was in the bare metal application.  The typedefs, structures and malloc's are all from the demo.  I'm sorry this is probably a basic question.

Can someone tell me why it doesn't work in the MQX project?

The relevant code is:

#include "fsl_adc16_driver.h"
#include "fsl_gpio_driver.h"
#include "gpio_pins.h"
// Application Included Files
#define LED_ON                  (0U)
#define LED_OFF                 (1U)
#define ON   (1U)
#define OFF   (0U)

/*
** ===================================================================
**     Callback    : Main_Task
**     Description : Task function entry.
**     Parameters  :
**       task_init_data - OS task parameter
**     Returns : Nothing
** ===================================================================
*/
adc16_converter_config_t *g_adcConfig;

void Main_Task(os_task_param_t task_init_data)
{
  /* Write your local variable definition here */
    g_adcConfig = (adc16_converter_config_t *)OSA_MemAlloc(sizeof(adc16_converter_config_t));

    GPIO_DRV_Init(NULL,ALERT);

    GPIO_DRV_Init(NULL, ledPins);
    GPIO_DRV_WritePinOutput(BOARD_GPIO_LED_RED, LED_ON);
    GPIO_DRV_WritePinOutput(BOARD_GPIO_LED_GREEN, LED_ON);
    GPIO_DRV_WritePinOutput(BOARD_GPIO_LED_BLUE, LED_ON);

    g_adcConfigs->clkDividerMode = kAdc16ClkDividerOf2;
    g_adcConfigs->lowPowerEnable = true;

#ifdef PEX_USE_RTOS
  while (1) {
#endif
    /* Write your code here ... */
   
    //demo_state_machine(); // User menu, viewable through serial terminal
   
    OSA_TimeDelay(10);               
#ifdef PEX_USE_RTOS  
  }
#endif   
}

==========================================================================

I was able to get it to work by changing the declaration, malloc & assignments to:

adc16_converter_config_t tadcConfig;

adc16_converter_config_t *adcConfig = OSA_MemAlloc(sizeof(adc16_converter_config_t));

adcConfig = &tadcConfig;

But it doesn't explain why it didn't work before.

Thanks!

0 Kudos
1 Solution
60 Views
wildhorsemusic
Contributor III

After researching the a little further, I determined that the issue is an MQX configuration issue.  MQX malloc has some good information that lead me to the conclusion that my problem was in configuring MQX.  By default, it is configured as MQX_Lite.  MQX Lite uses static memory allocation by default.  If you want to use the RTCS TCP/IP stack, MFS file system, dynamic memory allocation, or some of the advanced features of MQX RTOS, use MQX Standard. see: How To: Create an MQX RTOS for KSDK project with Processor Expert in Kinetis Design Studio IDE .

Thanks to the NXP team and this expert community!

View solution in original post

0 Kudos
3 Replies
61 Views
wildhorsemusic
Contributor III

After researching the a little further, I determined that the issue is an MQX configuration issue.  MQX malloc has some good information that lead me to the conclusion that my problem was in configuring MQX.  By default, it is configured as MQX_Lite.  MQX Lite uses static memory allocation by default.  If you want to use the RTCS TCP/IP stack, MFS file system, dynamic memory allocation, or some of the advanced features of MQX RTOS, use MQX Standard. see: How To: Create an MQX RTOS for KSDK project with Processor Expert in Kinetis Design Studio IDE .

Thanks to the NXP team and this expert community!

View solution in original post

0 Kudos
60 Views
isaacavila
NXP Employee
NXP Employee

Hello Duane,

In fact, you should validate that pointer was allocated correctly in order to avoid this kind of issues, you can add this part:

g_adcConfig = (adc16_converter_config_t *)OSA_MemAlloc(sizeof(adc16_converter_config_t));

if (NULL == g_adcConfig) {

  //Print any error message

}

This way you can identify allocation problems faster.

I hope this can help you!

Best regards,

Isaac

60 Views
wildhorsemusic
Contributor III

Thank you, Isaac!

0 Kudos