examples: Even more coding-style fixes.
This commit is contained in:
parent
c3fea659d1
commit
bb8741a79b
@ -258,8 +258,7 @@ void gpio_setup(void)
|
|||||||
*/
|
*/
|
||||||
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ,
|
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ,
|
||||||
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL,
|
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL,
|
||||||
GPIO_TIM3_CH1 |
|
GPIO_TIM3_CH1 | GPIO_TIM3_CH2);
|
||||||
GPIO_TIM3_CH2);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set GPIO0 and 1 (in GPIO port B) to
|
* Set GPIO0 and 1 (in GPIO port B) to
|
||||||
@ -267,8 +266,7 @@ void gpio_setup(void)
|
|||||||
*/
|
*/
|
||||||
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ,
|
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ,
|
||||||
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL,
|
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL,
|
||||||
GPIO_TIM3_CH3 |
|
GPIO_TIM3_CH3 | GPIO_TIM3_CH4);
|
||||||
GPIO_TIM3_CH4);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
void tim_setup(void)
|
void tim_setup(void)
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
|
|
||||||
#include <libopencm3/stm32/f1/rcc.h>
|
#include <libopencm3/stm32/f1/rcc.h>
|
||||||
#include <libopencm3/stm32/f1/gpio.h>
|
#include <libopencm3/stm32/f1/gpio.h>
|
||||||
|
|
||||||
#include <libopencm3/usb/usbd.h>
|
#include <libopencm3/usb/usbd.h>
|
||||||
|
|
||||||
const struct usb_device_descriptor dev = {
|
const struct usb_device_descriptor dev = {
|
||||||
@ -73,7 +72,7 @@ const char *usb_strings[] = {
|
|||||||
"x",
|
"x",
|
||||||
"Black Sphere Technologies",
|
"Black Sphere Technologies",
|
||||||
"Simple Device",
|
"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,
|
||||||
@ -84,7 +83,7 @@ static int simple_control_callback(struct usb_setup_data *req, u8 **buf,
|
|||||||
(void)complete;
|
(void)complete;
|
||||||
|
|
||||||
if (req->bmRequestType != 0x40)
|
if (req->bmRequestType != 0x40)
|
||||||
return 0; /* Only accept vendor request */
|
return 0; /* Only accept vendor request. */
|
||||||
|
|
||||||
if (req->wValue & 1)
|
if (req->wValue & 1)
|
||||||
gpio_set(GPIOC, GPIO6);
|
gpio_set(GPIOC, GPIO6);
|
||||||
|
@ -45,8 +45,7 @@ void button_setup(void)
|
|||||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
|
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
|
||||||
|
|
||||||
/* Set GPIO0 (in GPIO port A) to 'input open-drain'. */
|
/* Set GPIO0 (in GPIO port A) to 'input open-drain'. */
|
||||||
gpio_set_mode(GPIOA, GPIO_MODE_INPUT,
|
gpio_set_mode(GPIOA, GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO0);
|
||||||
GPIO_CNF_INPUT_FLOAT, GPIO0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
|
@ -18,32 +18,32 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* 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/spi.h>
|
||||||
#include <libopencm3/stm32/usart.h>
|
#include <libopencm3/stm32/usart.h>
|
||||||
#include <libopencm3/stm32/nvic.h>
|
#include <libopencm3/stm32/nvic.h>
|
||||||
#include <libopencm3/stm32/f2/gpio.h>
|
#include <libopencm3/stm32/f2/gpio.h>
|
||||||
#include <libopencm3/stm32/f2/rcc.h>
|
#include <libopencm3/stm32/f2/rcc.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <errno.h>
|
|
||||||
|
|
||||||
void clock_setup(void)
|
void clock_setup(void)
|
||||||
{
|
{
|
||||||
RCC_APB1ENR |= RCC_APB1ENR_SPI2EN;
|
RCC_APB1ENR |= RCC_APB1ENR_SPI2EN;
|
||||||
RCC_APB2ENR |= RCC_APB2ENR_USART1EN;
|
RCC_APB2ENR |= RCC_APB2ENR_USART1EN;
|
||||||
RCC_AHB1ENR |= RCC_AHB1ENR_IOPCEN | RCC_AHB1ENR_IOPAEN | RCC_AHB1ENR_IOPBEN;
|
RCC_AHB1ENR |=
|
||||||
|
RCC_AHB1ENR_IOPCEN | RCC_AHB1ENR_IOPAEN | RCC_AHB1ENR_IOPBEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
void spi_setup(void)
|
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);
|
gpio_set_af(GPIOB, GPIO_AF5, GPIO13 | GPIO14 | GPIO15);
|
||||||
|
|
||||||
/* Setup SPI parameters. */
|
/* Setup SPI parameters. */
|
||||||
spi_init_master(SPI2, SPI_CR1_BAUDRATE_FPCLK_DIV_256, SPI_CR1_CPOL, \
|
spi_init_master(SPI2, SPI_CR1_BAUDRATE_FPCLK_DIV_256, SPI_CR1_CPOL,
|
||||||
SPI_CR1_CPHA, SPI_CR1_DFF_8BIT, SPI_CR1_MSBFIRST);
|
SPI_CR1_CPHA, SPI_CR1_DFF_8BIT, SPI_CR1_MSBFIRST);
|
||||||
spi_enable_ss_output(SPI2); /* Required, see 25.3.1 section about NSS */
|
spi_enable_ss_output(SPI2); /* Required, see NSS, 25.3.1 section. */
|
||||||
|
|
||||||
/* Finally enable the SPI. */
|
/* Finally enable the SPI. */
|
||||||
spi_enable(SPI2);
|
spi_enable(SPI2);
|
||||||
@ -70,9 +70,8 @@ void gpio_setup(void)
|
|||||||
{
|
{
|
||||||
gpio_set(GPIOC, GPIO3);
|
gpio_set(GPIOC, GPIO3);
|
||||||
|
|
||||||
/* Setup GPIO3 (in GPIO port C) for led use. */
|
/* Setup GPIO3 (in GPIO port C) for LED use. */
|
||||||
gpio_mode_setup(GPIOC, GPIO_MODE_OUTPUT,
|
gpio_mode_setup(GPIOC, GPIO_MODE_OUTPUT, GPIO_MODE_OUTPUT, GPIO3);
|
||||||
GPIO_MODE_OUTPUT, GPIO3);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int _write(int file, char *ptr, int len)
|
int _write(int file, char *ptr, int len)
|
||||||
@ -80,9 +79,8 @@ int _write (int file, char *ptr, int len)
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (file == 1) {
|
if (file == 1) {
|
||||||
for (i = 0; i < len; i++){
|
for (i = 0; i < len; i++)
|
||||||
usart_send_blocking(USART1, ptr[i]);
|
usart_send_blocking(USART1, ptr[i]);
|
||||||
}
|
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
errno = EIO;
|
errno = EIO;
|
||||||
@ -99,15 +97,16 @@ int main(void)
|
|||||||
usart_setup();
|
usart_setup();
|
||||||
spi_setup();
|
spi_setup();
|
||||||
|
|
||||||
while (1)
|
while (1) {
|
||||||
{
|
|
||||||
counter++;
|
counter++;
|
||||||
printf("Hello, world! %i\r\n", counter);
|
printf("Hello, world! %i\r\n", counter);
|
||||||
dummy = spi_read(SPI2); /* Stops RX buff overflow, but probably not needed */
|
/* Stops RX buffer overflow, but probably not needed. */
|
||||||
|
dummy = spi_read(SPI2);
|
||||||
spi_send(SPI2, (u8) counter);
|
spi_send(SPI2, (u8) counter);
|
||||||
gpio_toggle(GPIOC, GPIO3);
|
gpio_toggle(GPIOC, GPIO3);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (1);
|
while (1);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -35,8 +35,7 @@ void clock_setup(void)
|
|||||||
|
|
||||||
/* Enable clocks for GPIO port A (for GPIO_USART1_TX) and USART1. */
|
/* Enable clocks for GPIO port A (for GPIO_USART1_TX) and USART1. */
|
||||||
// rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN |
|
// rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN |
|
||||||
// RCC_APB2ENR_AFIOEN |
|
// RCC_APB2ENR_AFIOEN | RCC_APB2ENR_USART1EN);
|
||||||
// RCC_APB2ENR_USART1EN);
|
|
||||||
RCC_APB2ENR |= RCC_APB2ENR_USART1EN;
|
RCC_APB2ENR |= RCC_APB2ENR_USART1EN;
|
||||||
RCC_AHB1ENR |= RCC_AHB1ENR_IOPCEN | RCC_AHB1ENR_IOPAEN;
|
RCC_AHB1ENR |= RCC_AHB1ENR_IOPCEN | RCC_AHB1ENR_IOPAEN;
|
||||||
}
|
}
|
||||||
@ -62,9 +61,8 @@ void gpio_setup(void)
|
|||||||
{
|
{
|
||||||
gpio_set(GPIOC, GPIO3);
|
gpio_set(GPIOC, GPIO3);
|
||||||
|
|
||||||
/* Setup GPIO6 and 7 (in GPIO port A) for led use. */
|
/* Setup GPIO6 and 7 (in GPIO port A) for LED use. */
|
||||||
gpio_mode_setup(GPIOC, GPIO_MODE_OUTPUT,
|
gpio_mode_setup(GPIOC, GPIO_MODE_OUTPUT, GPIO_MODE_OUTPUT, GPIO3);
|
||||||
GPIO_MODE_OUTPUT, GPIO3);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int _write(int file, char *ptr, int len)
|
int _write(int file, char *ptr, int len)
|
||||||
@ -72,10 +70,8 @@ int _write (int file, char *ptr, int len)
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (file == 1) {
|
if (file == 1) {
|
||||||
for (i = 0; i < len; i++){
|
for (i = 0; i < len; i++)
|
||||||
usart_send_blocking(USART1, ptr[i]);
|
usart_send_blocking(USART1, ptr[i]);
|
||||||
}
|
|
||||||
|
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,7 +95,8 @@ int main(void)
|
|||||||
*/
|
*/
|
||||||
while (1) {
|
while (1) {
|
||||||
gpio_toggle(GPIOC, GPIO3);
|
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++;
|
counter++;
|
||||||
fcounter += 0.01;
|
fcounter += 0.01;
|
||||||
dcounter += 0.01;
|
dcounter += 0.01;
|
||||||
|
@ -37,8 +37,7 @@ void gpio_setup(void)
|
|||||||
|
|
||||||
/* Set GPIO12 (in GPIO port D) to 'output push-pull'. */
|
/* Set GPIO12 (in GPIO port D) to 'output push-pull'. */
|
||||||
gpio_mode_setup(GPIOD, GPIO_MODE_OUTPUT,
|
gpio_mode_setup(GPIOD, GPIO_MODE_OUTPUT,
|
||||||
GPIO_PUPD_NONE,
|
GPIO_PUPD_NONE, GPIO12 | GPIO13 | GPIO14 | GPIO15);
|
||||||
GPIO12 | GPIO13 | GPIO14 | GPIO15);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void button_setup(void)
|
void button_setup(void)
|
||||||
@ -47,9 +46,7 @@ void button_setup(void)
|
|||||||
rcc_peripheral_enable_clock(&RCC_AHB1ENR, RCC_AHB1ENR_IOPAEN);
|
rcc_peripheral_enable_clock(&RCC_AHB1ENR, RCC_AHB1ENR_IOPAEN);
|
||||||
|
|
||||||
/* Set GPIO0 (in GPIO port A) to 'input open-drain'. */
|
/* Set GPIO0 (in GPIO port A) to 'input open-drain'. */
|
||||||
gpio_mode_setup(GPIOA, GPIO_MODE_INPUT,
|
gpio_mode_setup(GPIOA, GPIO_MODE_INPUT, GPIO_PUPD_NONE, GPIO0);
|
||||||
GPIO_PUPD_NONE,
|
|
||||||
GPIO0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
|
@ -35,8 +35,7 @@ void gpio_setup(void)
|
|||||||
{
|
{
|
||||||
/* Set GPIO12-15 (in GPIO port D) to 'output push-pull'. */
|
/* Set GPIO12-15 (in GPIO port D) to 'output push-pull'. */
|
||||||
gpio_mode_setup(GPIOD, GPIO_MODE_OUTPUT,
|
gpio_mode_setup(GPIOD, GPIO_MODE_OUTPUT,
|
||||||
GPIO_PUPD_NONE,
|
GPIO_PUPD_NONE, GPIO12 | GPIO13 | GPIO14 | GPIO15);
|
||||||
GPIO12 | GPIO13 | GPIO14 | GPIO15);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
|
@ -34,9 +34,7 @@ void gpio_setup(void)
|
|||||||
// GPIOD_CRH = (GPIO_CNF_OUTPUT_PUSHPULL << (((8 - 8) * 4) + 2));
|
// GPIOD_CRH = (GPIO_CNF_OUTPUT_PUSHPULL << (((8 - 8) * 4) + 2));
|
||||||
// GPIOD_CRH |= (GPIO_MODE_OUTPUT_2_MHZ << ((8 - 8) * 4));
|
// GPIOD_CRH |= (GPIO_MODE_OUTPUT_2_MHZ << ((8 - 8) * 4));
|
||||||
/* Using API functions: */
|
/* Using API functions: */
|
||||||
gpio_mode_setup(GPIOD, GPIO_MODE_OUTPUT,
|
gpio_mode_setup(GPIOD, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO12);
|
||||||
GPIO_PUPD_NONE,
|
|
||||||
GPIO12);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
|
@ -49,14 +49,10 @@ void usart_setup(void)
|
|||||||
void gpio_setup(void)
|
void gpio_setup(void)
|
||||||
{
|
{
|
||||||
/* Setup GPIO pin GPIO12 on GPIO port D for LED. */
|
/* Setup GPIO pin GPIO12 on GPIO port D for LED. */
|
||||||
gpio_mode_setup(GPIOD, GPIO_MODE_OUTPUT,
|
gpio_mode_setup(GPIOD, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO12);
|
||||||
GPIO_PUPD_NONE,
|
|
||||||
GPIO12);
|
|
||||||
|
|
||||||
/* Setup GPIO pins for USART2 transmit. */
|
/* Setup GPIO pins for USART2 transmit. */
|
||||||
gpio_mode_setup(GPIOA, GPIO_MODE_AF,
|
gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO2);
|
||||||
GPIO_PUPD_NONE,
|
|
||||||
GPIO2);
|
|
||||||
|
|
||||||
/* Setup USART2 TX pin as alternate function. */
|
/* Setup USART2 TX pin as alternate function. */
|
||||||
gpio_set_af(GPIOA, GPIO_AF7, GPIO2);
|
gpio_set_af(GPIOA, GPIO_AF7, GPIO2);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user