Ejemplo n.º 1
0
/* (Called from exc.S with global interrupts disabled.) */
void __error(int num) {
    nvic_globalirq_enable();
    usart_putstr(ERROR_USART, "\r\nexception: ");
    usart_putudec(ERROR_USART, num);
    usart_putc(ERROR_USART, '\n');
    usart_putc(ERROR_USART, '\r');
	for(;;);
    throb();
	
	/* Turn off peripheral interrupts */
    nvic_irq_disable_all();

    /* Turn off timers */
    timer_disable_all();

    /* Turn off ADC */
    adc_disable_all();

    /* Turn off all USARTs */
    usart_disable_all();

    /* Turn the USB interrupt back on so the bootloader keeps on functioning */
    nvic_irq_enable(NVIC_USB_HP_CAN_TX);
    nvic_irq_enable(NVIC_USB_LP_CAN_RX0);

    /* Reenable global interrupts */
    nvic_globalirq_enable();
    throb();
}
Ejemplo n.º 2
0
/**
 * @brief Print an error message on a UART upon a failed assertion
 *        and throb the error LED, if there is one defined.
 * @param file Source file of failed assertion
 * @param line Source line of failed assertion
 * @param exp String representation of failed assertion
 * @sideeffect Turns of all peripheral interrupts except USB.
 */
void _fail(const char* file, int line, const char* exp) {
    /* Initialize the error USART */
    gpio_set_mode(ERROR_TX_PORT, ERROR_TX_PIN, GPIO_AF_OUTPUT_PP);
    usart_init(ERROR_USART);
    usart_set_baud_rate(ERROR_USART, ERROR_USART_CLK_SPEED, ERROR_USART_BAUD);

    /* Print failed assert message */
    usart_putstr(ERROR_USART, "ERROR: FAILED ASSERT(");
    usart_putstr(ERROR_USART, exp);
    usart_putstr(ERROR_USART, "): ");
    usart_putstr(ERROR_USART, file);
    usart_putstr(ERROR_USART, ": ");
    usart_putudec(ERROR_USART, line);
    usart_putc(ERROR_USART, '\n');
    usart_putc(ERROR_USART, '\r');

    /* Error fade */
    __error();
}
Ejemplo n.º 3
0
// new common exception code
// TODO: we have task switching so if fault occures in task we can just remove task from queue
//
void __attribute__((noreturn)) __error(uint32_t num, uint32_t pc, uint32_t lr)
{

#ifdef DEBUG_BUILD
    static const char * const faults[] = {
        "", // 0 
        "", // 1
        "HardFault", // 2
        "MemManage fault", // 3 
        "BusFault", // 4 
        "UsageFault", // 5 
        "illegal Flash Write", // 6 
        "", // 7 
        "", // 8 
        "", // 9 
        "", // 10 
        "PureVirtual function call", // 11
        "failed to setup clock", // 12
        "exit from main()", // 13
        "", // 14
    };
#endif


        /* Turn off peripheral interrupts */
    __disable_irq();

    timer_disable_all(); // turn off all PWM

    if(is_bare_metal())  // bare metal build without bootloader should reboot to DFU after any fault
        board_set_rtc_register(DFU_RTC_SIGNATURE, RTC_SIGNATURE_REG);


    /* Turn the USB interrupt back on so "the reboot to bootloader" keeps on functioning */
    NVIC_EnableIRQ(OTG_HS_EP1_OUT_IRQn);
    NVIC_EnableIRQ(OTG_HS_EP1_IN_IRQn);
    NVIC_EnableIRQ(OTG_HS_EP1_IN_IRQn);
    NVIC_EnableIRQ(OTG_HS_IRQn);
    NVIC_EnableIRQ(OTG_FS_IRQn);

    __enable_irq();

    if(boardEmergencyHandler) boardEmergencyHandler(); // call emergency handler

#if 0
 #ifdef ERROR_USART
    usart_putstr(ERROR_USART, "\r\n!!! Exception: ");
  #ifdef DEBUG_BUILD
    usart_putstr(ERROR_USART, faults[num]);
  #else
    usart_putudec(ERROR_USART, num);
  #endif
    usart_putstr(ERROR_USART, " at ");
    usart_putudec(ERROR_USART, pc);
    usart_putstr(ERROR_USART, " lr ");
    usart_putudec(ERROR_USART, lr);
    usart_putc(ERROR_USART, '\n');
    usart_putc(ERROR_USART, '\r');
 #endif
#else
 #ifdef DEBUG_BUILD
    printf("\r\n!!! Exception: %s at %x LR=%x\n",faults[num], pc, lr);
 #else
    printf("\r\n!!! Exception: %d at %x LR=%x\n",num, pc, lr);
 #endif
#endif
    error_throb(num);
}