Newbie looking for advice on odd behavior with pointer.

Hello community, First, I want to thank you for this great proyect, I found it specially good to learning c, embebed and OS in just one shoot. I started coding this week, I’m not sure if my approach is the right one but besides that when I’m trying to move it forward I’m finding an error that is driving me nuts. I’m on linux, using avr-gcc 4.8.1, an arduino duemillenova (at328p) and heap1, tacking serial example as starting point. Going to code itself, it is working fine as expected, when I un-coment that two lines at “MESSAGE[]”, I compile and load program as before, just that task “Pwm1” stop works while “Pwm2” still does fine. I can check Pwm1 switches and runs (printing that commented chars by uart) but it does’t set pins. I would appreciate any advice regarding this issue and whatever other you can share about my code, I’m self learning so any insight would be gladly welcome. Thank you. Andres.-
~~~~

include “FreeRTOS.h”

include “task.h”

include “uart/uart.h”

static const char *MESSAGE[] = { “CMD not found.”, // “PWM Not Found.”, // “PWM Updated.” }; typedef union { uint32t u32; uint8t u8[4]; } msg_t; typedef struct { uint8t com; uint8t bit; volatile uint8t *port; volatile uint8t *reg; volatile uint8_t *ocr; uint8_t vol; } pwmio_t; typedef struct { TaskHandlet h; volatile uint8t *tccra; uint8_t tcaset; volatile uint8_t *tccrb; uint8_t tcbset; pwmio_t pin[2]; } pwm_t; typedef pwmt *ppwmt; typedef struct { pwmt pwm[4]; } fumenbott; static fumenbot_t fumenbot = { { { NULL, &TCCR0A, ((1 << WGM01) | (1 << WGM00)), &TCCR0B, (1 << CS01), { {COM0A1, PORTD5, &PORTD, &DDRD, &OCR0A, 255}, {COM0B1, PORTD6, &PORTD, &DDRD, &OCR0B, 255} } }, { NULL, &TCCR2A, ((1 << WGM21) | (1 << WGM20)), &TCCR2B, (1 << CS21), { {COM2A1, PORTB3, &PORTB, &DDRB, &OCR2A, 255}, {COM2B1, PORTD3, &PORTD, &DDRD, &OCR2B, 255} } } } }; static uint8t FUMENBOTPWM = 2; void vUart(void *pvParameters); static TaskHandle_t xUart0 = NULL; void vPwm(void *pvParameters); void vApplicationStackOverflowHook(TaskHandlet xTask, signed char *pcTaskName); void vApplicationStackOverflowHook(TaskHandlet xTask, signed char *pcTaskName) { uart0_puts((const char *)pcTaskName); } char *fumenbot_handler(char *in); char *fumenbot_handler(char *in) { char **out; char a = in[0]; msg_t pkt; pkt.u8[0] = in[1] – ‘0’; pkt.u8[1] = in[2] – ‘0’; pkt.u8[2] = in[3] – ‘0’; pkt.u8[3] = in[4] – ‘0’; if (a == ‘p’) { if (pkt.u8[0] >= FUMENBOT_PWM) { out = (char **)MESSAGE[1]; } else { xTaskNotify(fumenbot.pwm[pkt.u8[0]].h, pkt.u32, eSetValueWithOverwrite); out = (char **)MESSAGE[2]; } } else { out = (char **)MESSAGE[0]; } return (char *)out; }

define UARTBAUDRATE 19200

char uart0buffer[16]; uint8t uart0bufferidx = 0; void vUart(void pvParameters) { uart0_puts(“Fumenbot v0.7nr”); for(;;) { if(uart0_available()) { char c = uart0_getc(); if(c == ‘r’) { uart0_puts(“nr”); uart0_puts(fumenbot_handler((char)uart0buffer)); uart0bufferidx = 0; uint8t i; for(i=0; i<16; i++) { uart0buffer[i] = ‘’; } uart0puts(“nrOKnr”); } else { uart0buffer[uart0bufferidx] = c; uart0putc(c); uart0bufferidx++; } } } vTaskDelete(NULL); } void vPwm(void *pvParameters) { ppwm_t pPwm = pvPortMalloc(sizeof(pwm_t)); pPwm = (ppwm_t)pvParameters; *(pPwm->tccra) |= pPwm->tcaset; *(pPwm->tccrb) |= pPwm->tcbset; msg_t msg; uint8_t i = 0; for(i=0;i<2;i++) { *(pPwm->pin[i].reg) |= (1<pin[i].bit); *(pPwm->pin[i].port) &= ~(1<pin[i].bit); } for(;;) { xTaskNotifyWait(0x00, 0xffffffff, (uint32_t *)&msg.u32, portMAX_DELAY); // uart0_putc(‘.’); if (msg.u8[2] < 1 || msg.u8[2] > 9) { *(pPwm->tccra) &= ~(1<pin[msg.u8[1]].com); *(pPwm->pin[msg.u8[1]].port) &= ~(1<pin[msg.u8[1]].bit); } else { *(pPwm->tccra) |= (1<pin[msg.u8[1]].com); *(pPwm->pin[msg.u8[1]].ocr) = pPwm->pin[msg.u8[1]].vol / msg.u8[2]; } // uart0_putc(‘-‘); taskYIELD(); } vTaskDelete(NULL); } int main( void ) { uart0init( UARTBAUDSELECTDOUBLESPEED(UARTBAUDRATE,FCPU) ); xTaskCreate(vUart, “Uart0”, 200, NULL, 1, &xUart0); xTaskCreate(vPwm, “Pwm0”, 100, &fumenbot.pwm[0], 2, &fumenbot.pwm[0].h); xTaskCreate(vPwm, “Pwm1”, 100, &fumenbot.pwm[1], 2, &fumenbot.pwm[1].h); vTaskStartScheduler(); return 0; } ~~~~

Newbie looking for advice on odd behavior with pointer.

Sorry for you post not showing up right away. It went into moderation – which its not supposed to do. First I would suggest that you update your stack overflow hook so that it can’t return – if there is a stack overflow you don’t want to try and recover. It doesn’t look like the MESSAGE structure is being used by the pwm tasks, but only the uart task. Are you sure the code works ok when you are not using FreeRTOS?