[Stylecheck] F0, F1, F4

There are remaining C99 comments.
This commit is contained in:
Frantisek Burian
2014-01-23 19:06:13 +01:00
parent 022cc475bf
commit 3f47411e24
22 changed files with 203 additions and 159 deletions

View File

@@ -52,8 +52,9 @@ static void adc_setup(void)
/* Wait for ADC starting up. */
int i;
for (i = 0; i < 800000; i++) /* Wait a bit. */
for (i = 0; i < 800000; i++) { /* Wait a bit. */
__asm__("nop");
}
}
@@ -122,8 +123,9 @@ int main(void)
my_usart_print_int(USART1, temp);
int i;
for (i = 0; i < 800000; i++) /* Wait a bit. */
for (i = 0; i < 800000; i++) { /* Wait a bit. */
__asm__("nop");
}
}
return 0;

View File

@@ -62,13 +62,15 @@ int main(void)
gpio_toggle(GPIOC, GPIO8);
/* Upon button press, blink more slowly. */
if (gpio_get(GPIOA,GPIO0)) {
for (i = 0; i < 300000; i++) /* Wait a bit. */
if (gpio_get(GPIOA, GPIO0)) {
for (i = 0; i < 300000; i++) { /* Wait a bit. */
__asm__("nop");
}
}
for (i = 0; i < 300000; i++) /* Wait a bit. */
for (i = 0; i < 300000; i++) { /* Wait a bit. */
__asm__("nop");
}
}
return 0;

View File

@@ -50,23 +50,24 @@ int main(void)
/* Manually: */
// GPIOC_BSRR = PIN_LED; /* LED off */
// for (i = 0; i < 1000000; i++) /* Wait a bit. */
// __asm__("nop");
// __asm__("nop");
// GPIOC_BRR = PIN_LED; /* LED on */
// for (i = 0; i < 1000000; i++) /* Wait a bit. */
// __asm__("nop");
// __asm__("nop");
/* Using API functions gpio_set()/gpio_clear(): */
// gpio_set(PORT_LED, PIN_LED); /* LED off */
// for (i = 0; i < 1000000; i++) /* Wait a bit. */
// __asm__("nop");
// __asm__("nop");
// gpio_clear(PORT_LED, PIN_LED); /* LED on */
// for (i = 0; i < 1000000; i++) /* Wait a bit. */
// __asm__("nop");
// __asm__("nop");
/* Using API function gpio_toggle(): */
gpio_toggle(PORT_LED, PIN_LED); /* LED on/off */
for (i = 0; i < 1000000; i++) /* Wait a bit. */
for (i = 0; i < 1000000; i++) { /* Wait a bit. */
__asm__("nop");
}
}
return 0;

View File

@@ -35,7 +35,7 @@ static void systick_setup(int freq)
{
systick_set_clocksource(STK_CSR_CLKSOURCE_AHB);
/* clear counter so it starts right away */
STK_CVR=0;
STK_CVR = 0;
systick_set_reload(rcc_core_frequency / freq);
systick_counter_enable();
@@ -79,5 +79,5 @@ int main(void)
systick_setup(8);
/* Do nothing in main loop */
while(1);
while (1);
}

View File

@@ -75,8 +75,9 @@ int main(void)
usart_send_blocking(USART1, '\r');
usart_send_blocking(USART1, '\n');
}
for (i = 0; i < 100000; i++) /* Wait a bit. */
for (i = 0; i < 100000; i++) { /* Wait a bit. */
__asm__("NOP");
}
}
return 0;

View File

@@ -26,10 +26,10 @@
#include <stddef.h>
#include <sys/types.h>
static ssize_t _iord(void *_cookie, char *_buf,size_t _n);
static ssize_t _iowr(void *_cookie,const char *_buf, size_t _n);
static ssize_t _iord(void *_cookie, char *_buf, size_t _n);
static ssize_t _iowr(void *_cookie, const char *_buf, size_t _n);
static ssize_t _iord(void *_cookie, char *_buf,size_t _n)
static ssize_t _iord(void *_cookie, char *_buf, size_t _n)
{
/* dont support reading now */
(void)_cookie;
@@ -38,7 +38,7 @@ static ssize_t _iord(void *_cookie, char *_buf,size_t _n)
return 0;
}
static ssize_t _iowr(void *_cookie,const char *_buf, size_t _n)
static ssize_t _iowr(void *_cookie, const char *_buf, size_t _n)
{
uint32_t dev = (uint32_t)_cookie;
@@ -51,7 +51,7 @@ static ssize_t _iowr(void *_cookie,const char *_buf, size_t _n)
}
static FILE* usart_setup(uint32_t dev)
static FILE *usart_setup(uint32_t dev)
{
/* Setup USART2 parameters. */
usart_set_baudrate(dev, 38400);
@@ -65,7 +65,7 @@ static FILE* usart_setup(uint32_t dev)
usart_enable(dev);
cookie_io_functions_t stub = { _iord, _iowr, NULL, NULL };
FILE *fp = fopencookie((void *)dev,"rw+",stub);
FILE *fp = fopencookie((void *)dev, "rw+", stub);
/* Do not buffer the serial line */
setvbuf(fp, NULL, _IONBF, 0);
return fp;
@@ -107,12 +107,13 @@ int main(void)
while (1) {
gpio_toggle(GPIOC, GPIO8); /* LED on/off */
fprintf(fp,"Pass: %d\n",c);
fprintf(fp, "Pass: %d\n", c);
c = (c == 200) ? 0 : c + 1; /* Increment c. */
for (i = 0; i < 1000000; i++) /* Wait a bit. */
for (i = 0; i < 1000000; i++) { /* Wait a bit. */
__asm__("NOP");
}
}
return 0;

View File

@@ -62,12 +62,12 @@ static void gpio_setup(void)
gpio_set_af(GPIOA, GPIO_AF7, GPIO2);
}
static uint64_t key[4] = {0x11223344,0x44556677,0x77889900, 0x99005522};
static uint64_t iv[4] = {0x01020304,0x02030405,0x09080706, 0x55245711};
static uint64_t key[4] = {0x11223344, 0x44556677, 0x77889900, 0x99005522};
static uint64_t iv[4] = {0x01020304, 0x02030405, 0x09080706, 0x55245711};
static uint8_t plaintext[8] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
static uint8_t ciphertext[8] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
static uint8_t plaintext2[8] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
static uint8_t plaintext[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
static uint8_t ciphertext[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
static uint8_t plaintext2[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
int main(void)
{
@@ -84,41 +84,42 @@ int main(void)
/* encode the plaintext message into ciphertext */
crypto_set_key(CRYPTO_KEY_128BIT,key);
crypto_set_key(CRYPTO_KEY_128BIT, key);
crypto_set_iv(iv); /* only in CBC or CTR mode */
crypto_set_datatype(CRYPTO_DATA_32BIT);
crypto_set_algorithm(ENCRYPT_DES_ECB);
crypto_start();
crypto_process_block((uint32_t*)plaintext,
(uint32_t*)ciphertext,
crypto_process_block((uint32_t *)plaintext,
(uint32_t *)ciphertext,
8 / sizeof(uint32_t));
crypto_stop();
/* decode the previously encoded message
from ciphertext to plaintext2 */
crypto_set_key(CRYPTO_KEY_128BIT,key);
crypto_set_key(CRYPTO_KEY_128BIT, key);
crypto_set_iv(iv); /* only in CBC or CTR mode */
crypto_set_datatype(CRYPTO_DATA_32BIT);
crypto_set_algorithm(DECRYPT_DES_ECB);
crypto_start();
crypto_process_block((uint32_t*)ciphertext,
(uint32_t*)plaintext2,
crypto_process_block((uint32_t *)ciphertext,
(uint32_t *)plaintext2,
8 / sizeof(uint32_t));
crypto_stop();
/* compare the two plaintexts if they are same */
iserr = 0;
for (i=0; i<8; i++)
{
if (plaintext[i] != plaintext2[i])
for (i = 0; i < 8; i++) {
if (plaintext[i] != plaintext2[i]) {
iserr = true;
}
}
if (iserr)
gpio_toggle(GPIOD,GPIO12); /* something went wrong. */
if (iserr) {
gpio_toggle(GPIOD, GPIO12); /* something went wrong. */
}
}
return 0;

View File

@@ -137,8 +137,8 @@ int main(void)
dac_setup();
/* green led for ticking */
gpio_mode_setup(LED_DISCO_GREEN_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, LED_DISCO_GREEN_PIN);
gpio_mode_setup(LED_DISCO_GREEN_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE,
LED_DISCO_GREEN_PIN);
while (1) {
uint16_t input_adc0 = read_adc_naiive(0);
@@ -148,9 +148,13 @@ int main(void)
uint16_t input_adc1 = read_adc_naiive(1);
printf("tick: %d: adc0= %u, target adc1=%d, adc1=%d\n",
j++, input_adc0, target, input_adc1);
gpio_toggle(LED_DISCO_GREEN_PORT, LED_DISCO_GREEN_PIN); /* LED on/off */
for (i = 0; i < 1000000; i++) /* Wait a bit. */
/* LED on/off */
gpio_toggle(LED_DISCO_GREEN_PORT, LED_DISCO_GREEN_PIN);
for (i = 0; i < 1000000; i++) { /* Wait a bit. */
__asm__("NOP");
}
}
return 0;

View File

@@ -64,12 +64,14 @@ int main(void)
/* Upon button press, blink more slowly. */
exti_line_state = GPIOA_IDR;
if ((exti_line_state & (1 << 0)) != 0) {
for (i = 0; i < 3000000; i++) /* Wait a bit. */
for (i = 0; i < 3000000; i++) { /* Wait a bit. */
__asm__("nop");
}
}
for (i = 0; i < 3000000; i++) /* Wait a bit. */
for (i = 0; i < 3000000; i++) { /* Wait a bit. */
__asm__("nop");
}
}
return 0;

View File

@@ -68,7 +68,8 @@ static void timer_setup(void)
timer_set_oc_mode(TIM2, TIM_OC1, TIM_OCM_TOGGLE);
timer_set_oc_value(TIM2, TIM_OC1, 500);
timer_disable_preload(TIM2);
/* Set the timer trigger output (for the DAC) to the channel 1 output compare */
/* Set the timer trigger output (for the DAC) to the channel 1 output
compare */
timer_set_master_mode(TIM2, TIM_CR2_MMS_COMPARE_OC1REF);
timer_enable_counter(TIM2);
}
@@ -86,8 +87,10 @@ static void dma_setup(void)
dma_set_peripheral_size(DMA1, DMA_STREAM5, DMA_SxCR_PSIZE_8BIT);
dma_enable_memory_increment_mode(DMA1, DMA_STREAM5);
dma_enable_circular_mode(DMA1, DMA_STREAM5);
dma_set_transfer_mode(DMA1, DMA_STREAM5, DMA_SxCR_DIR_MEM_TO_PERIPHERAL);
/* The register to target is the DAC1 8-bit right justified data register */
dma_set_transfer_mode(DMA1, DMA_STREAM5,
DMA_SxCR_DIR_MEM_TO_PERIPHERAL);
/* The register to target is the DAC1 8-bit right justified data
register */
dma_set_peripheral_address(DMA1, DMA_STREAM5, (uint32_t) &DAC_DHR8R1);
/* The array v[] is filled with the waveform data to be output */
dma_set_memory_address(DMA1, DMA_STREAM5, (uint32_t) waveform);
@@ -115,8 +118,7 @@ static void dac_setup(void)
void dma1_stream5_isr(void)
{
if (dma_get_interrupt_flag(DMA1, DMA_STREAM5, DMA_TCIF))
{
if (dma_get_interrupt_flag(DMA1, DMA_STREAM5, DMA_TCIF)) {
dma_clear_interrupt_flags(DMA1, DMA_STREAM5, DMA_TCIF);
/* Toggle PC1 just to keep aware of activity and frequency. */
gpio_toggle(GPIOC, GPIO1);
@@ -129,13 +131,18 @@ int main(void)
/* Fill the array with funky waveform data */
/* This is for dual channel 8-bit right aligned */
uint16_t i, x;
for (i=0; i<256; i++)
{
if (i<10) x=10;
else if (i<121) x=10+((i*i)>>7);
else if (i<170) x=i/2;
else if (i<246) x=i+(80-i/2);
else x=10;
for (i = 0; i < 256; i++) {
if (i < 10) {
x = 10;
} else if (i < 121) {
x = 10 + ((i*i) >> 7);
} else if (i < 170) {
x = i/2;
} else if (i < 246) {
x = i + (80 - i/2);
} else {
x = 10;
}
waveform[i] = x;
}
clock_setup();
@@ -144,9 +151,7 @@ int main(void)
dma_setup();
dac_setup();
while (1) {
}
while (1);
return 0;
}

View File

@@ -52,8 +52,9 @@ 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");
}
}
return 0;

View File

@@ -70,15 +70,15 @@ static char color[maxIter+1] = " .:++xxXXX%%%%%%################";
/* Main mandelbrot calculation */
static int iterate(float px, float py)
{
int it=0;
float x=0,y=0;
while(it<maxIter)
{
int it = 0;
float x = 0, y = 0;
while (it < maxIter) {
float nx = x*x;
float ny = y*y;
if( (nx + ny) > 4 )
if ((nx + ny) > 4) {
return it;
// Zn+1 = Zn^2 + P
}
/* Zn+1 = Zn^2 + P */
y = 2*x*y + py;
x = nx - ny + px;
it++;
@@ -88,12 +88,10 @@ static int iterate(float px, float py)
static void mandel(float cX, float cY, float scale)
{
int x,y;
for(x=-60;x<60;x++)
{
for(y=-50;y<50;y++)
{
int i = iterate(cX+x*scale, cY+y*scale);
int x, y;
for (x = -60; x < 60; x++) {
for (y = -50; y < 50; y++) {
int i = iterate(cX + x*scale, cY + y*scale);
usart_send_blocking(USART2, color[i]);
}
usart_send_blocking(USART2, '\r');
@@ -111,8 +109,8 @@ int main(void)
while (1) {
/* Blink the LED (PD12) on the board with each fractal drawn. */
gpio_toggle(GPIOD, GPIO12); /* LED on/off */
mandel(centerX,centerY,scale); /* draw mandelbrot */
gpio_toggle(GPIOD, GPIO12); /* LED on/off */
mandel(centerX, centerY, scale); /* draw mandelbrot */
/* Change scale and center */
centerX += 0.175f * scale;

View File

@@ -48,23 +48,24 @@ int main(void)
/* Manually: */
// GPIOD_BSRR = GPIO12; /* LED off */
// for (i = 0; i < 1000000; i++) /* Wait a bit. */
// __asm__("nop");
// __asm__("nop");
// GPIOD_BRR = GPIO12; /* LED on */
// for (i = 0; i < 1000000; i++) /* Wait a bit. */
// __asm__("nop");
// __asm__("nop");
/* Using API functions gpio_set()/gpio_clear(): */
// gpio_set(GPIOD, GPIO12); /* LED off */
// for (i = 0; i < 1000000; i++) /* Wait a bit. */
// __asm__("nop");
// __asm__("nop");
// gpio_clear(GPIOD, GPIO12); /* LED on */
// for (i = 0; i < 1000000; i++) /* Wait a bit. */
// __asm__("nop");
// __asm__("nop");
/* Using API function gpio_toggle(): */
gpio_toggle(GPIOD, GPIO12); /* LED on/off */
for (i = 0; i < 1000000; i++) /* Wait a bit. */
for (i = 0; i < 1000000; i++) { /* Wait a bit. */
__asm__("nop");
}
}
return 0;

View File

@@ -15,7 +15,6 @@
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include <libopencm3/cm3/common.h>
#include <libopencm3/stm32/rcc.h>
#include <libopencm3/stm32/gpio.h>
@@ -37,8 +36,9 @@ static void rng_setup(void)
/* Enable interupt */
/* Set the IE bit in the RNG_CR register. */
RNG_CR |= RNG_CR_IE;
/* Enable the random number generation by setting the RNGEN bit in the RNG_CR
register. This activates the analog part, the RNG_LFSR and the error detector.
/* Enable the random number generation by setting the RNGEN bit in
the RNG_CR register. This activates the analog part, the RNG_LFSR
and the error detector.
*/
RNG_CR |= RNG_CR_RNGEN;
}
@@ -46,43 +46,51 @@ static void rng_setup(void)
static void gpio_setup(void)
{
/* Setup onboard led */
gpio_mode_setup(GPIOD, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO12 | GPIO13);
gpio_mode_setup(GPIOD, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE,
GPIO12 | GPIO13);
}
/* Tried to folow the guidelines in the stm32f4 user manual.*/
static uint32_t random_int(void)
{
static uint32_t last_value=0;
static uint32_t new_value=0;
static uint32_t last_value;
static uint32_t new_value;
uint32_t error_bits = 0;
error_bits = RNG_SR_SEIS | RNG_SR_CEIS;
while (new_value==last_value) {
while (new_value == last_value) {
/* Check for error flags and if data is ready. */
if ( ((RNG_SR & error_bits) == 0) && ( (RNG_SR & RNG_SR_DRDY) == 1 ) )
new_value=RNG_DR;
if (((RNG_SR & error_bits) == 0) &&
((RNG_SR & RNG_SR_DRDY) == 1)) {
new_value = RNG_DR;
}
}
last_value=new_value;
last_value = new_value;
return new_value;
}
int main(void)
{
int i,j;
int i, j;
rcc_setup();
gpio_setup();
rng_setup();
while(1){
while (1) {
uint32_t rnd;
rnd = random_int();
for(i=0;i!=32;++i){
if ( (rnd & (1 << i))!=0 )
for (i = 0; i != 32; i++) {
if ((rnd & (1 << i)) != 0) {
gpio_set(GPIOD, GPIO12);
else
} else {
gpio_clear(GPIOD, GPIO12);
}
/* Delay */
for(j=0;j!=5000000;++j)
for (j = 0; j != 5000000; j++) {
__asm__("nop");
}
}
}
}

View File

@@ -27,22 +27,22 @@
#include <libopencm3/cm3/nvic.h>
#include <libopencm3/cm3/systick.h>
void msleep(uint32_t);
/* monotonically increasing number of milliseconds from reset
* overflows every 49 days if you're wondering
*/
volatile uint32_t system_millis;
/* Called when systick fires */
void sys_tick_handler(void) {
void sys_tick_handler(void)
{
system_millis++;
}
/* sleep for delay milliseconds */
void msleep(uint32_t delay) {
static void msleep(uint32_t delay)
{
uint32_t wake = system_millis + delay;
while (wake > system_millis) ;
while (wake > system_millis;
}
/* Set up a timer to create 1mS ticks. */
@@ -68,8 +68,8 @@ static void clock_setup(void)
static void gpio_setup(void)
{
/* Set GPIO11-15 (in GPIO port D) to 'output push-pull'. */
gpio_mode_setup(GPIOD, GPIO_MODE_OUTPUT,
GPIO_PUPD_NONE, GPIO11 | GPIO12 | GPIO13 | GPIO14 | GPIO15);
gpio_mode_setup(GPIOD, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE,
GPIO11 | GPIO12 | GPIO13 | GPIO14 | GPIO15);
}
int main(void)

View File

@@ -75,8 +75,9 @@ int main(void)
usart_send_blocking(USART2, '\r');
usart_send_blocking(USART2, '\n');
}
for (i = 0; i < 3000000; i++) /* Wait a bit. */
for (i = 0; i < 3000000; i++) { /* Wait a bit. */
__asm__("NOP");
}
}
return 0;

View File

@@ -53,7 +53,7 @@ static const struct usb_endpoint_descriptor comm_endp[] = {{
.bmAttributes = USB_ENDPOINT_ATTR_INTERRUPT,
.wMaxPacketSize = 16,
.bInterval = 255,
}};
} };
static const struct usb_endpoint_descriptor data_endp[] = {{
.bLength = USB_DT_ENDPOINT_SIZE,
@@ -69,7 +69,7 @@ static const struct usb_endpoint_descriptor data_endp[] = {{
.bmAttributes = USB_ENDPOINT_ATTR_BULK,
.wMaxPacketSize = 64,
.bInterval = 1,
}};
} };
static const struct {
struct usb_cdc_header_descriptor header;
@@ -121,7 +121,7 @@ static const struct usb_interface_descriptor comm_iface[] = {{
.extra = &cdcacm_functional_descriptors,
.extralen = sizeof(cdcacm_functional_descriptors)
}};
} };
static const struct usb_interface_descriptor data_iface[] = {{
.bLength = USB_DT_INTERFACE_SIZE,
@@ -135,7 +135,7 @@ static const struct usb_interface_descriptor data_iface[] = {{
.iInterface = 0,
.endpoint = data_endp,
}};
} };
static const struct usb_interface ifaces[] = {{
.num_altsetting = 1,
@@ -143,7 +143,7 @@ static const struct usb_interface ifaces[] = {{
}, {
.num_altsetting = 1,
.altsetting = data_iface,
}};
} };
static const struct usb_config_descriptor config = {
.bLength = USB_DT_CONFIGURATION_SIZE,
@@ -158,7 +158,7 @@ static const struct usb_config_descriptor config = {
.interface = ifaces,
};
static const char *usb_strings[] = {
static const char *const usb_strings[] = {
"Black Sphere Technologies",
"CDC-ACM Demo",
"DEMO",
@@ -167,8 +167,9 @@ static const char *usb_strings[] = {
/* Buffer to be used for control requests. */
uint8_t usbd_control_buffer[128];
static int cdcacm_control_request(usbd_device *usbd_dev, struct usb_setup_data *req, uint8_t **buf,
uint16_t *len, void (**complete)(usbd_device *usbd_dev, struct usb_setup_data *req))
static int cdcacm_control_request(usbd_device *usbd_dev,
struct usb_setup_data *req, uint8_t **buf, uint16_t *len,
void (**complete)(usbd_device *usbd_dev, struct usb_setup_data *req))
{
(void)complete;
(void)buf;
@@ -184,8 +185,9 @@ static int cdcacm_control_request(usbd_device *usbd_dev, struct usb_setup_data *
return 1;
}
case USB_CDC_REQ_SET_LINE_CODING:
if (*len < sizeof(struct usb_cdc_line_coding))
if (*len < sizeof(struct usb_cdc_line_coding)) {
return 0;
}
return 1;
}
@@ -200,8 +202,7 @@ static void cdcacm_data_rx_cb(usbd_device *usbd_dev, uint8_t ep)
int len = usbd_ep_read_packet(usbd_dev, 0x01, buf, 64);
if (len) {
while (usbd_ep_write_packet(usbd_dev, 0x82, buf, len) == 0)
;
while (usbd_ep_write_packet(usbd_dev, 0x82, buf, len) == 0);
}
gpio_toggle(GPIOC, GPIO5);
@@ -211,7 +212,8 @@ static void cdcacm_set_config(usbd_device *usbd_dev, uint16_t wValue)
{
(void)wValue;
usbd_ep_setup(usbd_dev, 0x01, USB_ENDPOINT_ATTR_BULK, 64, cdcacm_data_rx_cb);
usbd_ep_setup(usbd_dev, 0x01, USB_ENDPOINT_ATTR_BULK, 64,
cdcacm_data_rx_cb);
usbd_ep_setup(usbd_dev, 0x82, USB_ENDPOINT_ATTR_BULK, 64, NULL);
usbd_ep_setup(usbd_dev, 0x83, USB_ENDPOINT_ATTR_INTERRUPT, 16, NULL);
@@ -235,9 +237,13 @@ int main(void)
GPIO9 | GPIO11 | GPIO12);
gpio_set_af(GPIOA, GPIO_AF10, GPIO9 | GPIO11 | GPIO12);
usbd_dev = usbd_init(&otgfs_usb_driver, &dev, &config, usb_strings, 3, usbd_control_buffer, sizeof(usbd_control_buffer));
usbd_dev = usbd_init(&otgfs_usb_driver, &dev, &config,
usb_strings, 3,
usbd_control_buffer, sizeof(usbd_control_buffer));
usbd_register_set_config_callback(usbd_dev, cdcacm_set_config);
while (1)
while (1) {
usbd_poll(usbd_dev);
}
}

View File

@@ -38,7 +38,7 @@ static volatile struct state_t state;
int _write(int file, char *ptr, int len);
__attribute__((always_inline)) static inline void __WFI(void)
static inline __attribute__((always_inline)) void __WFI(void)
{
__asm volatile ("wfi");
}
@@ -46,8 +46,11 @@ __attribute__((always_inline)) static inline void __WFI(void)
static void gpio_setup(void)
{
/* green led for ticking, blue for button feedback */
gpio_mode_setup(LED_DISCO_GREEN_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, LED_DISCO_GREEN_PIN);
gpio_mode_setup(LED_DISCO_BLUE_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, LED_DISCO_BLUE_PIN);
gpio_mode_setup(LED_DISCO_GREEN_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE,
LED_DISCO_GREEN_PIN);
gpio_mode_setup(LED_DISCO_BLUE_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE,
LED_DISCO_BLUE_PIN);
/* Setup GPIO pins for USART2 transmit. */
gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO2);
@@ -76,7 +79,8 @@ static void setup_buttons(void)
/* Enable EXTI0 interrupt. */
nvic_enable_irq(BUTTON_DISCO_USER_NVIC);
gpio_mode_setup(BUTTON_DISCO_USER_PORT, GPIO_MODE_INPUT, GPIO_PUPD_NONE, BUTTON_DISCO_USER_PIN);
gpio_mode_setup(BUTTON_DISCO_USER_PORT, GPIO_MODE_INPUT, GPIO_PUPD_NONE,
BUTTON_DISCO_USER_PIN);
/* Configure the EXTI subsystem. */
exti_select_source(BUTTON_DISCO_USER_EXTI, BUTTON_DISCO_USER_PORT);
@@ -128,7 +132,7 @@ int _write(int file, char *ptr, int len)
static void setup_button_press_timer(void)
{
timer_reset(TIMER_BUTTON_PRESS);
timer_set_prescaler(TIMER_BUTTON_PRESS, 3999); // 4Mhz/1000hz - 1
timer_set_prescaler(TIMER_BUTTON_PRESS, 3999); /* 4Mhz/1000hz - 1 */
timer_set_period(TIMER_BUTTON_PRESS, 0xffff);
timer_enable_counter(TIMER_BUTTON_PRESS);
}
@@ -151,15 +155,15 @@ static int setup_rtc(void)
rcc_rtc_select_clock(RCC_CSR_RTCSEL_LSE);
/* ?! Stdperiph examples don't turn this on until _afterwards_ which
* simply doesn't work. It must be on at least to be able to configure it */
* simply doesn't work. It must be on at least to be able to
* configure it */
RCC_CSR |= RCC_CSR_RTCEN;
rtc_unlock();
/* enter init mode */
RTC_ISR |= RTC_ISR_INIT;
while ((RTC_ISR & RTC_ISR_INITF) == 0)
;
while ((RTC_ISR & RTC_ISR_INITF) == 0);
/* set synch prescaler, using defaults for 1Hz out */
uint32_t sync = 255;
@@ -190,8 +194,7 @@ static int setup_rtc_wakeup(int period)
RTC_CR &= ~RTC_CR_WUTE;
/* Wait until we can write */
while ((RTC_ISR & RTC_ISR_WUTWF) == 0)
;
while ((RTC_ISR & RTC_ISR_WUTWF) == 0);
RTC_WUTR = period - 1;
@@ -210,12 +213,13 @@ static int setup_rtc_wakeup(int period)
/* done with rtc registers, lock them again */
rtc_lock();
nvic_enable_irq(NVIC_RTC_WKUP_IRQ);
// EXTI configuration
/* EXTI configuration */
/* Configure the EXTI subsystem. */
// not needed, this chooses ports exti_select_source(EXTI20, BUTTON_DISCO_USER_PORT);
/* not needed, this chooses ports
exti_select_source(EXTI20, BUTTON_DISCO_USER_PORT);
*/
exti_set_trigger(EXTI20, EXTI_TRIGGER_RISING);
exti_enable_request(EXTI20);
return 0;

View File

@@ -46,14 +46,16 @@ static void clock_setup(void)
/* And timers. */
rcc_periph_clock_enable(RCC_TIM6);
rcc_periph_clock_enable(RCC_TIM7);
}
static void gpio_setup(void)
{
/* green led for ticking, blue for button feedback */
gpio_mode_setup(LED_DISCO_GREEN_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, LED_DISCO_GREEN_PIN);
gpio_mode_setup(LED_DISCO_BLUE_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, LED_DISCO_BLUE_PIN);
gpio_mode_setup(LED_DISCO_GREEN_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE,
LED_DISCO_GREEN_PIN);
gpio_mode_setup(LED_DISCO_BLUE_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE,
LED_DISCO_BLUE_PIN);
/* Setup GPIO pins for USART2 transmit. */
gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO2);
@@ -117,7 +119,7 @@ void BUTTON_DISCO_USER_isr(void)
}
}
static volatile int t6ovf = 0;
static volatile int t6ovf;
void tim6_isr(void)
{
@@ -136,13 +138,13 @@ void tim6_isr(void)
static void setup_tim6(void)
{
timer_reset(TIM6);
// 24Mhz / 10khz -1.
timer_set_prescaler(TIM6, 2399); // 24Mhz/10000hz - 1
// 10khz for 10 ticks = 1 khz overflow = 1ms overflow interrupts
/* 24Mhz / 10khz -1. */
timer_set_prescaler(TIM6, 2399); /* 24Mhz/10000hz - 1 */
/* 10khz for 10 ticks = 1 khz overflow = 1ms overflow interrupts */
timer_set_period(TIM6, 10);
nvic_enable_irq(NVIC_TIM6_IRQ);
timer_enable_update_event(TIM6); // default at reset!
timer_enable_update_event(TIM6); /* default at reset! */
timer_enable_irq(TIM6, TIM_DIER_UIE);
timer_enable_counter(TIM6);
}
@@ -153,7 +155,7 @@ static void setup_tim6(void)
static void setup_tim7(void)
{
timer_reset(TIM7);
timer_set_prescaler(TIM7, 23999); // 24Mhz/1000hz - 1
timer_set_prescaler(TIM7, 23999); /* 24Mhz/1000hz - 1 */
timer_set_period(TIM7, 0xffff);
timer_enable_counter(TIM7);
}
@@ -163,7 +165,8 @@ static void setup_buttons(void)
/* Enable EXTI0 interrupt. */
nvic_enable_irq(BUTTON_DISCO_USER_NVIC);
gpio_mode_setup(BUTTON_DISCO_USER_PORT, GPIO_MODE_INPUT, GPIO_PUPD_NONE, BUTTON_DISCO_USER_PIN);
gpio_mode_setup(BUTTON_DISCO_USER_PORT, GPIO_MODE_INPUT, GPIO_PUPD_NONE,
BUTTON_DISCO_USER_PIN);
/* Configure the EXTI subsystem. */
exti_select_source(BUTTON_DISCO_USER_EXTI, BUTTON_DISCO_USER_PORT);

View File

@@ -46,23 +46,24 @@ int main(void)
/* Manually: */
// GPIOD_BSRR = GPIO6; /* LED off */
// for (i = 0; i < 1000000; i++) /* Wait a bit. */
// __asm__("nop");
// __asm__("nop");
// GPIOD_BRR = GPIO6; /* LED on */
// for (i = 0; i < 1000000; i++) /* Wait a bit. */
// __asm__("nop");
// __asm__("nop");
/* Using API functions gpio_set()/gpio_clear(): */
// gpio_set(GPIOD, GPIO6); /* LED off */
// for (i = 0; i < 1000000; i++) /* Wait a bit. */
// __asm__("nop");
// __asm__("nop");
// gpio_clear(GPIOD, GPIO6); /* LED on */
// for (i = 0; i < 1000000; i++) /* Wait a bit. */
// __asm__("nop");
// __asm__("nop");
/* Using API function gpio_toggle(): */
gpio_toggle(GPIOB, GPIO6); /* LED on/off */
for (i = 0; i < 1000000; i++) /* Wait a bit. */
for (i = 0; i < 1000000; i++) { /* Wait a bit. */
__asm__("nop");
}
}
return 0;

View File

@@ -84,8 +84,9 @@ int main(void)
usart_send_blocking(USART2, '\r');
usart_send_blocking(USART2, '\n');
}
for (i = 0; i < 100000; i++) /* Wait a bit. */
for (i = 0; i < 100000; i++) { /* Wait a bit. */
__asm__("NOP");
}
}
return 0;

View File

@@ -76,8 +76,9 @@ int main(void)
usart_send_blocking(USART2, '\r');
usart_send_blocking(USART2, '\n');
}
for (i = 0; i < 100000; i++) /* Wait a bit. */
for (i = 0; i < 100000; i++) { /* Wait a bit. */
__asm__("NOP");
}
}
return 0;