[Stylecheck] F0, F1, F4
There are remaining C99 comments.
This commit is contained in:
@@ -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,9 +123,10 @@ 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;
|
||||
}
|
||||
|
||||
@@ -63,13 +63,15 @@ int main(void)
|
||||
|
||||
/* Upon button press, blink more slowly. */
|
||||
if (gpio_get(GPIOA, GPIO0)) {
|
||||
for (i = 0; i < 300000; i++) /* Wait a bit. */
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -65,9 +65,10 @@ int main(void)
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
@@ -75,9 +75,10 @@ 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;
|
||||
}
|
||||
|
||||
@@ -111,9 +111,10 @@ int main(void)
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -111,15 +111,16 @@ int main(void)
|
||||
|
||||
/* 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)
|
||||
if (iserr) {
|
||||
gpio_toggle(GPIOD, GPIO12); /* something went wrong. */
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -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,10 +148,14 @@ 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;
|
||||
}
|
||||
|
||||
@@ -64,13 +64,15 @@ 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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -52,9 +52,10 @@ 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;
|
||||
}
|
||||
|
||||
@@ -72,13 +72,13 @@ static int iterate(float px, float py)
|
||||
{
|
||||
int it = 0;
|
||||
float x = 0, y = 0;
|
||||
while(it<maxIter)
|
||||
{
|
||||
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++;
|
||||
@@ -89,10 +89,8 @@ 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++)
|
||||
{
|
||||
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]);
|
||||
}
|
||||
|
||||
@@ -63,9 +63,10 @@ int main(void)
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
@@ -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,21 +46,25 @@ 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) {
|
||||
/* Check for error flags and if data is ready. */
|
||||
if ( ((RNG_SR & error_bits) == 0) && ( (RNG_SR & RNG_SR_DRDY) == 1 ) )
|
||||
if (((RNG_SR & error_bits) == 0) &&
|
||||
((RNG_SR & RNG_SR_DRDY) == 1)) {
|
||||
new_value = RNG_DR;
|
||||
}
|
||||
}
|
||||
last_value = new_value;
|
||||
return new_value;
|
||||
}
|
||||
@@ -72,17 +76,21 @@ int main(void)
|
||||
rcc_setup();
|
||||
gpio_setup();
|
||||
rng_setup();
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -75,9 +75,10 @@ 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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -61,9 +61,10 @@ int main(void)
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
@@ -84,9 +84,10 @@ 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;
|
||||
}
|
||||
|
||||
@@ -76,9 +76,10 @@ 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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user