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!