Code: Select all
#include "ch.h"
#include "hal.h"
#include "test.h"
#include "spi.h"
#include "i2c.h"
#include "usbcfg.h"
#include "chprintf.h"
#include "shell.h"
#include "chthreads.h"
// testing rtc
#include "rtc.h"
#include "chrtclib.h"
#define usb_lld_connect_bus(usbp)
#define usb_lld_disconnect_bus(usbp)
/* Virtual serial port over USB.*/
SerialUSBDriver SDU1;
/*
blah, blah, blah, some functions
*/
#define SHELL_WA_SIZE THD_WA_SIZE(1024)
/*
blah, blah, blah, funcitons with shell commands
*/
static const ShellCommand shCmds[] = {
{"test", cmd_test},
{"helpme", cmd_help},
{"gyrodata", cmd_gyrodata},
{"magdata", cmd_magdata},
{"adjust", cmd_adjust},
{"nextsch", cmd_nextsch},
{"time", cmd_time},
{"free", cmd_mem},
{"reboot", cmd_reboot},
{NULL, NULL}
};
static const ShellConfig shCfg = {
(BaseSequentialStream *)&SDU1,
shCmds
};
/*
blah, blah, blah, some other irrelevant code
*/
int main(void) {
Thread *sh = NULL;
halInit();
chSysInit();
sduObjectInit(&SDU1);
sduStart(&SDU1, &serusbcfg);
usbDisconnectBus(serusbcfg.usbp);
chThdSleepMilliseconds(1000);
usbStart(serusbcfg.usbp, &usbcfg);
usbConnectBus(serusbcfg.usbp);
spiStart(&SPID1, &spi1cfg);
i2cStart(&I2CD1, &i2cconfig);
initGyro();
initAccel();
initMag();
shellInit();
chThdCreateStatic(waThreadBlink, sizeof(waThreadBlink), NORMALPRIO, ThreadBlink, NULL);
while (TRUE) {
if (!sh) {
sh = shellCreate(&shCfg, SHELL_WA_SIZE, NORMALPRIO);
}
else if (chThdTerminated(sh)) {
chThdRelease(sh);
sh = NULL;
}
chThdSleepMilliseconds(1000);
}
return 0; // never returns, lol
}
Somewhy, I am pretty sure that the bug is in my code. Please tell me where it might be. Also, this is unlikely to be an STM32-specific issue.