Exemple #1
0
void setupUSB (void) {
	setupDisconnectPin();
	disconnectUSB();

  /* turn on the USB clock */
#ifdef STM32F2
  pRCC->AHB1ENR |= RCC_AHB1ENR_OTGHSEN;
#else
  pRCC->APB1ENR |= RCC_APB1ENR_USB_CLK;
#endif

  /* initialize the usb application */
	connectUSB();
	usbAppInit();
}
Exemple #2
0
void setupUSB (void) {
  /* enable USB DISC Pin */
#ifdef STM32F2
#if !defined(BOARD_DiscoveryF4)
  pRCC->AHB1ENR |= RCC_AHB1ENR_USB;


	GPIO_TypeDef *p = (GPIO_TypeDef *)USB_DISC_BANK;
  /* set to output */
  p->MODER = 1 << (2*USB_DISC);
  /* Configure pins speed to 100 MHz */
  //p->OSPEEDR = 0xffffc00f; // 2 bit/port medium speed = %01
  /* Configure pins Output type to open drain */
  p->OTYPER  = 1 << (2*USB_DISC);
  /* No pull-up, pull-down for PEx pins */
  //p->PUPDR   = 0x00000000;
#endif
#else
  pRCC->APB2ENR |= RCC_APB2ENR_USB;
  /* Setup USB DISC pin as output open drain */
  SET_REG(USB_DISC_CR, (GET_REG(USB_DISC_CR) & USB_DISC_CR_MASK) | USB_DISC_CR_OUTPUT_OD); // ala42 just pull down external pull up
  //SET_REG(USB_DISC_CR, (GET_REG(USB_DISC_CR) & USB_DISC_CR_MASK) | USB_DISC_CR_OUTPUT_PP); // ala42 actively pull up USBDP
#endif

	disconnectUSB();

  /* turn on the USB clock */
#ifdef STM32F2
  pRCC->AHB1ENR |= RCC_AHB1ENR_OTGHSEN;
#else
  pRCC->APB1ENR |= RCC_APB1ENR_USB_CLK;
#endif

  /* initialize the usb application */
	connectUSB();
	usbAppInit();
}
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    // Register QtKeypadBridge for the virtual keyboard functionality
    ui->keypadWidget->installEventFilter(&qt_keypad_bridge);
    ui->lcdView->installEventFilter(&qt_keypad_bridge);

    //Emu -> GUI (QueuedConnection as they're different threads)
    connect(&emu, SIGNAL(serialChar(char)), this, SLOT(serialChar(char)), Qt::QueuedConnection);
    connect(&emu, SIGNAL(debugStr(QString)), this, SLOT(debugStr(QString))); //Not queued connection as it may cause a hang
    connect(&emu, SIGNAL(speedChanged(double)), this, SLOT(showSpeed(double)), Qt::QueuedConnection);
    connect(&emu, SIGNAL(statusMsg(QString)), ui->statusbar, SLOT(showMessage(QString)), Qt::QueuedConnection);
    connect(&emu, SIGNAL(turboModeChanged(bool)), ui->buttonSpeed, SLOT(setChecked(bool)), Qt::QueuedConnection);
    connect(&emu, SIGNAL(usblinkChanged(bool)), this, SLOT(usblinkChanged(bool)), Qt::QueuedConnection);

    //Menu "Emulator"
    connect(ui->buttonReset, SIGNAL(clicked(bool)), &emu, SLOT(reset()));
    connect(ui->actionReset, SIGNAL(triggered()), &emu, SLOT(reset()));
    connect(ui->actionRestart, SIGNAL(triggered()), this, SLOT(restart()));
    connect(ui->actionDebugger, SIGNAL(triggered()), &emu, SLOT(enterDebugger()));
    connect(ui->buttonPause, SIGNAL(clicked(bool)), &emu, SLOT(setPaused(bool)));
    connect(ui->buttonPause, SIGNAL(clicked(bool)), ui->actionPause, SLOT(setChecked(bool)));
    connect(ui->actionPause, SIGNAL(toggled(bool)), &emu, SLOT(setPaused(bool)));
    connect(ui->actionPause, SIGNAL(toggled(bool)), ui->buttonPause, SLOT(setChecked(bool)));
    connect(ui->buttonSpeed, SIGNAL(clicked(bool)), &emu, SLOT(setTurboMode(bool)));
    QShortcut *shortcut = new QShortcut(QKeySequence(Qt::Key_F11), this);
    shortcut->setAutoRepeat(false);
    connect(shortcut, SIGNAL(activated()), &emu, SLOT(toggleTurbo()));

    //Menu "Tools"
    connect(ui->buttonScreenshot, SIGNAL(clicked()), this, SLOT(screenshot()));
    connect(ui->actionScreenshot, SIGNAL(triggered()), this, SLOT(screenshot()));
    connect(ui->actionConnect, SIGNAL(triggered()), this, SLOT(connectUSB()));
    connect(ui->buttonUSB, SIGNAL(clicked(bool)), this, SLOT(connectUSB()));
    connect(ui->actionXModem, SIGNAL(triggered()), this, SLOT(xmodemSend()));
    ui->actionConnect->setShortcut(QKeySequence(Qt::Key_F10));
    ui->actionConnect->setAutoRepeat(false);

    //Menu "Flash"
    connect(ui->actionSave, SIGNAL(triggered()), this, SLOT(saveFlash()));
    connect(ui->actionCreate_flash, SIGNAL(triggered()), this, SLOT(createFlash()));

    //Debugging
    connect(ui->lineEdit, SIGNAL(returnPressed()), this, SLOT(debugCommand()));

    //File transfer
    connect(ui->refreshButton, SIGNAL(clicked(bool)), this, SLOT(reload_filebrowser()));
    connect(this, SIGNAL(usblink_progress_changed(int)), this, SLOT(changeProgress(int)), Qt::QueuedConnection);

    //Settings
    connect(ui->checkDebugger, SIGNAL(toggled(bool)), this, SLOT(setDebuggerOnStartup(bool)));
    connect(ui->checkWarning, SIGNAL(toggled(bool)), this, SLOT(setDebuggerOnWarning(bool)));
    connect(ui->uiDocks, SIGNAL(toggled(bool)), this, SLOT(setUIMode(bool)));
    connect(ui->checkAutostart, SIGNAL(toggled(bool)), this, SLOT(setAutostart(bool)));
    connect(ui->fileBoot1, SIGNAL(pressed()), this, SLOT(selectBoot1()));
    connect(ui->fileFlash, SIGNAL(pressed()), this, SLOT(selectFlash()));
    connect(ui->pathTransfer, SIGNAL(textEdited(QString)), this, SLOT(setUSBPath(QString)));
    connect(ui->spinGDB, SIGNAL(valueChanged(int)), this, SLOT(setGDBPort(int)));
    connect(ui->spinRDBG, SIGNAL(valueChanged(int)), this, SLOT(setRDBGPort(int)));
    connect(ui->orderDiags, SIGNAL(toggled(bool)), this, SLOT(setBootOrder(bool)));

    //Set up monospace fonts
    QFont monospace = QFontDatabase::systemFont(QFontDatabase::FixedFont);
    ui->debugConsole->setFont(monospace);
    ui->serialConsole->setFont(monospace);

    qRegisterMetaType<QVector<int>>();

#ifdef Q_OS_ANDROID
    //On android the settings file is deleted everytime you update or uninstall,
    //so choose a better, safer, location
    QString path = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation);
    settings = new QSettings(path + "/nspire_emu.ini", QSettings::IniFormat);
#else
    settings = new QSettings();
#endif

    //Load settings
    setUIMode(settings->value("docksEnabled", true).toBool());
    restoreGeometry(settings->value("windowGeometry").toByteArray());
    restoreState(settings->value("windowState").toByteArray(), WindowStateVersion);
    selectBoot1(settings->value("boot1", "").toString());
    selectFlash(settings->value("flash", "").toString());
    setDebuggerOnStartup(settings->value("debugOnStart", false).toBool());
    setDebuggerOnWarning(settings->value("debugOnWarn", false).toBool());
    setUSBPath(settings->value("usbdir", QString("ndless")).toString());
    setGDBPort(settings->value("gdbPort", 3333).toUInt());
    setRDBGPort(settings->value("rdbgPort", 3334).toUInt());
    setBootOrder(false);

    bool autostart = settings->value("emuAutostart", false).toBool();
    setAutostart(autostart);
    if(emu.boot1 != "" && emu.flash != "" && autostart)
        emu.start();
    else
        ui->statusbar->showMessage(trUtf8("Start the emulation via Emulation->Restart."));

    #ifdef Q_OS_MAC
        QTimer::singleShot(50, [&] {dockVisibilityChanged(false);}); // Trigger dock update (after UI was shown)
    #endif
}
Exemple #4
0
int main() {
  systemReset(); // peripherals but not PC
  setupCLK();
  setupLED();
  setupBUTTON();

#ifdef STM32F2
	setupDisconnectPin();
	disconnectUSB();
#else
  setupUSB();
  setupFLASH();
#endif


  strobePin(LED_BANK,LED,STARTUP_BLINKS,BLINK_FAST);

#ifdef STM32F2
  // enter built in boot load if magic number found in RAM
	if(*START_BOOT_LOADER_MAGIC_ADDR == START_BOOT_LOADER_MAGIC) {
 	  connectUSB();
		*START_BOOT_LOADER_MAGIC_ADDR = 0;
    jumpToUser(BUILT_IN_BOOT_LOADER);
	}
#endif



#ifdef FASTSTART
  // for an unknown reason the loader process hangs if the button port is not read
	bool pinState = readPin(BUTTON_BANK, BUTTON);
#else

	bool buttonStatusHigh = TRUE;
	bool buttonStatusLow  = FALSE;
	for(int i=0; i<10; i++) {
		bool pinState = readPin(BUTTON_BANK, BUTTON);
		buttonStatusHigh = buttonStatusHigh && pinState;
		buttonStatusLow  = buttonStatusLow || pinState;
	}

  /* wait for host to upload program or halt bootloader */
  bool no_user_jump = (!checkUserCode(USER_CODE_FLASH) && !checkUserCode(USER_CODE_RAM))
        								|| buttonStatusHigh;
  int delay_count = 0;


  while ((delay_count++ < BOOTLOADER_WAIT) || no_user_jump) {
    strobePin(LED_BANK,LED,1,BLINK_SLOW);

  #ifndef STM32F2
    if (dfuUploadStarted()) {
      dfuFinishUpload(); // systemHardReset from DFU once done
    }
  #endif
  }
#endif

	if (checkUserCode(USER_CODE_RAM)) {
    jumpToUser(USER_CODE_RAM);
  } else if (checkUserCode(USER_CODE_FLASH)) {
    jumpToUser(USER_CODE_FLASH);
  } else {
    // some sort of fault occurred, hard reset
    strobePin(LED_BANK,LED,5,BLINK_FAST);
    systemHardReset();
  }

  return 0;               /* can't happen, but placate the compiler */
}