rusefi/firmware/bootloader/src/main.cpp

65 lines
1.3 KiB
C++
Raw Normal View History

2017-05-30 15:38:51 -07:00
2018-09-16 19:25:17 -07:00
#include "global.h"
2017-05-30 15:38:51 -07:00
#include "hardware.h"
2019-03-29 06:11:13 -07:00
#include "efi_gpio.h"
2017-05-30 15:38:51 -07:00
#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */
#include <ch.h>
#include <hal.h>
#include <stm32f4xx.h>
#ifdef __cplusplus
}
#endif /* __cplusplus */
#include "dfu.h"
static bool wasCommand = false;
static THD_WORKING_AREA(waBootloaderSerial, 128);
static THD_FUNCTION(thBootloaderSerial, arg) {
(void)arg;
chRegSetThreadName("BootloaderSerial");
// start our DFU emulator
wasCommand = dfuStartLoop();
chThdExit(MSG_OK);
}
int main(void) {
// run ChibiOS
halInit();
chSysInit();
// set base pin configuration based on the board
2019-04-28 20:42:49 -07:00
setDefaultBasePins(PASS_CONFIG_PARAMETER_SIGNATURE);
/* at the moment SD card is not needed by bootloader
2017-05-30 15:38:51 -07:00
// set SD card configuration also
setDefaultSdCardParameters(PASS_ENGINE_PARAMETER_SIGNATURE);
*/
2017-05-30 15:38:51 -07:00
// start UART
getTsChannel()->start(38400); // TODO: should bootloader serial speed be configurable?
2017-05-30 15:38:51 -07:00
// start a serial port reader thread
thread_t *thrSerial = chThdCreateStatic(waBootloaderSerial, sizeof(waBootloaderSerial), NORMALPRIO, thBootloaderSerial, NULL);
// wait for the thread to finish
chThdWait(thrSerial);
#if 0
if (wasCommand) // abnormal termination of the bootloader thread
chSysHalt("Bootloader DFU FAIL");
#endif
// Run application
dfuJumpToApp(APPLICATION_ADDR);
return 0;
}