void __attribute__((naked)) isr_fault() { unsigned int sp, lr, psr, usp; sp = GET_SP (); psr = GET_PSR(); lr = GET_LR (); usp = GET_USP(); printk("\nKernel SP 0x%08x\n" "Stacked PSR 0x%08x\n" "Stacked PC 0x%08x\n" "Stacked LR 0x%08x\n" "Current LR 0x%08x\n" "Current PSR 0x%08x(vector number:%d)\n", sp, *(unsigned int *)(sp + 28), *(unsigned int *)(sp + 24), *(unsigned int *)(sp + 20), lr, psr, psr & 0x1ff); printk("\nUser SP 0x%08x\n" "Stacked PSR 0x%08x\n" "Stacked PC 0x%08x\n" "Stacked LR 0x%08x\n", usp, *(unsigned int *)(usp + 28), *(unsigned int *)(usp + 24), *(unsigned int *)(usp + 20)); printk("\ncurrent->sp 0x%08x\n" "current->base 0x%08x\n" "current->heap 0x%08x\n" "current->kernel 0x%08x\n" "current->kernel->sp 0x%08x\n" "current->state 0x%08x\n" "current->irqflag 0x%08x\n" "current->addr 0x%08x\n" "current 0x%08x\n" , current->mm.sp, current->mm.base, current->mm.heap, current->mm.kernel.base, current->mm.kernel.sp, current->state, current->irqflag, current->addr, current); printk("\ncurrent context\n"); unsigned int i; for (i = 0; i < NR_CONTEXT*2; i++) printk("[0x%08x] 0x%08x\n", usp + i*4, ((unsigned int *)usp)[i]); printk("\nSCB_ICSR 0x%08x\n" "SCB_CFSR 0x%08x\n" "SCB_HFSR 0x%08x\n" "SCB_MMFAR 0x%08x\n" "SCB_BFAR 0x%08x\n", SCB_ICSR, SCB_CFSR, SCB_HFSR, SCB_MMFAR, SCB_BFAR); /* led for debugging */ #ifdef LED_DEBUG SET_PORT_CLOCK(ENABLE, PORTD); SET_PORT_PIN(PORTD, 2, PIN_OUTPUT_50MHZ); unsigned int j; while (1) { PUT_PORT(PORTD, GET_PORT(PORTD) ^ 4); for (i = 100; i; i--) { for (j = 10; j; j--) { __asm__ __volatile__( "nop \n\t" "nop \n\t" "nop \n\t" "nop \n\t" "nop \n\t" "nop \n\t" "nop \n\t" "nop \n\t" "nop \n\t" "nop \n\t" ::: "memory"); } } } #endif }
void __attribute__((naked)) isr_fault() { /* disable interrupts */ /* save registers */ unsigned int sp, lr, psr, usp; sp = __get_sp(); psr = __get_psr(); lr = __get_lr(); usp = __get_usp(); debug(MSG_ERROR, "\nFault type: %x <%08x>\n" " (%x=Usage fault, %x=Bus fault, %x=Memory management fault)", SCB_SHCSR & 0xfff, SCB_SHCSR, USAGE_FAULT, BUS_FAULT, MM_FAULT); debug(MSG_ERROR, "Fault source: "); busfault(); usagefault(); printk("\nKernel Space\n"); print_kernel_status((unsigned int *)sp, lr, psr); printk("\nUser Space\n"); print_user_status((unsigned int *)usp); printk("\nTask Status\n"); print_task_status(current); printk("\nCurrent Context\n"); print_context((unsigned int *)usp); printk("\nSCB_ICSR 0x%08x\n" "SCB_CFSR 0x%08x\n" "SCB_HFSR 0x%08x\n" "SCB_MMFAR 0x%08x\n" "SCB_BFAR 0x%08x\n", SCB_ICSR, SCB_CFSR, SCB_HFSR, SCB_MMFAR, SCB_BFAR); /* led for debugging */ #ifdef LED_DEBUG SET_PORT_CLOCK(ENABLE, PORTD); SET_PORT_PIN(PORTD, 2, PIN_OUTPUT_50MHZ); unsigned int j; while (1) { PUT_PORT(PORTD, GET_PORT(PORTD) ^ 4); for (i = 100; i; i--) { for (j = 10; j; j--) { __asm__ __volatile__( "nop \n\t" "nop \n\t" "nop \n\t" "nop \n\t" "nop \n\t" "nop \n\t" "nop \n\t" "nop \n\t" "nop \n\t" "nop \n\t" ::: "memory"); } } } #endif while (1); /* restore registers */ /* enable interrupts */ }
int gpio_init(unsigned int index, unsigned int flags) { unsigned int port, pin, mode; int vector; unsigned int irqflag; vector = -1; mode = 0; port = calc_port(index); pin = calc_pin(index); spin_lock_irqsave(gpio_init_lock, irqflag); #if (SOC == stm32f1) SET_CLOCK_APB2(ENABLE, port + 2); #elif (SOC == stm32f4) SET_CLOCK_AHB1(ENABLE, port); #endif port = calc_port_addr(port); /* default */ #if (SOC == stm32f4) /* no pull-up, pull-down */ *(volatile unsigned int *)(port + 0xc) &= ~(3 << (pin * 2)); /* very high speed I/O output speed */ *(volatile unsigned int *)(port + 8) |= 3 << (pin * 2); /* push-pull output */ *(volatile unsigned int *)(port + 4) &= ~(1 << pin); #endif if (flags & GPIO_MODE_OUTPUT) { mode = PIN_OUTPUT; } else if (flags & GPIO_MODE_ALT) { mode = PIN_ALT; } else if (flags & GPIO_MODE_ANALOG) { mode = PIN_ANALOG; } else { /* GPIO_MODE_INPUT */ mode = PIN_INPUT; #if (SOC == stm32f1) mode |= PIN_FLOATING; #endif } if (flags & GPIO_CONF_OPENDRAIN) { #if (SOC == stm32f4) *(volatile unsigned int *)(port + 4) |= 1 << pin; #elif (SOC == stm32f1) mode &= ~(PIN_FLOATING); if (flags & GPIO_MODE_ALT) mode |= PIN_ALT_OPENDRAIN; else mode |= PIN_OPENDRAIN; #endif } else if (flags & GPIO_CONF_PULL_UP) { #if (SOC == stm32f4) *(volatile unsigned int *)(port + 0xc) |= 1 << (pin * 2); #elif (SOC == stm32f1) mode &= ~(PIN_FLOATING); mode |= PIN_PULL; #endif PUT_PORT_PIN(port, pin, 1); } else if (flags & GPIO_CONF_PULL_DOWN) { #if (SOC == stm32f4) *(volatile unsigned int *)(port + 0xc) |= 2 << (pin * 2); #elif (SOC == stm32f1) mode &= ~(PIN_FLOATING); mode |= PIN_PULL; #endif PUT_PORT_PIN(port, pin, 0); } SET_PORT_PIN(port, pin, mode); if (flags & (GPIO_INT_FALLING | GPIO_INT_RISING)) { #if (SOC == stm32f1) /* AFIO deals with Pin Remapping and EXTI */ SET_CLOCK_APB2(ENABLE, 0); #elif (SOC == stm32f4) /* exti <- syscfg <- apb2 */ SET_CLOCK_APB2(ENABLE, 14); #endif EXTI_IMR |= 1 << pin; if (flags & GPIO_INT_FALLING) EXTI_FTSR |= 1 << pin; if (flags & GPIO_INT_RISING) EXTI_RTSR |= 1 << pin; switch (pin) { case 0 ... 4: nvic_set(pin + 6, ON); vector = pin + 22; break; case 5 ... 9: nvic_set(23, ON); vector = 39; break; case 10 ... 15: nvic_set(40, ON); vector = 56; break; default: break; } link_exti_to_nvic(port, pin); }