examples: Even more coding-style fixes.

This commit is contained in:
Uwe Hermann 2011-11-13 17:07:21 +01:00
parent c3fea659d1
commit bb8741a79b
31 changed files with 157 additions and 175 deletions

View File

@ -45,8 +45,8 @@ void gpio_setup(void)
AFIO_MAPR |= AFIO_MAPR_SWJ_CFG_FULL_SWJ_NO_JNTRST;
/* Preconfigure the LEDs. */
gpio_set(GPIOB, GPIO4); /* Switch off LED. */
gpio_clear(GPIOC, GPIO13); /* Switch on LED. */
gpio_set(GPIOB, GPIO4); /* Switch off LED. */
gpio_clear(GPIOC, GPIO13); /* Switch on LED. */
}
int main(void)

View File

@ -170,7 +170,7 @@ static int cdcacm_control_request(struct usb_setup_data *req, u8 **buf,
(void)complete;
(void)buf;
switch(req->bRequest) {
switch (req->bRequest) {
case USB_CDC_REQ_SET_CONTROL_LINE_STATE: {
/*
* This Linux cdc_acm driver requires this to be implemented
@ -240,10 +240,10 @@ int main(void)
gpio_set(GPIOC, GPIO2);
gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_2_MHZ,
GPIO_CNF_OUTPUT_PUSHPULL, GPIO2);
GPIO_CNF_OUTPUT_PUSHPULL, GPIO2);
gpio_set(GPIOC, GPIO5);
gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_2_MHZ,
GPIO_CNF_OUTPUT_PUSHPULL, GPIO5);
GPIO_CNF_OUTPUT_PUSHPULL, GPIO5);
usbd_init(&stm32f107_usb_driver, &dev, &config, usb_strings);
usbd_register_set_config_callback(cdcacm_set_config);

View File

@ -197,7 +197,7 @@ static void dfu_detach_complete(struct usb_setup_data *req)
gpio_set_mode(GPIOA, GPIO_MODE_INPUT, 0, GPIO15);
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ,
GPIO_CNF_OUTPUT_PUSHPULL, GPIO10);
GPIO_CNF_OUTPUT_PUSHPULL, GPIO10);
gpio_set(GPIOA, GPIO10);
scb_reset_core();
}

View File

@ -367,25 +367,25 @@ int main(void)
TIM1_CCR1 = gamma_table_linear[j0];
j0 += d0;
if (j0 == 255)
d0 =- 1;
d0 = -1;
if (j0 == 0)
d0 = 1;
TIM1_CCR2 = gamma_table_1_3[j1];
j1 += d1;
if (j1 == 255)
d1 =- 1;
d1 = -1;
if (j1 == 0)
d1 = 1;
TIM1_CCR3 = gamma_table_2_5[j2];
j2 += d2;
if (j2 == 255)
d2 =- 1;
d2 = -1;
if (j2 == 0)
d2 = 1;
TIM1_CCR4= gamma_table_3_0[j3];
TIM1_CCR4 = gamma_table_3_0[j3];
j3 += d3;
if (j3 == 255)
d3 =- 1;
d3 = -1;
if (j3 == 0)
d3 = 1;
for (i = 0; i < 50000; i++);
@ -405,25 +405,25 @@ int main(void)
TIM1_CCR1 = GAMMA_TABLE[j0];
j0 += d0;
if (j0 == 255)
d0 =- 1;
d0 = -1;
if (j0 == 0)
d0 = 1;
TIM1_CCR2 = GAMMA_TABLE[j1];
j1 += d1;
if (j1 == 255)
d1 =- 1;
d1 = - 1;
if (j1 == 0)
d1 = 1;
TIM1_CCR3 = GAMMA_TABLE[j2];
j2 += d2;
if (j2 == 255)
d2 =- 1;
d2 = -1;
if (j2 == 0)
d2 = 1;
TIM1_CCR4 = GAMMA_TABLE[j3];
j3 += d3;
if (j3 == 255)
d3 =- 1;
d3 = -1;
if (j3 == 0)
d3 = 1;
for (i = 0; i < 10000; i++);
@ -446,25 +446,25 @@ int main(void)
TIM1_CCR1 = GAMMA_TABLE[j0];
j0 += d0;
if (j0 == 255)
d0 =- 1;
d0 = -1;
if (j0 == 19)
j0 = 20;
TIM1_CCR2 = GAMMA_TABLE[j1];
j1 += d1;
if (j1 == 255)
d1 =- 1;
d1 = -1;
if (j1 == 19)
j1 = 20;
TIM1_CCR3 = GAMMA_TABLE[j2];
j2 += d2;
if (j2 == 255)
d2 =- 1;
d2 = -1;
if (j2 == 19)
j2 = 20;
TIM1_CCR4 = GAMMA_TABLE[j3];
j3 += d3;
if (j3 == 255)
d3 =- 1;
d3 = -1;
if (j3 == 19)
j3 = 20;
for (i = 0; i < 5000; i++);
@ -486,7 +486,7 @@ int main(void)
break;
}
if (k == 3)
kd =- 1;
kd = -1;
if (k == 0)
kd = 1;
}

View File

@ -62,15 +62,15 @@ void gpio_setup(void)
/* 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_CNF_OUTPUT_PUSHPULL, GPIO6);
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ,
GPIO_CNF_OUTPUT_PUSHPULL, GPIO7);
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_CNF_OUTPUT_PUSHPULL, GPIO0);
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ,
GPIO_CNF_OUTPUT_PUSHPULL, GPIO1);
GPIO_CNF_OUTPUT_PUSHPULL, GPIO1);
}
void systick_setup(void)

View File

@ -257,18 +257,16 @@ void gpio_setup(void)
* 'output alternate function push-pull'.
*/
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ,
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL,
GPIO_TIM3_CH1 |
GPIO_TIM3_CH2);
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL,
GPIO_TIM3_CH1 | GPIO_TIM3_CH2);
/*
* Set GPIO0 and 1 (in GPIO port B) to
* 'output alternate function push-pull'.
*/
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ,
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL,
GPIO_TIM3_CH3 |
GPIO_TIM3_CH4);
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL,
GPIO_TIM3_CH3 | GPIO_TIM3_CH4);
}
void tim_setup(void)
@ -354,25 +352,25 @@ int main(void)
TIM3_CCR1 = gamma_table_linear[j0];
j0 += d0;
if (j0 == 255)
d0 =- 1;
d0 = -1;
if (j0 == 0)
d0 = 1;
TIM3_CCR2 = gamma_table_1_3[j1];
j1 += d1;
if (j1 == 255)
d1 =- 1;
d1 = -1;
if (j1 == 0)
d1 = 1;
TIM3_CCR3 = gamma_table_2_5[j2];
j2 += d2;
if (j2 == 255)
d2 =- 1;
d2 = -1;
if (j2 == 0)
d2 = 1;
TIM3_CCR4= gamma_table_3_0[j3];
TIM3_CCR4 = gamma_table_3_0[j3];
j3 += d3;
if (j3 == 255)
d3 =- 1;
d3 = -1;
if (j3 == 0)
d3 = 1;
for (i = 0; i < 50000; i++);
@ -392,25 +390,25 @@ int main(void)
TIM3_CCR1 = GAMMA_TABLE[j0];
j0 += d0;
if (j0 == 255)
d0 =- 1;
d0 = -1;
if (j0 == 0)
d0 = 1;
TIM3_CCR2 = GAMMA_TABLE[j1];
j1 += d1;
if (j1 == 255)
d1 =- 1;
d1 = -1;
if (j1 == 0)
d1 = 1;
TIM3_CCR3 = GAMMA_TABLE[j2];
j2 += d2;
if (j2 == 255)
d2 =- 1;
d2 = -1;
if (j2 == 0)
d2 = 1;
TIM3_CCR4 = GAMMA_TABLE[j3];
j3 += d3;
if (j3 == 255)
d3 =- 1;
d3 = -1;
if (j3 == 0)
d3 = 1;
for (i = 0; i < 10000; i++);
@ -433,25 +431,25 @@ int main(void)
TIM3_CCR1 = GAMMA_TABLE[j0];
j0 += d0;
if (j0 == 255)
d0 =- 1;
d0 = -1;
if (j0 == 19)
j0 = 20;
TIM3_CCR2 = GAMMA_TABLE[j1];
j1 += d1;
if (j1 == 255)
d1 =- 1;
d1 = -1;
if (j1 == 19)
j1 = 20;
TIM3_CCR3 = GAMMA_TABLE[j2];
j2 += d2;
if (j2 == 255)
d2 =- 1;
d2 = -1;
if (j2 == 19)
j2 = 20;
TIM3_CCR4 = GAMMA_TABLE[j3];
j3 += d3;
if (j3 == 255)
d3 =- 1;
d3 = -1;
if (j3 == 19)
j3 = 20;
for (i = 0; i < 15000; i++)
@ -474,7 +472,7 @@ int main(void)
break;
}
if (k == 3)
kd =- 1;
kd = -1;
if (k == 0)
kd = 1;
}

View File

@ -41,15 +41,15 @@ void gpio_setup(void)
/* 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_CNF_OUTPUT_PUSHPULL, GPIO6);
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ,
GPIO_CNF_OUTPUT_PUSHPULL, GPIO7);
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_CNF_OUTPUT_PUSHPULL, GPIO0);
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ,
GPIO_CNF_OUTPUT_PUSHPULL, GPIO1);
GPIO_CNF_OUTPUT_PUSHPULL, GPIO1);
}
void sys_tick_handler(void)

View File

@ -44,7 +44,7 @@ void usart_setup(void)
/* Setup GPIO pin GPIO_USART3_TX/GPIO10 on GPIO port B for transmit. */
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ,
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART1_RE_TX);
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART1_RE_TX);
/* Setup UART parameters. */
usart_set_baudrate(USART1, 230400, rcc_ppre2_frequency);

View File

@ -45,7 +45,7 @@ void usart_setup(void)
/* Setup GPIO pin GPIO_USART1_RE_TX on GPIO port B for transmit. */
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ,
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART1_RE_TX);
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART1_RE_TX);
/* Setup GPIO pin GPIO_USART1_RE_RX on GPIO port B for receive. */
gpio_set_mode(GPIOB, GPIO_MODE_INPUT,

View File

@ -31,7 +31,7 @@ void usart_setup(void)
/* Setup GPIO pin GPIO_USART1_TX/GPIO9 on GPIO port A for transmit. */
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ,
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART1_TX);
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART1_TX);
/* Setup UART parameters. */
usart_set_baudrate(USART1, 115200, rcc_ppre2_frequency);
@ -52,9 +52,9 @@ void gpio_setup(void)
/* Set GPIO6/7 (in GPIO port B) to 'output push-pull' for the LEDs. */
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_2_MHZ,
GPIO_CNF_OUTPUT_PUSHPULL, GPIO6);
GPIO_CNF_OUTPUT_PUSHPULL, GPIO6);
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_2_MHZ,
GPIO_CNF_OUTPUT_PUSHPULL, GPIO7);
GPIO_CNF_OUTPUT_PUSHPULL, GPIO7);
}
void adc_setup(void)
@ -93,8 +93,8 @@ void my_usart_print_int(u32 usart, int value)
char buffer[25];
if (value < 0) {
usart_send(usart, '-');
value = value * -1;
usart_send(usart, '-');
value = value * -1;
}
while (value > 0) {

View File

@ -31,7 +31,7 @@ void usart_setup(void)
/* Setup GPIO pin GPIO_USART1_TX/GPIO9 on GPIO port A for transmit. */
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ,
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART1_TX);
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART1_TX);
/* Setup UART parameters. */
usart_set_baudrate(USART1, 115200, rcc_ppre2_frequency);
@ -52,9 +52,9 @@ void gpio_setup(void)
/* Set GPIO6/7 (in GPIO port B) to 'output push-pull' for the LEDs. */
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_2_MHZ,
GPIO_CNF_OUTPUT_PUSHPULL, GPIO6);
GPIO_CNF_OUTPUT_PUSHPULL, GPIO6);
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_2_MHZ,
GPIO_CNF_OUTPUT_PUSHPULL, GPIO7);
GPIO_CNF_OUTPUT_PUSHPULL, GPIO7);
}
void my_usart_print_string(u32 usart, char *s)

View File

@ -159,7 +159,7 @@ void dogm128_update_display(void)
u8 page, column;
/* Tell the display that we want to start. */
spi_set_nss_low(DOGM128_SPI);
spi_set_nss_low(DOGM128_SPI);
for (page = 0; page <= 7; page++) {
dogm128_send_command(0xB0 + page); /* Set page. */

View File

@ -33,24 +33,24 @@ void gpio_setup(void)
/* Set GPIO6/7 (in GPIO port B) to 'output push-pull' for the LEDs. */
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_2_MHZ,
GPIO_CNF_OUTPUT_PUSHPULL, GPIO6);
GPIO_CNF_OUTPUT_PUSHPULL, GPIO6);
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_2_MHZ,
GPIO_CNF_OUTPUT_PUSHPULL, GPIO7);
GPIO_CNF_OUTPUT_PUSHPULL, GPIO7);
/* A0 of DOGM128 */
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ,
GPIO_CNF_OUTPUT_PUSHPULL, GPIO14);
GPIO_CNF_OUTPUT_PUSHPULL, GPIO14);
/* Reset of DOGM128 */
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ,
GPIO_CNF_OUTPUT_PUSHPULL, GPIO10);
GPIO_CNF_OUTPUT_PUSHPULL, GPIO10);
/* DOGM128/SPI2 clock and MOSI and NSS(CS1) */
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ,
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO12);
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO12);
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ,
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO13);
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO13);
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ,
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO15);
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO15);
}
void spi_setup(void)

View File

@ -128,7 +128,7 @@ int main(void)
temperature = stts75_read_temperature(I2C2, STTS75_SENSOR0);
/* Send the temperature as binary over USART1. */
for (i = 15; i >= 0 ; i--) {
for (i = 15; i >= 0; i--) {
if (temperature & (1 << i))
usart_send(USART1, '1');
else

View File

@ -140,7 +140,7 @@ u16 stts75_read_temperature(u32 i2c, u8 sensor)
reg32 = I2C_SR2(i2c);
i2c_send_data(i2c, 0x0); /* temperature register */
while (!(I2C_SR1(i2c) & (I2C_SR1_BTF|I2C_SR1_TxE)));
while (!(I2C_SR1(i2c) & (I2C_SR1_BTF | I2C_SR1_TxE)));
/*
* Now we transferred that we want to ACCESS the temperature register.

View File

@ -40,7 +40,7 @@ void usart_setup(void)
{
/* Setup GPIO pin GPIO_USART1_TX/GPIO9 on GPIO port A for transmit. */
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ,
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART1_TX);
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART1_TX);
/* Setup UART parameters. */
usart_set_baudrate(USART1, 38400, rcc_ppre2_frequency);

View File

@ -32,9 +32,9 @@ void gpio_setup(void)
/* Set GPIO6/7 (in GPIO port B) to 'output push-pull' for the LEDs. */
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_2_MHZ,
GPIO_CNF_OUTPUT_PUSHPULL, GPIO6);
GPIO_CNF_OUTPUT_PUSHPULL, GPIO6);
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_2_MHZ,
GPIO_CNF_OUTPUT_PUSHPULL, GPIO7);
GPIO_CNF_OUTPUT_PUSHPULL, GPIO7);
}
void sys_tick_handler(void)

View File

@ -30,9 +30,9 @@ void gpio_setup(void)
/* Set GPIO6/7 (in GPIO port B) to 'output push-pull' for the LEDs. */
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_2_MHZ,
GPIO_CNF_OUTPUT_PUSHPULL, GPIO6);
GPIO_CNF_OUTPUT_PUSHPULL, GPIO6);
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_2_MHZ,
GPIO_CNF_OUTPUT_PUSHPULL, GPIO7);
GPIO_CNF_OUTPUT_PUSHPULL, GPIO7);
}
void nvic_setup(void)

View File

@ -102,12 +102,12 @@ int main(void)
/* Blink the LED (PC12) on the board with every transmitted byte. */
while (1) {
gpio_toggle(GPIOC, GPIO12); /* LED on/off */
usart_send_blocking(USART1, c + '0'); /* USART1: Send byte. */
usart_send_blocking(USART2, c + '0'); /* USART2: Send byte. */
usart_send_blocking(USART3, c + '0'); /* USART3: Send byte. */
gpio_toggle(GPIOC, GPIO12); /* LED on/off */
usart_send_blocking(USART1, c + '0'); /* USART1: Send byte. */
usart_send_blocking(USART2, c + '0'); /* USART2: Send byte. */
usart_send_blocking(USART3, c + '0'); /* USART3: Send byte. */
c = (c == 9) ? 0 : c + 1; /* Increment c. */
if ((j++ % 80) == 0) { /* Newline after line full. */
if ((j++ % 80) == 0) { /* Newline after line full. */
usart_send_blocking(USART1, '\r');
usart_send_blocking(USART1, '\n');
usart_send_blocking(USART2, '\r');

View File

@ -193,7 +193,7 @@ static void dfu_detach_complete(struct usb_setup_data *req)
gpio_set_mode(GPIOA, GPIO_MODE_INPUT, 0, GPIO15);
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ,
GPIO_CNF_OUTPUT_PUSHPULL, GPIO10);
GPIO_CNF_OUTPUT_PUSHPULL, GPIO10);
gpio_set(GPIOA, GPIO10);
scb_reset_core();
}
@ -230,7 +230,7 @@ static void hid_set_config(u16 wValue)
dfu_control_request);
#endif
systick_set_clocksource(STK_CTRL_CLKSOURCE_AHB_DIV8);
systick_set_clocksource(STK_CTRL_CLKSOURCE_AHB_DIV8);
systick_set_reload(100000);
systick_interrupt_enable();
systick_counter_enable();

View File

@ -19,24 +19,23 @@
#include <libopencm3/stm32/f1/rcc.h>
#include <libopencm3/stm32/f1/gpio.h>
#include <libopencm3/usb/usbd.h>
const struct usb_device_descriptor dev = {
.bLength = USB_DT_DEVICE_SIZE,
.bDescriptorType = USB_DT_DEVICE,
.bcdUSB = 0x0200,
.bDeviceClass = 0xFF,
.bDeviceSubClass = 0,
.bDeviceProtocol = 0,
.bMaxPacketSize0 = 64,
.idVendor = 0xCAFE,
.idProduct = 0xCAFE,
.bcdDevice = 0x0200,
.iManufacturer = 1,
.iProduct = 2,
.iSerialNumber = 3,
.bNumConfigurations = 1,
.bLength = USB_DT_DEVICE_SIZE,
.bDescriptorType = USB_DT_DEVICE,
.bcdUSB = 0x0200,
.bDeviceClass = 0xFF,
.bDeviceSubClass = 0,
.bDeviceProtocol = 0,
.bMaxPacketSize0 = 64,
.idVendor = 0xCAFE,
.idProduct = 0xCAFE,
.bcdDevice = 0x0200,
.iManufacturer = 1,
.iProduct = 2,
.iSerialNumber = 3,
.bNumConfigurations = 1,
};
const struct usb_interface_descriptor iface = {
@ -73,20 +72,20 @@ const char *usb_strings[] = {
"x",
"Black Sphere Technologies",
"Simple Device",
"1001"
"1001",
};
static int simple_control_callback(struct usb_setup_data *req, u8 **buf,
static int simple_control_callback(struct usb_setup_data *req, u8 **buf,
u16 *len, void (**complete)(struct usb_setup_data *req))
{
(void)buf;
(void)len;
(void)complete;
if(req->bmRequestType != 0x40)
return 0; /* Only accept vendor request */
if (req->bmRequestType != 0x40)
return 0; /* Only accept vendor request. */
if(req->wValue & 1)
if (req->wValue & 1)
gpio_set(GPIOC, GPIO6);
else
gpio_clear(GPIOC, GPIO6);
@ -102,16 +101,16 @@ int main(void)
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN);
/* LED output */
gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_2_MHZ,
GPIO_CNF_OUTPUT_PUSHPULL, GPIO6);
gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_2_MHZ,
GPIO_CNF_OUTPUT_PUSHPULL, GPIO6);
usbd_init(&stm32f107_usb_driver, &dev, &config, usb_strings);
usbd_register_control_callback(
USB_REQ_TYPE_VENDOR,
USB_REQ_TYPE_VENDOR,
USB_REQ_TYPE_TYPE,
simple_control_callback);
while (1)
while (1)
usbd_poll();
}

View File

@ -45,8 +45,7 @@ void button_setup(void)
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
/* Set GPIO0 (in GPIO port A) to 'input open-drain'. */
gpio_set_mode(GPIOA, GPIO_MODE_INPUT,
GPIO_CNF_INPUT_FLOAT, GPIO0);
gpio_set_mode(GPIOA, GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO0);
}
int main(void)

View File

@ -41,7 +41,7 @@ void usart_setup(void)
{
/* Setup GPIO pin GPIO_USART1_TX/GPIO9 on GPIO port A for transmit. */
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ,
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART1_TX);
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART1_TX);
/* Setup UART parameters. */
// usart_set_baudrate(USART1, 38400);

View File

@ -37,7 +37,7 @@ void usart_setup(void)
{
/* Setup GPIO pin GPIO_USART1_TX/GPIO9 on GPIO port A for transmit. */
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ,
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART1_TX);
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART1_TX);
/* Setup UART parameters. */
// usart_set_baudrate(USART1, 38400);

View File

@ -33,8 +33,8 @@ void gpio_setup(void)
// GPIOC_CRH = (GPIO_CNF_OUTPUT_PUSHPULL << (((12 - 8) * 4) + 2));
// GPIOC_CRH |= (GPIO_MODE_OUTPUT_2_MHZ << ((12 - 8) * 4));
/* Using API functions: */
MMIO32(RCC_BASE+0x30) |= (1<<2);
gpio_mode_setup(GPIOC, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO3|GPIO4);
MMIO32(RCC_BASE + 0x30) |= (1 << 2);
gpio_mode_setup(GPIOC, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO3 | GPIO4);
}
int main(void)

View File

@ -18,32 +18,32 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <errno.h>
#include <libopencm3/stm32/spi.h>
#include <libopencm3/stm32/usart.h>
#include <libopencm3/stm32/nvic.h>
#include <libopencm3/stm32/f2/gpio.h>
#include <libopencm3/stm32/f2/rcc.h>
#include <stdio.h>
#include <errno.h>
void clock_setup(void)
{
RCC_APB1ENR |= RCC_APB1ENR_SPI2EN;
RCC_APB2ENR |= RCC_APB2ENR_USART1EN;
RCC_AHB1ENR |= RCC_AHB1ENR_IOPCEN | RCC_AHB1ENR_IOPAEN | RCC_AHB1ENR_IOPBEN;
RCC_APB1ENR |= RCC_APB1ENR_SPI2EN;
RCC_APB2ENR |= RCC_APB2ENR_USART1EN;
RCC_AHB1ENR |=
RCC_AHB1ENR_IOPCEN | RCC_AHB1ENR_IOPAEN | RCC_AHB1ENR_IOPBEN;
}
void spi_setup(void)
{
gpio_mode_setup(GPIOB, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO13 | GPIO14 | GPIO15);
gpio_mode_setup(GPIOB, GPIO_MODE_AF, GPIO_PUPD_NONE,
GPIO13 | GPIO14 | GPIO15);
gpio_set_af(GPIOB, GPIO_AF5, GPIO13 | GPIO14 | GPIO15);
/* Setup SPI parameters. */
spi_init_master(SPI2, SPI_CR1_BAUDRATE_FPCLK_DIV_256, SPI_CR1_CPOL, \
SPI_CR1_CPHA, SPI_CR1_DFF_8BIT, SPI_CR1_MSBFIRST);
spi_enable_ss_output(SPI2); /* Required, see 25.3.1 section about NSS */
spi_init_master(SPI2, SPI_CR1_BAUDRATE_FPCLK_DIV_256, SPI_CR1_CPOL,
SPI_CR1_CPHA, SPI_CR1_DFF_8BIT, SPI_CR1_MSBFIRST);
spi_enable_ss_output(SPI2); /* Required, see NSS, 25.3.1 section. */
/* Finally enable the SPI. */
spi_enable(SPI2);
@ -52,7 +52,7 @@ void spi_setup(void)
void usart_setup(void)
{
gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO9);
gpio_set_af(GPIOA, GPIO_AF7, GPIO9|GPIO10);
gpio_set_af(GPIOA, GPIO_AF7, GPIO9 | GPIO10);
/* Setup UART parameters. */
usart_set_baudrate(USART1, 9600, 16000000);
@ -70,44 +70,43 @@ void gpio_setup(void)
{
gpio_set(GPIOC, GPIO3);
/* Setup GPIO3 (in GPIO port C) for led use. */
gpio_mode_setup(GPIOC, GPIO_MODE_OUTPUT,
GPIO_MODE_OUTPUT, GPIO3);
/* Setup GPIO3 (in GPIO port C) for LED use. */
gpio_mode_setup(GPIOC, GPIO_MODE_OUTPUT, GPIO_MODE_OUTPUT, GPIO3);
}
int _write (int file, char *ptr, int len)
int _write(int file, char *ptr, int len)
{
int i;
int i;
if (file == 1) {
for (i = 0; i < len; i++){
for (i = 0; i < len; i++)
usart_send_blocking(USART1, ptr[i]);
}
return i;
}
errno = EIO;
return -1;
errno = EIO;
return -1;
}
int main(void)
{
int counter = 0;
volatile u16 dummy;
volatile u16 dummy;
clock_setup();
gpio_setup();
usart_setup();
spi_setup();
spi_setup();
while (1)
{
while (1) {
counter++;
printf("Hello, world! %i\r\n", counter);
dummy = spi_read(SPI2); /* Stops RX buff overflow, but probably not needed */
spi_send(SPI2,(u8)counter);
gpio_toggle(GPIOC, GPIO3);
printf("Hello, world! %i\r\n", counter);
/* Stops RX buffer overflow, but probably not needed. */
dummy = spi_read(SPI2);
spi_send(SPI2, (u8) counter);
gpio_toggle(GPIOC, GPIO3);
}
while(1);
while (1);
return 0;
}

View File

@ -34,17 +34,16 @@ void clock_setup(void)
//rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN);
/* Enable clocks for GPIO port A (for GPIO_USART1_TX) and USART1. */
//rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN |
// RCC_APB2ENR_AFIOEN |
// RCC_APB2ENR_USART1EN);
RCC_APB2ENR |= RCC_APB2ENR_USART1EN;
// rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN |
// RCC_APB2ENR_AFIOEN | RCC_APB2ENR_USART1EN);
RCC_APB2ENR |= RCC_APB2ENR_USART1EN;
RCC_AHB1ENR |= RCC_AHB1ENR_IOPCEN | RCC_AHB1ENR_IOPAEN;
}
void usart_setup(void)
{
gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO9);
gpio_set_af(GPIOA, GPIO_AF7, GPIO9|GPIO10);
gpio_set_af(GPIOA, GPIO_AF7, GPIO9 | GPIO10);
/* Setup UART parameters. */
usart_set_baudrate(USART1, 9600, 16000000);
@ -62,25 +61,22 @@ void gpio_setup(void)
{
gpio_set(GPIOC, GPIO3);
/* Setup GPIO6 and 7 (in GPIO port A) for led use. */
gpio_mode_setup(GPIOC, GPIO_MODE_OUTPUT,
GPIO_MODE_OUTPUT, GPIO3);
/* Setup GPIO6 and 7 (in GPIO port A) for LED use. */
gpio_mode_setup(GPIOC, GPIO_MODE_OUTPUT, GPIO_MODE_OUTPUT, GPIO3);
}
int _write (int file, char *ptr, int len)
int _write(int file, char *ptr, int len)
{
int i;
int i;
if (file == 1) {
for (i = 0; i < len; i++){
for (i = 0; i < len; i++)
usart_send_blocking(USART1, ptr[i]);
}
return i;
}
errno = EIO;
return -1;
errno = EIO;
return -1;
}
int main(void)
@ -99,10 +95,11 @@ int main(void)
*/
while (1) {
gpio_toggle(GPIOC, GPIO3);
printf("Hello World! %i %f %f\r\n", counter, fcounter, dcounter);
printf("Hello World! %i %f %f\r\n", counter, fcounter,
dcounter);
counter++;
fcounter+=0.01;
dcounter+=0.01;
fcounter += 0.01;
dcounter += 0.01;
}
return 0;

View File

@ -37,8 +37,7 @@ void gpio_setup(void)
/* Set GPIO12 (in GPIO port D) to 'output push-pull'. */
gpio_mode_setup(GPIOD, GPIO_MODE_OUTPUT,
GPIO_PUPD_NONE,
GPIO12 | GPIO13 | GPIO14 | GPIO15);
GPIO_PUPD_NONE, GPIO12 | GPIO13 | GPIO14 | GPIO15);
}
void button_setup(void)
@ -47,9 +46,7 @@ void button_setup(void)
rcc_peripheral_enable_clock(&RCC_AHB1ENR, RCC_AHB1ENR_IOPAEN);
/* Set GPIO0 (in GPIO port A) to 'input open-drain'. */
gpio_mode_setup(GPIOA, GPIO_MODE_INPUT,
GPIO_PUPD_NONE,
GPIO0);
gpio_mode_setup(GPIOA, GPIO_MODE_INPUT, GPIO_PUPD_NONE, GPIO0);
}
int main(void)

View File

@ -35,8 +35,7 @@ void gpio_setup(void)
{
/* Set GPIO12-15 (in GPIO port D) to 'output push-pull'. */
gpio_mode_setup(GPIOD, GPIO_MODE_OUTPUT,
GPIO_PUPD_NONE,
GPIO12 | GPIO13 | GPIO14 | GPIO15);
GPIO_PUPD_NONE, GPIO12 | GPIO13 | GPIO14 | GPIO15);
}
int main(void)
@ -53,7 +52,7 @@ int main(void)
while (1) {
/* Toggle LEDs. */
gpio_toggle(GPIOD, GPIO12 | GPIO13 | GPIO14 | GPIO15);
for (i = 0; i < 6000000; i++) /* Wait a bit. */
for (i = 0; i < 6000000; i++) /* Wait a bit. */
__asm__("nop");
}

View File

@ -34,9 +34,7 @@ void gpio_setup(void)
// GPIOD_CRH = (GPIO_CNF_OUTPUT_PUSHPULL << (((8 - 8) * 4) + 2));
// GPIOD_CRH |= (GPIO_MODE_OUTPUT_2_MHZ << ((8 - 8) * 4));
/* Using API functions: */
gpio_mode_setup(GPIOD, GPIO_MODE_OUTPUT,
GPIO_PUPD_NONE,
GPIO12);
gpio_mode_setup(GPIOD, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO12);
}
int main(void)

View File

@ -49,14 +49,10 @@ void usart_setup(void)
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);
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);
gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO2);
/* Setup USART2 TX pin as alternate function. */
gpio_set_af(GPIOA, GPIO_AF7, GPIO2);