Hi Giovanni,
Thanks for the code - I adapted to 2.6.1, and I still get timeouts, the output is a little odd, mostly timeouts, occasionally successfully reading 88:
Code: Select all
ChibiOS/RT Shell
ch> loop
Got 88.
Timeout
Timeout
Timeout
Timeout
Got 88.
Timeout
Timeout
Timeout
Timeout
Timeout
Got 88.
Timeout
Timeout
Timeout
Timeout
Timeout
Timeout
Timeout
Timeout
Timeout
Timeout
Timeout
Timeout
Timeout
Timeout
Timeout
Changing to -O3, I get mostly success, some timeouts:
Code: Select all
ch> loop
Got 88.
Got 88.
Got 88.
Got 88.
Got 88.
Got 88.
Got 88.
Timeout
Got 88.
Got 88.
Got 88.
Got 88.
Got 88.
Got 88.
Got 88.
Got 88.
Got 88.
Timeout
Got 88.
Got 88.
Got 88.
Got 88.
Here's the code in case I didn't adapt correctly, I used this in the fairly standard project I was using for the one-wire and my original loopback test, which I attached in the zip before. It's based on the disco F4 demo with USB shell, but with debug enabled:
Code: Select all
#include "ch.h"
#include "hal.h"
#include "chprintf.h"
#include "shell.h"
#include "usbcfg.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>
/* Virtual serial port over USB.*/
SerialUSBDriver SDU1;
#define SHELL_WA_SIZE THD_WA_SIZE(2048)
static void cmd_loop(BaseSequentialStream *chp, int argc, char *argv[]) {
EventListener el;
(void)argv;
if (argc > 0) {
chprintf(chp, "Usage: loop\r\n");
return;
}
chEvtRegister(&((BaseAsynchronousChannel *)chp)->event, &el, 0);
while (chnGetTimeout((BaseAsynchronousChannel *)chp,
TIME_IMMEDIATE) == Q_TIMEOUT) {
msg_t r;
flagsmask_t flags;
sdPut(&SD2, 'X');
r = sdGetTimeout(&SD2, MS2ST(100));
flags = chEvtGetAndClearFlags(&el);
if ((flags & (SD_PARITY_ERROR | SD_FRAMING_ERROR |
SD_OVERRUN_ERROR | SD_NOISE_ERROR |
SD_BREAK_DETECTED)) != 0)
chprintf(chp, "Error %4x.\r\n", flags);
if (Q_TIMEOUT == r)
chprintf(chp, "Timeout\r\n", r);
else
chprintf(chp, "Got %d.\r\n", r);
chThdSleepMilliseconds(100);
}
chprintf(chp, "Done\r\n");
chEvtUnregister(&((BaseAsynchronousChannel *)chp)->event, &el);
}
static const ShellCommand commands[] = {
{"loop", cmd_loop},
{NULL, NULL}
};
static const ShellConfig shell_cfg1 = {
(BaseSequentialStream *)&SDU1,
commands
};
/*===========================================================================*/
/* Initialization and main thread. */
/*===========================================================================*/
/*
* 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();
/*
* Shell manager initialization.
*/
shellInit();
/*
* Initializes a serial-over-USB CDC driver.
*/
sduObjectInit(&SDU1);
sduStart(&SDU1, &serusbcfg);
/*
* Activates the USB driver and then the USB bus pull-up on D+.
* Note, a delay is inserted in order to not have to disconnect the cable
* after a reset.
*/
usbDisconnectBus(serusbcfg.usbp);
chThdSleepMilliseconds(1000);
usbStart(serusbcfg.usbp, &usbcfg);
usbConnectBus(serusbcfg.usbp);
/*
* Activates the serial driver 2 using the driver default configuration.
* PA2(TX) and PA3(RX) are routed to USART2.
*/
sdStart(&SD2, NULL);
palSetPadMode(GPIOA, 2, PAL_MODE_ALTERNATE(7));
palSetPadMode(GPIOA, 3, PAL_MODE_ALTERNATE(7));
/*
* Normal main() thread activity, in this demo it just performs
* a shell respawn upon its termination.
*/
while (TRUE) {
if (!shelltp) {
if (SDU1.config->usbp->state == USB_ACTIVE) {
/* Spawns a new shell.*/
shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO);
}
}
else {
/* If the previous shell exited.*/
if (chThdTerminated(shelltp)) {
/* Recovers memory of the previous shell.*/
chThdRelease(shelltp);
shelltp = NULL;
}
}
chThdSleepMilliseconds(500);
}
}