From 408fa52ec38b1861920f503257336fb426caf156 Mon Sep 17 00:00:00 2001 From: Alexandru Gagniuc Date: Mon, 8 Jul 2013 09:57:14 -0500 Subject: [PATCH] Global: Remove temporary backup files file.c~ (note the tilde at the end) are temporary backup files used by some editors. They are not needed. Signed-off-by: Alexandru Gagniuc --- examples/stm32/f1/lisa-m-1/can/can.c~ | 218 ---------------- examples/stm32/f1/lisa-m-2/can/can.c~ | 232 ------------------ .../stm32/f1/lisa-m-2/usart_dma/usart_dma.c~ | 86 ------- examples/stm32/f1/obldc-strip/can/can.c~ | 232 ------------------ examples/stm32/f1/obldc/can/can.c~ | 232 ------------------ .../stm32f4-discovery/usart_irq/usart_irq.c~ | 93 ------- 6 files changed, 1093 deletions(-) delete mode 100644 examples/stm32/f1/lisa-m-1/can/can.c~ delete mode 100644 examples/stm32/f1/lisa-m-2/can/can.c~ delete mode 100644 examples/stm32/f1/lisa-m-2/usart_dma/usart_dma.c~ delete mode 100644 examples/stm32/f1/obldc-strip/can/can.c~ delete mode 100644 examples/stm32/f1/obldc/can/can.c~ delete mode 100644 examples/stm32/f4/stm32f4-discovery/usart_irq/usart_irq.c~ diff --git a/examples/stm32/f1/lisa-m-1/can/can.c~ b/examples/stm32/f1/lisa-m-1/can/can.c~ deleted file mode 100644 index dc3bb07..0000000 --- a/examples/stm32/f1/lisa-m-1/can/can.c~ +++ /dev/null @@ -1,218 +0,0 @@ -/* - * This file is part of the libopencm3 project. - * - * Copyright (C) 2010 Thomas Otto - * Copyright (C) 2010 Piotr Esden-Tempski - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include -#include -#include -#include -#include - -struct can_tx_msg { - u32 std_id; - u32 ext_id; - u8 ide; - u8 rtr; - u8 dlc; - u8 data[8]; -}; - -struct can_rx_msg { - u32 std_id; - u32 ext_id; - u8 ide; - u8 rtr; - u8 dlc; - u8 data[8]; - u8 fmi; -}; - -struct can_tx_msg can_tx_msg; -struct can_rx_msg can_rx_msg; - -void gpio_setup(void) -{ - /* Enable GPIOA clock. */ - rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN); - - /* Enable GPIOB clock. */ - rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN); - - gpio_set(GPIOA, GPIO6); /* LED0 off */ - gpio_set(GPIOA, GPIO7); /* LED1 off */ - gpio_set(GPIOB, GPIO0); /* LED2 off */ - gpio_set(GPIOB, GPIO1); /* LED3 off */ - - /* Set GPIO6/7 (in GPIO port A) to 'output push-pull' for the LEDs. */ - gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ, - GPIO_CNF_OUTPUT_PUSHPULL, GPIO6); - gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ, - GPIO_CNF_OUTPUT_PUSHPULL, GPIO7); - - /* Set GPIO0/1 (in GPIO port B) to 'output push-pull' for the LEDs. */ - gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ, - GPIO_CNF_OUTPUT_PUSHPULL, GPIO0); - gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ, - GPIO_CNF_OUTPUT_PUSHPULL, GPIO1); -} - -void systick_setup(void) -{ - /* 72MHz / 8 => 9000000 counts per second */ - systick_set_clocksource(STK_CTRL_CLKSOURCE_AHB_DIV8); - - /* 9000000/9000 = 1000 overflows per second - every 1ms one interrupt */ - systick_set_reload(9000); - - systick_interrupt_enable(); - - /* Start counting. */ - systick_counter_enable(); -} - -void can_setup(void) -{ - /* Enable peripheral clocks. */ - rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_AFIOEN); - rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN); - rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_CANEN); - - AFIO_MAPR = AFIO_MAPR_CAN1_REMAP_PORTB; - - /* Configure CAN pin: RX (input pull-up). */ - gpio_set_mode(GPIOB, GPIO_MODE_INPUT, - GPIO_CNF_INPUT_PULL_UPDOWN, GPIO_CAN1_PB_RX); - gpio_set(GPIOB, GPIO_CAN1_PB_RX); - - /* Configure CAN pin: TX. */ - gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ, - GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_CAN1_PB_TX); - - /* NVIC setup. */ - nvic_enable_irq(NVIC_USB_LP_CAN_RX0_IRQ); - nvic_set_priority(NVIC_USB_LP_CAN_RX0_IRQ, 1); - - /* Reset CAN. */ - can_reset(CAN1); - - /* CAN cell init. */ - if (can_init(CAN1, - false, /* TTCM: Time triggered comm mode? */ - true, /* ABOM: Automatic bus-off management? */ - false, /* AWUM: Automatic wakeup mode? */ - false, /* NART: No automatic retransmission? */ - false, /* RFLM: Receive FIFO locked mode? */ - false, /* TXFP: Transmit FIFO priority? */ - CAN_BTR_SJW_1TQ, - CAN_BTR_TS1_3TQ, - CAN_BTR_TS2_4TQ, - 12)) /* BRP+1: Baud rate prescaler */ - { - gpio_set(GPIOA, GPIO6); /* LED0 off */ - gpio_set(GPIOA, GPIO7); /* LED1 off */ - gpio_set(GPIOB, GPIO0); /* LED2 off */ - gpio_clear(GPIOB, GPIO1); /* LED3 on */ - - /* Die because we failed to initialize. */ - while (1) - __asm__("nop"); - } - - /* CAN filter 0 init. */ - can_filter_id_mask_32bit_init(CAN1, - 0, /* Filter ID */ - 0, /* CAN ID */ - 0, /* CAN ID mask */ - 0, /* FIFO assignment (here: FIFO0) */ - true); /* Enable the filter. */ - - /* Enable CAN RX interrupt. */ - can_enable_irq(CAN1, CAN_IER_FMPIE0); -} - -void sys_tick_handler(void) -{ - static int temp32 = 0; - static u8 data[8] = {0, 1, 2, 0, 0, 0, 0, 0}; - - /* We call this handler every 1ms so 1000ms = 1s on/off. */ - if (++temp32 != 1000) - return; - - temp32 = 0; - - /* Transmit CAN frame. */ - data[0]++; - if (can_transmit(CAN1, - 0, /* (EX/ST)ID: CAN ID */ - false, /* IDE: CAN ID extended? */ - false, /* RTR: Request transmit? */ - 8, /* DLC: Data length */ - data) == -1) - { - gpio_set(GPIOA, GPIO6); /* LED0 off */ - gpio_set(GPIOA, GPIO7); /* LED1 off */ - gpio_clear(GPIOB, GPIO0); /* LED2 on */ - gpio_set(GPIOB, GPIO1); /* LED3 off */ - } -} - -void usb_lp_can_rx0_isr(void) -{ - u32 id, fmi; - bool ext, rtr; - u8 length, data[8]; - - can_receive(CAN1, 0, false, &id, &ext, &rtr, &fmi, &length, data); - - if (data[0] & 1) - gpio_clear(GPIOA, GPIO6); - else - gpio_set(GPIOA, GPIO6); - - if (data[0] & 2) - gpio_clear(GPIOA, GPIO7); - else - gpio_set(GPIOA, GPIO7); - - if (data[0] & 4) - gpio_clear(GPIOB, GPIO0); - else - gpio_set(GPIOB, GPIO0); - - if (data[0] & 8) - gpio_clear(GPIOB, GPIO1); - else - gpio_set(GPIOB, GPIO1); - - can_fifo_release(CAN1, 0); -} - -int main(void) -{ - rcc_clock_setup_in_hse_12mhz_out_72mhz(); - gpio_setup(); - can_setup(); - systick_setup(); - - while (1); /* Halt. */ - - return 0; -} diff --git a/examples/stm32/f1/lisa-m-2/can/can.c~ b/examples/stm32/f1/lisa-m-2/can/can.c~ deleted file mode 100644 index 41432b6..0000000 --- a/examples/stm32/f1/lisa-m-2/can/can.c~ +++ /dev/null @@ -1,232 +0,0 @@ -/* - * This file is part of the libopencm3 project. - * - * Copyright (C) 2010 Thomas Otto - * Copyright (C) 2010 Piotr Esden-Tempski - * - * This library is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library. If not, see . - */ - -#include -#include -#include -#include -#include -#include - -struct can_tx_msg { - u32 std_id; - u32 ext_id; - u8 ide; - u8 rtr; - u8 dlc; - u8 data[8]; -}; - -struct can_rx_msg { - u32 std_id; - u32 ext_id; - u8 ide; - u8 rtr; - u8 dlc; - u8 data[8]; - u8 fmi; -}; - -struct can_tx_msg can_tx_msg; -struct can_rx_msg can_rx_msg; - -void gpio_setup(void) -{ - /* Enable Alternate Function clock. */ - rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_AFIOEN); - - /* Enable GPIOA clock. */ - rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN); - - /* Enable GPIOB clock. */ - rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN); - - /* Enable GPIOC clock. */ - rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN); - - /* Preconfigure LEDs. */ - gpio_set(GPIOA, GPIO8); /* LED0 off */ - gpio_set(GPIOB, GPIO4); /* LED1 off */ - gpio_set(GPIOC, GPIO15); /* LED2 off */ - gpio_set(GPIOC, GPIO2); /* LED3 off */ - gpio_set(GPIOC, GPIO5); /* LED4 off */ - - /* Configure LED GPIOOs. */ - gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ, - GPIO_CNF_OUTPUT_PUSHPULL, GPIO8); - gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ, - GPIO_CNF_OUTPUT_PUSHPULL, GPIO4); - gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ, - GPIO_CNF_OUTPUT_PUSHPULL, GPIO15); - gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ, - GPIO_CNF_OUTPUT_PUSHPULL, GPIO2); - gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ, - GPIO_CNF_OUTPUT_PUSHPULL, GPIO5); - - /* Configure PB4 as GPIO. */ - AFIO_MAPR |= AFIO_MAPR_SWJ_CFG_FULL_SWJ_NO_JNTRST; - -} - -void systick_setup(void) -{ - /* 72MHz / 8 => 9000000 counts per second */ - systick_set_clocksource(STK_CTRL_CLKSOURCE_AHB_DIV8); - - /* 9000000/9000 = 1000 overflows per second - every 1ms one interrupt */ - systick_set_reload(9000); - - systick_interrupt_enable(); - - /* Start counting. */ - systick_counter_enable(); -} - -void can_setup(void) -{ - /* Enable peripheral clocks. */ - rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_AFIOEN); - rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN); - rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_CANEN); - - AFIO_MAPR = AFIO_MAPR_CAN1_REMAP_PORTB; - - /* Configure CAN pin: RX (input pull-up). */ - gpio_set_mode(GPIOB, GPIO_MODE_INPUT, - GPIO_CNF_INPUT_PULL_UPDOWN, GPIO_CAN1_PB_RX); - gpio_set(GPIOB, GPIO_CAN1_PB_RX); - - /* Configure CAN pin: TX. */ - gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ, - GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_CAN1_PB_TX); - - /* NVIC setup. */ - nvic_enable_irq(NVIC_USB_LP_CAN_RX0_IRQ); - nvic_set_priority(NVIC_USB_LP_CAN_RX0_IRQ, 1); - - /* Reset CAN. */ - can_reset(CAN1); - - /* CAN cell init. */ - if (can_init(CAN1, - false, /* TTCM: Time triggered comm mode? */ - true, /* ABOM: Automatic bus-off management? */ - false, /* AWUM: Automatic wakeup mode? */ - false, /* NART: No automatic retransmission? */ - false, /* RFLM: Receive FIFO locked mode? */ - false, /* TXFP: Transmit FIFO priority? */ - CAN_BTR_SJW_1TQ, - CAN_BTR_TS1_3TQ, - CAN_BTR_TS2_4TQ, - 12)) /* BRP+1: Baud rate prescaler */ - { - gpio_set(GPIOA, GPIO8); /* LED0 off */ - gpio_set(GPIOB, GPIO4); /* LED1 off */ - gpio_set(GPIOC, GPIO15); /* LED2 off */ - gpio_clear(GPIOC, GPIO2); /* LED3 on */ - gpio_set(GPIOC, GPIO5); /* LED4 off */ - - /* Die because we failed to initialize. */ - while (1) - __asm__("nop"); - } - - /* CAN filter 0 init. */ - can_filter_id_mask_32bit_init(CAN1, - 0, /* Filter ID */ - 0, /* CAN ID */ - 0, /* CAN ID mask */ - 0, /* FIFO assignment (here: FIFO0) */ - true); /* Enable the filter. */ - - /* Enable CAN RX interrupt. */ - can_enable_irq(CAN1, CAN_IER_FMPIE0); -} - -void sys_tick_handler(void) -{ - static int temp32 = 0; - static u8 data[8] = {0, 1, 2, 0, 0, 0, 0, 0}; - - /* We call this handler every 1ms so 1000ms = 1s on/off. */ - if (++temp32 != 1000) - return; - - temp32 = 0; - - /* Transmit CAN frame. */ - data[0]++; - if (can_transmit(CAN1, - 0, /* (EX/ST)ID: CAN ID */ - false, /* IDE: CAN ID extended? */ - false, /* RTR: Request transmit? */ - 8, /* DLC: Data length */ - data) == -1) - { - gpio_set(GPIOA, GPIO8); /* LED0 off */ - gpio_set(GPIOB, GPIO4); /* LED1 off */ - gpio_set(GPIOC, GPIO15); /* LED2 off */ - gpio_set(GPIOC, GPIO2); /* LED3 off */ - gpio_clear(GPIOC, GPIO5); /* LED4 on */ - } -} - -void usb_lp_can_rx0_isr(void) -{ - u32 id, fmi; - bool ext, rtr; - u8 length, data[8]; - - can_receive(CAN1, 0, false, &id, &ext, &rtr, &fmi, &length, data); - - if (data[0] & 1) - gpio_clear(GPIOA, GPIO8); - else - gpio_set(GPIOA, GPIO8); - - if (data[0] & 2) - gpio_clear(GPIOB, GPIO4); - else - gpio_set(GPIOB, GPIO4); - - if (data[0] & 4) - gpio_clear(GPIOC, GPIO15); - else - gpio_set(GPIOC, GPIO15); - - if (data[0] & 8) - gpio_clear(GPIOC, GPIO2); - else - gpio_set(GPIOC, GPIO2); - - can_fifo_release(CAN1, 0); -} - -int main(void) -{ - rcc_clock_setup_in_hse_12mhz_out_72mhz(); - gpio_setup(); - can_setup(); - systick_setup(); - - while (1); /* Halt. */ - - return 0; -} diff --git a/examples/stm32/f1/lisa-m-2/usart_dma/usart_dma.c~ b/examples/stm32/f1/lisa-m-2/usart_dma/usart_dma.c~ deleted file mode 100644 index 4422b55..0000000 --- a/examples/stm32/f1/lisa-m-2/usart_dma/usart_dma.c~ +++ /dev/null @@ -1,86 +0,0 @@ -/* - * This file is part of the libopencm3 project. - * - * Copyright (C) 2009 Uwe Hermann - * - * This library is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library. If not, see . - */ - -#include -#include -#include - -void clock_setup(void) -{ - rcc_clock_setup_in_hse_12mhz_out_72mhz(); - - /* Enable GPIOA, GPIOB, GPIOC clock. */ - rcc_peripheral_enable_clock(&RCC_APB2ENR, - RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPBEN | - RCC_APB2ENR_IOPCEN); - - /* Enable clocks for GPIO port B (for GPIO_USART3_TX) and USART3. */ - rcc_peripheral_enable_clock(&RCC_APB1ENR, - RCC_APB1ENR_USART2EN); -} - -void usart_setup(void) -{ - /* Setup GPIO pin GPIO_USART2_TX. */ - gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ, - GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART2_TX); - - /* Setup UART parameters. */ - usart_set_baudrate(USART2, 38400); - usart_set_databits(USART2, 8); - usart_set_stopbits(USART2, USART_STOPBITS_1); - usart_set_mode(USART2, USART_MODE_TX); - usart_set_parity(USART2, USART_PARITY_NONE); - usart_set_flow_control(USART2, USART_FLOWCONTROL_NONE); - - /* Finally enable the USART. */ - usart_enable(USART2); - -} - -void gpio_setup(void) -{ - /* Set GPIO8 (in GPIO port A) to 'output push-pull'. */ - gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ, - GPIO_CNF_OUTPUT_PUSHPULL, GPIO8); -} - -int main(void) -{ - int i, j = 0, c = 0; - - clock_setup(); - gpio_setup(); - usart_setup(); - - /* Blink the LED (PA8) on the board with every transmitted byte. */ - while (1) { - gpio_toggle(GPIOA, GPIO8); /* LED on/off */ - usart_send_blocking(USART2, c + '0'); /* USART2: Send byte. */ - c = (c == 9) ? 0 : c + 1; /* Increment c. */ - if ((j++ % 80) == 0) { /* Newline after line full. */ - usart_send_blocking(USART2, '\r'); - usart_send_blocking(USART2, '\n'); - } - for (i = 0; i < 800000; i++) /* Wait a bit. */ - __asm__("nop"); - } - - return 0; -} diff --git a/examples/stm32/f1/obldc-strip/can/can.c~ b/examples/stm32/f1/obldc-strip/can/can.c~ deleted file mode 100644 index 41432b6..0000000 --- a/examples/stm32/f1/obldc-strip/can/can.c~ +++ /dev/null @@ -1,232 +0,0 @@ -/* - * This file is part of the libopencm3 project. - * - * Copyright (C) 2010 Thomas Otto - * Copyright (C) 2010 Piotr Esden-Tempski - * - * This library is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library. If not, see . - */ - -#include -#include -#include -#include -#include -#include - -struct can_tx_msg { - u32 std_id; - u32 ext_id; - u8 ide; - u8 rtr; - u8 dlc; - u8 data[8]; -}; - -struct can_rx_msg { - u32 std_id; - u32 ext_id; - u8 ide; - u8 rtr; - u8 dlc; - u8 data[8]; - u8 fmi; -}; - -struct can_tx_msg can_tx_msg; -struct can_rx_msg can_rx_msg; - -void gpio_setup(void) -{ - /* Enable Alternate Function clock. */ - rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_AFIOEN); - - /* Enable GPIOA clock. */ - rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN); - - /* Enable GPIOB clock. */ - rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN); - - /* Enable GPIOC clock. */ - rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN); - - /* Preconfigure LEDs. */ - gpio_set(GPIOA, GPIO8); /* LED0 off */ - gpio_set(GPIOB, GPIO4); /* LED1 off */ - gpio_set(GPIOC, GPIO15); /* LED2 off */ - gpio_set(GPIOC, GPIO2); /* LED3 off */ - gpio_set(GPIOC, GPIO5); /* LED4 off */ - - /* Configure LED GPIOOs. */ - gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ, - GPIO_CNF_OUTPUT_PUSHPULL, GPIO8); - gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ, - GPIO_CNF_OUTPUT_PUSHPULL, GPIO4); - gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ, - GPIO_CNF_OUTPUT_PUSHPULL, GPIO15); - gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ, - GPIO_CNF_OUTPUT_PUSHPULL, GPIO2); - gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ, - GPIO_CNF_OUTPUT_PUSHPULL, GPIO5); - - /* Configure PB4 as GPIO. */ - AFIO_MAPR |= AFIO_MAPR_SWJ_CFG_FULL_SWJ_NO_JNTRST; - -} - -void systick_setup(void) -{ - /* 72MHz / 8 => 9000000 counts per second */ - systick_set_clocksource(STK_CTRL_CLKSOURCE_AHB_DIV8); - - /* 9000000/9000 = 1000 overflows per second - every 1ms one interrupt */ - systick_set_reload(9000); - - systick_interrupt_enable(); - - /* Start counting. */ - systick_counter_enable(); -} - -void can_setup(void) -{ - /* Enable peripheral clocks. */ - rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_AFIOEN); - rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN); - rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_CANEN); - - AFIO_MAPR = AFIO_MAPR_CAN1_REMAP_PORTB; - - /* Configure CAN pin: RX (input pull-up). */ - gpio_set_mode(GPIOB, GPIO_MODE_INPUT, - GPIO_CNF_INPUT_PULL_UPDOWN, GPIO_CAN1_PB_RX); - gpio_set(GPIOB, GPIO_CAN1_PB_RX); - - /* Configure CAN pin: TX. */ - gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ, - GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_CAN1_PB_TX); - - /* NVIC setup. */ - nvic_enable_irq(NVIC_USB_LP_CAN_RX0_IRQ); - nvic_set_priority(NVIC_USB_LP_CAN_RX0_IRQ, 1); - - /* Reset CAN. */ - can_reset(CAN1); - - /* CAN cell init. */ - if (can_init(CAN1, - false, /* TTCM: Time triggered comm mode? */ - true, /* ABOM: Automatic bus-off management? */ - false, /* AWUM: Automatic wakeup mode? */ - false, /* NART: No automatic retransmission? */ - false, /* RFLM: Receive FIFO locked mode? */ - false, /* TXFP: Transmit FIFO priority? */ - CAN_BTR_SJW_1TQ, - CAN_BTR_TS1_3TQ, - CAN_BTR_TS2_4TQ, - 12)) /* BRP+1: Baud rate prescaler */ - { - gpio_set(GPIOA, GPIO8); /* LED0 off */ - gpio_set(GPIOB, GPIO4); /* LED1 off */ - gpio_set(GPIOC, GPIO15); /* LED2 off */ - gpio_clear(GPIOC, GPIO2); /* LED3 on */ - gpio_set(GPIOC, GPIO5); /* LED4 off */ - - /* Die because we failed to initialize. */ - while (1) - __asm__("nop"); - } - - /* CAN filter 0 init. */ - can_filter_id_mask_32bit_init(CAN1, - 0, /* Filter ID */ - 0, /* CAN ID */ - 0, /* CAN ID mask */ - 0, /* FIFO assignment (here: FIFO0) */ - true); /* Enable the filter. */ - - /* Enable CAN RX interrupt. */ - can_enable_irq(CAN1, CAN_IER_FMPIE0); -} - -void sys_tick_handler(void) -{ - static int temp32 = 0; - static u8 data[8] = {0, 1, 2, 0, 0, 0, 0, 0}; - - /* We call this handler every 1ms so 1000ms = 1s on/off. */ - if (++temp32 != 1000) - return; - - temp32 = 0; - - /* Transmit CAN frame. */ - data[0]++; - if (can_transmit(CAN1, - 0, /* (EX/ST)ID: CAN ID */ - false, /* IDE: CAN ID extended? */ - false, /* RTR: Request transmit? */ - 8, /* DLC: Data length */ - data) == -1) - { - gpio_set(GPIOA, GPIO8); /* LED0 off */ - gpio_set(GPIOB, GPIO4); /* LED1 off */ - gpio_set(GPIOC, GPIO15); /* LED2 off */ - gpio_set(GPIOC, GPIO2); /* LED3 off */ - gpio_clear(GPIOC, GPIO5); /* LED4 on */ - } -} - -void usb_lp_can_rx0_isr(void) -{ - u32 id, fmi; - bool ext, rtr; - u8 length, data[8]; - - can_receive(CAN1, 0, false, &id, &ext, &rtr, &fmi, &length, data); - - if (data[0] & 1) - gpio_clear(GPIOA, GPIO8); - else - gpio_set(GPIOA, GPIO8); - - if (data[0] & 2) - gpio_clear(GPIOB, GPIO4); - else - gpio_set(GPIOB, GPIO4); - - if (data[0] & 4) - gpio_clear(GPIOC, GPIO15); - else - gpio_set(GPIOC, GPIO15); - - if (data[0] & 8) - gpio_clear(GPIOC, GPIO2); - else - gpio_set(GPIOC, GPIO2); - - can_fifo_release(CAN1, 0); -} - -int main(void) -{ - rcc_clock_setup_in_hse_12mhz_out_72mhz(); - gpio_setup(); - can_setup(); - systick_setup(); - - while (1); /* Halt. */ - - return 0; -} diff --git a/examples/stm32/f1/obldc/can/can.c~ b/examples/stm32/f1/obldc/can/can.c~ deleted file mode 100644 index 41432b6..0000000 --- a/examples/stm32/f1/obldc/can/can.c~ +++ /dev/null @@ -1,232 +0,0 @@ -/* - * This file is part of the libopencm3 project. - * - * Copyright (C) 2010 Thomas Otto - * Copyright (C) 2010 Piotr Esden-Tempski - * - * This library is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library. If not, see . - */ - -#include -#include -#include -#include -#include -#include - -struct can_tx_msg { - u32 std_id; - u32 ext_id; - u8 ide; - u8 rtr; - u8 dlc; - u8 data[8]; -}; - -struct can_rx_msg { - u32 std_id; - u32 ext_id; - u8 ide; - u8 rtr; - u8 dlc; - u8 data[8]; - u8 fmi; -}; - -struct can_tx_msg can_tx_msg; -struct can_rx_msg can_rx_msg; - -void gpio_setup(void) -{ - /* Enable Alternate Function clock. */ - rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_AFIOEN); - - /* Enable GPIOA clock. */ - rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN); - - /* Enable GPIOB clock. */ - rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN); - - /* Enable GPIOC clock. */ - rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN); - - /* Preconfigure LEDs. */ - gpio_set(GPIOA, GPIO8); /* LED0 off */ - gpio_set(GPIOB, GPIO4); /* LED1 off */ - gpio_set(GPIOC, GPIO15); /* LED2 off */ - gpio_set(GPIOC, GPIO2); /* LED3 off */ - gpio_set(GPIOC, GPIO5); /* LED4 off */ - - /* Configure LED GPIOOs. */ - gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ, - GPIO_CNF_OUTPUT_PUSHPULL, GPIO8); - gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ, - GPIO_CNF_OUTPUT_PUSHPULL, GPIO4); - gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ, - GPIO_CNF_OUTPUT_PUSHPULL, GPIO15); - gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ, - GPIO_CNF_OUTPUT_PUSHPULL, GPIO2); - gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ, - GPIO_CNF_OUTPUT_PUSHPULL, GPIO5); - - /* Configure PB4 as GPIO. */ - AFIO_MAPR |= AFIO_MAPR_SWJ_CFG_FULL_SWJ_NO_JNTRST; - -} - -void systick_setup(void) -{ - /* 72MHz / 8 => 9000000 counts per second */ - systick_set_clocksource(STK_CTRL_CLKSOURCE_AHB_DIV8); - - /* 9000000/9000 = 1000 overflows per second - every 1ms one interrupt */ - systick_set_reload(9000); - - systick_interrupt_enable(); - - /* Start counting. */ - systick_counter_enable(); -} - -void can_setup(void) -{ - /* Enable peripheral clocks. */ - rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_AFIOEN); - rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN); - rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_CANEN); - - AFIO_MAPR = AFIO_MAPR_CAN1_REMAP_PORTB; - - /* Configure CAN pin: RX (input pull-up). */ - gpio_set_mode(GPIOB, GPIO_MODE_INPUT, - GPIO_CNF_INPUT_PULL_UPDOWN, GPIO_CAN1_PB_RX); - gpio_set(GPIOB, GPIO_CAN1_PB_RX); - - /* Configure CAN pin: TX. */ - gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ, - GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_CAN1_PB_TX); - - /* NVIC setup. */ - nvic_enable_irq(NVIC_USB_LP_CAN_RX0_IRQ); - nvic_set_priority(NVIC_USB_LP_CAN_RX0_IRQ, 1); - - /* Reset CAN. */ - can_reset(CAN1); - - /* CAN cell init. */ - if (can_init(CAN1, - false, /* TTCM: Time triggered comm mode? */ - true, /* ABOM: Automatic bus-off management? */ - false, /* AWUM: Automatic wakeup mode? */ - false, /* NART: No automatic retransmission? */ - false, /* RFLM: Receive FIFO locked mode? */ - false, /* TXFP: Transmit FIFO priority? */ - CAN_BTR_SJW_1TQ, - CAN_BTR_TS1_3TQ, - CAN_BTR_TS2_4TQ, - 12)) /* BRP+1: Baud rate prescaler */ - { - gpio_set(GPIOA, GPIO8); /* LED0 off */ - gpio_set(GPIOB, GPIO4); /* LED1 off */ - gpio_set(GPIOC, GPIO15); /* LED2 off */ - gpio_clear(GPIOC, GPIO2); /* LED3 on */ - gpio_set(GPIOC, GPIO5); /* LED4 off */ - - /* Die because we failed to initialize. */ - while (1) - __asm__("nop"); - } - - /* CAN filter 0 init. */ - can_filter_id_mask_32bit_init(CAN1, - 0, /* Filter ID */ - 0, /* CAN ID */ - 0, /* CAN ID mask */ - 0, /* FIFO assignment (here: FIFO0) */ - true); /* Enable the filter. */ - - /* Enable CAN RX interrupt. */ - can_enable_irq(CAN1, CAN_IER_FMPIE0); -} - -void sys_tick_handler(void) -{ - static int temp32 = 0; - static u8 data[8] = {0, 1, 2, 0, 0, 0, 0, 0}; - - /* We call this handler every 1ms so 1000ms = 1s on/off. */ - if (++temp32 != 1000) - return; - - temp32 = 0; - - /* Transmit CAN frame. */ - data[0]++; - if (can_transmit(CAN1, - 0, /* (EX/ST)ID: CAN ID */ - false, /* IDE: CAN ID extended? */ - false, /* RTR: Request transmit? */ - 8, /* DLC: Data length */ - data) == -1) - { - gpio_set(GPIOA, GPIO8); /* LED0 off */ - gpio_set(GPIOB, GPIO4); /* LED1 off */ - gpio_set(GPIOC, GPIO15); /* LED2 off */ - gpio_set(GPIOC, GPIO2); /* LED3 off */ - gpio_clear(GPIOC, GPIO5); /* LED4 on */ - } -} - -void usb_lp_can_rx0_isr(void) -{ - u32 id, fmi; - bool ext, rtr; - u8 length, data[8]; - - can_receive(CAN1, 0, false, &id, &ext, &rtr, &fmi, &length, data); - - if (data[0] & 1) - gpio_clear(GPIOA, GPIO8); - else - gpio_set(GPIOA, GPIO8); - - if (data[0] & 2) - gpio_clear(GPIOB, GPIO4); - else - gpio_set(GPIOB, GPIO4); - - if (data[0] & 4) - gpio_clear(GPIOC, GPIO15); - else - gpio_set(GPIOC, GPIO15); - - if (data[0] & 8) - gpio_clear(GPIOC, GPIO2); - else - gpio_set(GPIOC, GPIO2); - - can_fifo_release(CAN1, 0); -} - -int main(void) -{ - rcc_clock_setup_in_hse_12mhz_out_72mhz(); - gpio_setup(); - can_setup(); - systick_setup(); - - while (1); /* Halt. */ - - return 0; -} diff --git a/examples/stm32/f4/stm32f4-discovery/usart_irq/usart_irq.c~ b/examples/stm32/f4/stm32f4-discovery/usart_irq/usart_irq.c~ deleted file mode 100644 index 5ae46d3..0000000 --- a/examples/stm32/f4/stm32f4-discovery/usart_irq/usart_irq.c~ +++ /dev/null @@ -1,93 +0,0 @@ -/* - * This file is part of the libopencm3 project. - * - * Copyright (C) 2009 Uwe Hermann - * Copyright (C) 2011 Stephen Caudle - * - * This library is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library. If not, see . - */ - -#include -#include -#include - -void clock_setup(void) -{ - /* Enable GPIOD clock for LED & USARTs. */ - rcc_peripheral_enable_clock(&RCC_AHB1ENR, RCC_AHB1ENR_IOPDEN); - rcc_peripheral_enable_clock(&RCC_AHB1ENR, RCC_AHB1ENR_IOPAEN); - - /* Enable clocks for USART2. */ - rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_USART2EN); -} - -void usart_setup(void) -{ - /* Setup USART2 parameters. */ - usart_set_baudrate(USART2, 38400); - usart_set_databits(USART2, 8); - usart_set_stopbits(USART2, USART_STOPBITS_1); - usart_set_mode(USART2, USART_MODE_TX); - usart_set_parity(USART2, USART_PARITY_NONE); - usart_set_flow_control(USART2, USART_FLOWCONTROL_NONE); - - /* Finally enable the USART. */ - usart_enable(USART2); -} - -void gpio_setup(void) -{ - /* Setup GPIO pin GPIO12 on GPIO port D for LED. */ - gpio_mode_setup(GPIOD, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO12); - - /* Setup GPIO pins for USART2 transmit. */ - gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO2); - - - /* Setup GPIO pins for USART2 receive. */ - gpio_mode_setup(GPIOA, GPIO_MODE_INPUT, GPIO_OTYPE_OD, GPIO3); - - /* Setup USART2 TX and RX pin as alternate function. */ - gpio_set_af(GPIOA, GPIO_AF7, GPIO2); - gpio_set_af(GPIOA, GPIO_AF7, GPIO3); -} - -int main(void) -{ - int i, j = 0, c = 0; - u16 in_ch = 0; - - clock_setup(); - gpio_setup(); - usart_setup(); - - /* Blink the LED (PD12) on the board with every transmitted byte. */ - while (1) { - gpio_toggle(GPIOD, GPIO12); /* LED on/off */ - usart_send_blocking(USART2, c + '0'); /* USART2: Send byte. */ - c = (c == 9) ? 0 : c + 1; /* Increment c. */ - if ((j++ % 80) == 0) { /* Newline after line full. */ - usart_send_blocking(USART2, '\r'); - usart_send_blocking(USART2, '\n'); - } - if ((USART_SR(usart) & USART_SR_RXNE) != 0) { - in_ch = usart_recv(USART2); - usart_send_blocking(USART2, in_ch); - } - for (i = 0; i < 3000000; i++) /* Wait a bit. */ - __asm__("NOP"); - } - - return 0; -}