I am writing a simple blinking LED program in MCUXpresso with ksdk 2.4 and Amazon Freertos. I intended to create two instances of the same thread definition by passing a void pointer to my struct which contains the GPIO type and pin number to the thread and later typecast the void pointer to pointer to my structure. however, during debugging, i realised that the new pointer points to a completely different address from my struct data and it always causes a hardware fault. This is however a code which works very well in Kinetis Design studio. I will appreciate help in understanind this problem.
~~~
include <stdio.h>
include “board.h”
include “peripherals.h”
include “pin_mux.h”
include “clock_config.h”
include “MK22F51212.h”
include “fsldebugconsole.h”
typedef struct BLINKY
param {
GPIOType* GPIO;
uint8
t Pinname;
} BLINKY
paramt;
enum PINS {
PTD2 = 2, // LED_A
};
include “FreeRTOS.h”
include “task.h”
include “semphr.h”
include “timers.h”
include “queue.h”
void air
blinky(void* blinkyparameters) ;
define mask(x) ( uint32_t )( 1U << (x) )
int main(void) {
CLOCK_EnableClock(kCLOCK_PortD);
PORT_SetPinMux(PORTD,PTD2,kPORT_MuxAsGpio);
gpio_pin_config_t config = { kGPIO_DigitalOutput, 0 };
GPIO_PinInit(GPIOD, PTD2, &config);
BLINKY_param_t Board_A_blinky = {GPIOD,PTD2};
if (xTaskCreate(air_blinky, "air_blinky_A", 50, &Board_A_blinky, 2,
NULL) == errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY)
exit(-1);
vTaskStartScheduler();
while (1) {
}
return 0;
}
void air
blinky(void* blinkyparameters) {
BLINKY_param_t* LED = (BLINKY_param_t*) blinky_parameters;
TickType_t Lastwakeuptime = xTaskGetTickCount();
uint8_t Flash_Time = 100;
for (;;)
{
GPIO_PortToggle(LED->GPIO, mask(LED->Pin_name)); // on
vTaskDelayUntil(&Lastwakeuptime,((Flash_Time * configTICK_RATE_HZ) / (float) 1000));
GPIO_PortToggle(GPIOD, mask(PTD2)); // off
vTaskDelayUntil(&Lastwakeuptime,((Flash_Time * configTICK_RATE_HZ) / (float) 1000));
GPIO_PortToggle(GPIOD, mask(PTD2)); // on
vTaskDelayUntil(&Lastwakeuptime,((Flash_Time * configTICK_RATE_HZ) / (float) 1000));
GPIO_PortToggle(GPIOD, mask(PTD2)); // off
vTaskDelayUntil(&Lastwakeuptime,((2000 * configTICK_RATE_HZ) / (float) 1000));
}
}
~~~