Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


Loading

cast from void pointer to pointer to struct results in hardware fault in FreeRtos Thread in thread argument

Posted by neicdech on June 14, 2018

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
include "board.h"
include "peripherals.h"
include "pin_mux.h"
include "clock_config.h"
include "MK22F51212.h"
include "fsldebugconsole.h"

typedef struct BLINKYparam { GPIOType* GPIO; uint8t Pinname; } BLINKYparamt;

enum PINS { PTD2 = 2, // LED_A };

include "FreeRTOS.h"
include "task.h"
include "semphr.h"
include "timers.h"
include "queue.h"

void airblinky(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 airblinky(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));
}

}

~~~


cast from void pointer to pointer to struct results in hardware fault in FreeRtos Thread in thread argument

Posted by rtel on June 14, 2018

If your question is "the pointer to BoardAblinky is corrupt inside the task airblinky" then that is because BoardAblinky is defined on the stack of main() - which no longer exists when the scheduler has been started. Either make BoardA_blinky static so it is not on the stack, or move the definition to be file scope.


cast from void pointer to pointer to struct results in hardware fault in FreeRtos Thread in thread argument

Posted by neicdech on June 14, 2018

yes, that actually the question. I tried your suggestion and it worked. thanks


[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]


Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS v10.2.1 is available for immediate download. MIT licensed, includes 64-bit RISC-V, NXP Cortex-M33 demo, Nuvoton Cortex-M23 demo & STM32H745 dual core (AMP) demo.

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


Careers

FreeRTOS and other embedded software careers at AWS.



FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Cadence Tensilica Cortes

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Mediatek

Renesas

RISC-V

SiFIve RISC-V

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner