I wrote a simple program to test queues on STM32F4-Discovery with Chibios 2.6.3. In the first thread I add to the queue an element (a letter from A to F). In the second thread I take element of the queue and I display it using Chprintf. In addition, in the first thread I also toggle the LED.
The program works well for a few minutes and then freezes and pops up an error "stack overflow". I have increased the size of all possible stacks, but it did not help.
I have set all the debugging options as in the document: http://www.chibios.org/dokuwiki/doku.ph ... ebug_guide
Does anyone know what is wrong in my program?
Code: Select all
/*
ChibiOS/RT - Copyright (C) 2006-2013 Giovanni Di Sirio
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "ch.h"
#include "hal.h"
#include "chprintf.h"
#define PORT_IDLE_THREAD_STACK_SIZE 0x0400
static uint8_t queueBuffer[20];
static INPUTQUEUE_DECL(inputQueueTest, &queueBuffer, 2000, NULL, NULL);
const SerialConfig sd2_config =
{
// SerialConfig for STM32 platforms
921600, // bit rate
0, // CR1 register settings
0, // CR2 register settings
0, // CR3 register settings
};
static WORKING_AREA(waThread1, 16000);
static msg_t HeartBeatThread(void *arg) {
(void)arg;
chRegSetThreadName("LED_HEARTBEAT");
CANRxFrame rxmsg1;
static int i = 0;
while (TRUE)
{
palSetPad(GPIOD, GPIOD_LED3);
chThdSleepMilliseconds(100);
palClearPad(GPIOD, GPIOD_LED3);
chThdSleepMilliseconds(100);
palSetPad(GPIOD, GPIOD_LED3);
chThdSleepMilliseconds(100);
palClearPad(GPIOD, GPIOD_LED3);
chThdSleepMilliseconds(700);
chSysLock();
int pull = chIQPutI(&inputQueueTest, 'A' + i);
chSysUnlock();
if(pull == Q_OK)
{
chprintf((BaseSequentialStream*)&SD2, "put ok\n");
}
if(pull == Q_FULL)
{
chprintf((BaseSequentialStream*)&SD2, "put full\n");
}
i++;
if (i == 6)
{
i = 0;
}
}
}
static WORKING_AREA(testQueue_wa, 8192);
static msg_t testQueue(void *arg)
{
(void)arg;
while(TRUE)
{
int Element = chIQGetTimeout(&inputQueueTest, MS2ST(200));
if(Element == Q_TIMEOUT)
{
chprintf((BaseSequentialStream*)&SD2, "TIMEOUT\n");
}
else if (Element == Q_RESET)
{
chprintf((BaseSequentialStream*)&SD2, "RESET\n");
}
else
{
chprintf((BaseSequentialStream*)&SD2, "element is %c\n", Element);
}
}
}
/*
* Application entry point.
*/
int main(void) {
/*
* System initializations.
* - HAL initialization, this also initializes the configured device drivers
* and performs the board-specific initializations.
* - Kernel initialization, the main() function becomes a thread and the
* RTOS is active.
*/
halInit();
chSysInit();
chIQInit(&inputQueueTest, (uint8_t *)&queueBuffer, 2000, NULL, NULL);
/*
* Activates the serial driver 2 using the driver default configuration.
* PA2(TX) and PA3(RX) are routed to USART2.
*/
sdStart(&SD2, &sd2_config);
palSetPadMode(GPIOA, 2, PAL_MODE_ALTERNATE(7));
palSetPadMode(GPIOA, 3, PAL_MODE_ALTERNATE(7));
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, HeartBeatThread, NULL);
chThdCreateStatic(testQueue_wa, sizeof(testQueue_wa), NORMALPRIO, testQueue, NULL);
while (TRUE)
{
chThdSleepMilliseconds(1000);
}
}