I have the following code in the main:
**********************************************************************************************
/*
* 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);
}
**********************************************************************************************
why usb not work (windows does not recognize usb) if i move that code in a thread:
**********************************************************************************************
static WORKING_AREA(myThreadWorkingArea, 1024);
static msg_t myThread(void *arg) {
while (TRUE) {
palSetPad(GPIOD, GPIOD_LED6);
if (!shelltp) {
if (SDU1.config->usbp->state == USB_ACTIVE) {
shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO);
}
}
else {
if (chThdTerminated(shelltp)) {
chThdRelease(shelltp);
shelltp = NULL;
}
}
chThdSleepMilliseconds(500);
}
}
(void)chThdCreateStatic(myThreadWorkingArea, sizeof(myThreadWorkingArea),
NORMALPRIO, myThread, NULL);
**********************************************************************************************
usb shell spawn
Moderator: RoccoMarco
Re: usb shell spawn
I checked that in the thread this condition:
if (SDU1.config->usbp->state == USB_ACTIVE)
is not satisfied
if (SDU1.config->usbp->state == USB_ACTIVE)
is not satisfied
Re: usb shell spawn
1. What board are you using?
2. On the stm32f4 discovery, be sure you plug the usb cable into the OTHER usb
port. The plug you use to load programs and debug through is not connected
to the stm32f4, you need to connect to the plug on the bottom of the bourd next
to the audio jack.
-John Scott
2. On the stm32f4 discovery, be sure you plug the usb cable into the OTHER usb
port. The plug you use to load programs and debug through is not connected
to the stm32f4, you need to connect to the plug on the bottom of the bourd next
to the audio jack.
-John Scott
Re: usb shell spawn
I'm beginning to think seriously about the presence of a bug in the operating system

- Giovanni
- Site Admin
- Posts: 14892
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 996 times
Re: usb shell spawn
I don't see problems with that code, so the problem is probably elsewhere.
If you find a bug please open a ticket.
Giovanni
If you find a bug please open a ticket.
Giovanni
Re: usb shell spawn
for completeness place the complete code
i call start_USB_communication() from main thread
start_USB_communication() and myThread have the same code.
in start_USB_communication usb function, in myThread no
Code: Select all
#include "ch.h"
#include "hal.h"
#include "chprintf.h"
#include "shell.h"
#include "lis302dl.h"
#include "usbcfg.h"
#define SHELL_WA_SIZE THD_WA_SIZE(2048)
#define TEST_WA_SIZE THD_WA_SIZE(256)
static void cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) {
size_t n, size;
(void)argv;
if (argc > 0) {
chprintf(chp, "Usage: mem\r\n");
return;
}
n = chHeapStatus(NULL, &size);
chprintf(chp, "core free memory : %u bytes\r\n", chCoreStatus());
chprintf(chp, "heap fragments : %u\r\n", n);
chprintf(chp, "heap free total : %u bytes\r\n", size);
}
static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
static const char *states[] = {THD_STATE_NAMES};
Thread *tp;
(void)argv;
if (argc > 0) {
chprintf(chp, "Usage: threads\r\n");
return;
}
chprintf(chp, " addr stack prio refs state time\r\n");
tp = chRegFirstThread();
do {
chprintf(chp, "%.8lx %.8lx %4lu %4lu %9s %lu\r\n",
(uint32_t)tp, (uint32_t)tp->p_ctx.r13,
(uint32_t)tp->p_prio, (uint32_t)(tp->p_refs - 1),
states[tp->p_state], (uint32_t)tp->p_time);
tp = chRegNextThread(tp);
} while (tp != NULL);
}
/*
static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) {
Thread *tp;
(void)argv;
if (argc > 0) {
chprintf(chp, "Usage: test\r\n");
return;
}
tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriority(),
TestThread, chp);
if (tp == NULL) {
chprintf(chp, "out of memory\r\n");
return;
}
chThdWait(tp);
}
*/
/* Virtual serial port over USB.*/
SerialUSBDriver SDU1;
static const ShellCommand commands[] = {
{"mem", cmd_mem},
{"threads", cmd_threads},
//{"test", cmd_test},
{NULL, NULL}
};
static const ShellConfig shell_cfg1 = {
(BaseSequentialStream *)&SDU1,
commands
};
static WORKING_AREA(myThreadWorkingArea, 1024);
static msg_t myThread(void *arg) {
/*Thread *shelltp = NULL;
shellInit();
sduObjectInit(&SDU1);
sduStart(&SDU1, &serusbcfg);
usbDisconnectBus(serusbcfg.usbp);
chThdSleepMilliseconds(1000);
usbStart(serusbcfg.usbp, &usbcfg);
usbConnectBus(serusbcfg.usbp);
while (TRUE) {
if (!shelltp) {
if (SDU1.config->usbp->state == USB_ACTIVE) {
palSetPad(GPIOD, GPIOD_LED6);
shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO);
}
}
else {
if (chThdTerminated(shelltp)) {
chThdRelease(shelltp);
shelltp = NULL;
}
}
chThdSleepMilliseconds(500);
}*/
}
void start_USB_communication(){
(void)chThdCreateStatic(myThreadWorkingArea, sizeof(myThreadWorkingArea),
NORMALPRIO, myThread, NULL);
Thread *shelltp = NULL;
shellInit();
sduObjectInit(&SDU1);
sduStart(&SDU1, &serusbcfg);
usbDisconnectBus(serusbcfg.usbp);
chThdSleepMilliseconds(1000);
usbStart(serusbcfg.usbp, &usbcfg);
usbConnectBus(serusbcfg.usbp);
//sdStart(&SD2, NULL);
//palSetPadMode(GPIOA, 2, PAL_MODE_ALTERNATE(7));
//palSetPadMode(GPIOA, 3, PAL_MODE_ALTERNATE(7));
while (TRUE) {
if (!shelltp) {
if (SDU1.config->usbp->state == USB_ACTIVE) {
palSetPad(GPIOD, GPIOD_LED6);
shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO);
}
}
else {
if (chThdTerminated(shelltp)) {
chThdRelease(shelltp);
shelltp = NULL;
}
}
chThdSleepMilliseconds(500);
}
}
i call start_USB_communication() from main thread
start_USB_communication() and myThread have the same code.
in start_USB_communication usb function, in myThread no
- Giovanni
- Site Admin
- Posts: 14892
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 996 times
Re: usb shell spawn
Code: Select all
int main(void) {
halInit();
chSysInit();
start_USB_communication();
while(TRUE){}
}