Ankieta: Jaki system operacyjnym preferujesz
Ankieta jest zamknięta.
Windows 60.78% 31 60.78%
Linux 31.37% 16 31.37%
MAC/OS 7.84% 4 7.84%
Inny 0% 0 0%
Razem 51 głosów 100%
*) odpowiedź wybrana przez Ciebie [Wyniki ankiety]

Odpowiedz 
 
Ocena wątku:
  • 1 Głosów - 5 Średnio
  • 1
  • 2
  • 3
  • 4
  • 5
Programowanie ARM, nauka, środowiska programistyczne IDE
SP6VGX Offline
Tomek
***

Liczba postów: 108
Dołączył: 03-11-2012
Post: #63
RE: Programowanie ARM, nauka, środowiska programistyczne IDE
(06-07-2016 13:37)QRP73 napisał(a):  Przeczytalem caly watek i powiem tak, duzo postow malo konkretow.
Mam DiscoverySTM32F429I, kwarc 8Mhz. Jak ustawic CoreClock za pomoca funkcji CMSIS na 168Mhz ?
Bede wdzieczny za kod z opisem co i dlaczego. Moze jakis autorski SysemInit().
Ogladam kod funkcji SystemInit i trudno sie w tym polapac.

No i wlasnie kolega Marek potwierdzil to o czym pisze... zaczyna sie problem bo brak wiadomosci o tym jak to poustawiac.

No i teraz w sumie pytanie czy lecimy z kodem - czy zrobic opis jak sie ustawia zegary ?


Natomiast co do migania LED-em to przykladowy kod z libopencm3. Jednak trudno to porownac - tutaj nie wymagane jest grzebanie w jakichkolwiek innych plkach do main.c wystarczy dolinkowac bibloteke... ale tego nie zrobi sie kreatorem...

Kod:
/*
* This file is part of the libopencm3 project.
*
* Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
* Copyright (C) 2011 Damjan Marion <damjan.marion@gmail.com>
* Copyright (C) 2011 Mark Panajotovic <marko@electrontube.org>
* Copyright (C) 2015 Piotr Esden-Tempski <piotr@esden.net>
*
* 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 <http://www.gnu.org/licenses/>.
*/

#include <libopencm3/stm32/rcc.h>
#include <libopencm3/stm32/gpio.h>

/* Set STM32 to 168 MHz. */
static void clock_setup(void)
{
    rcc_clock_setup_hse_3v3(&rcc_hse_8mhz_3v3[RCC_CLOCK_3V3_168MHZ]);

    /* Enable GPIOG clock. */
    rcc_periph_clock_enable(RCC_GPIOG);
}

static void gpio_setup(void)
{
    /* Set GPIO13-14 (in GPIO port G) to 'output push-pull'. */
    gpio_mode_setup(GPIOG, GPIO_MODE_OUTPUT,
            GPIO_PUPD_NONE, GPIO13 | GPIO14);
}

int main(void)
{
    int i;

    clock_setup();
    gpio_setup();

    /* Set two LEDs for wigwag effect when toggling. */
    gpio_set(GPIOG, GPIO13);

    /* Blink the LEDs (PG13 and PG14) on the board. */
    while (1) {
        /* Toggle LEDs. */
        gpio_toggle(GPIOG, GPIO13 | GPIO14);
        for (i = 0; i < 6000000; i++) { /* Wait a bit. */
            __asm__("nop");
        }
    }

    return 0;
}

kolejny przyklad z biblioteki z uzyciem systick dla funkcji opoznienia:

Kod:
/*
* This file is part of the libopencm3 project.
*
* Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
* Copyright (C) 2011 Damjan Marion <damjan.marion@gmail.com>
* Copyright (C) 2011 Mark Panajotovic <marko@electrontube.org>
* Copyright (C) 2013 Chuck McManis <cmcmanis@mcmanis.com>
* Copyright (C) 2015 Piotr Esden-Tempski <piotr@esden.net>
*
* 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 <http://www.gnu.org/licenses/>.
*/

/* This version derived from fancy blink */

#include <libopencm3/stm32/rcc.h>
#include <libopencm3/stm32/gpio.h>
#include <libopencm3/cm3/nvic.h>
#include <libopencm3/cm3/systick.h>

/* 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)
{
    system_millis++;
}

/* sleep for delay milliseconds */
static void msleep(uint32_t delay)
{
    uint32_t wake = system_millis + delay;
    while (wake > system_millis);
}

/*
* systick_setup(void)
*
* This function sets up the 1khz "system tick" count. The SYSTICK counter is a
* standard feature of the Cortex-M series.
*/
static void systick_setup(void)
{
    /* clock rate / 1000 to get 1mS interrupt rate */
    systick_set_reload(168000);
    systick_set_clocksource(STK_CSR_CLKSOURCE_AHB​);
    systick_counter_enable();
    /* this done last */
    systick_interrupt_enable();
}

/* Set STM32 system clock to 168 MHz. */
static void clock_setup(void)
{
    rcc_clock_setup_hse_3v3(&rcc_hse_8mhz_3v3[RCC_CLOCK_3V3_168MHZ]);

    /* Enable GPIOG clock. */
    rcc_periph_clock_enable(RCC_GPIOG);
}

static void gpio_setup(void)
{
    /* Set GPIO13-14 (in GPIO port G) to 'output push-pull'. */
    gpio_mode_setup(GPIOG, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE,
            GPIO13 | GPIO14);
}

int main(void)
{
    clock_setup();
    gpio_setup();
    systick_setup();

    /* Set two LEDs for wigwag effect when toggling. */
    gpio_set(GPIOG, GPIO13);

    /* Blink the LEDs (PG13 and PG14) on the board. */
    while (1) {
        gpio_toggle(GPIOG, GPIO13 | GPIO14);
        msleep(100);
    }

    return 0;
}

tylko nie wiem czy jest sens przeklejac kody ktore dostepne sa tutaj:
https://github.com/libopencm3/libopencm3...s/stm32/f4

i jeszcze jakis przyklad z aktualnych moich testow libopencm3... fragment obslugi UART pod ktory podpiety jest GPS...

Kod:
void GPS_HardwareInit(void)
{
    /**************************************************​******************************
     *  Enable Clock
     **************************************************​******************************/

    rcc_periph_clock_enable(RCC_GPIOC);
    rcc_periph_clock_enable(RCC_USART3);


    /**************************************************​******************************
     *  Configure GPIO
     **************************************************​******************************/

    /* PC10 - TX, PC11 - RX */
    gpio_mode_setup(GPIOC, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO10 | GPIO11);

    /* PC12 - Reset */
    gpio_mode_setup(GPIOC, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO12);

    /* PC11, PC12 - Out OpenDrain */
    gpio_set_output_options(GPIOC, GPIO_OTYPE_OD, GPIO_OSPEED_25MHZ, GPIO11 | GPIO12);

    /* AF7 - USART3 */
    gpio_set_af(GPIOC, GPIO_AF7, GPIO10 | GPIO11);

    /* PC12 - Reset Off */
    gpio_set(GPIOC, GPIO12);

    /**************************************************​******************************
     *  Configure USART
     **************************************************​******************************/

    usart_set_baudrate(USART3, 9600);
    usart_set_databits(USART3, 8);
    usart_set_stopbits(USART3, USART_STOPBITS_1);
    usart_set_mode(USART3, USART_MODE_RX);
    usart_set_parity(USART3, USART_PARITY_NONE);
    usart_set_flow_control(USART3, USART_FLOWCONTROL_NONE);


    /**************************************************​******************************
     *  USART IRQ
     **************************************************​******************************/
    nvic_set_priority(NVIC_USART3_IRQ, 0);
    nvic_enable_irq(NVIC_USART3_IRQ);
    usart_enable_rx_interrupt(USART3);


    /**************************************************​******************************
     *  Enable USART
     **************************************************​******************************/

    usart_enable(USART3);
}

void usart3_isr(void)
{
    if (((USART_CR1(USART3) & USART_CR1_RXNEIE) != 0) && ((USART_SR(USART3) & USART_SR_RXNE) != 0))
    {
        GPS_ParseChar(usart_recv(USART3));

        if (GPSNmea.msg_available)
        {
            GPS_ParseNMEA();
            GPSNmea.msg_available = false;
        }
    }
}

Tomek - SP6VGX (SWL: SP-0316-JG)
QTH: Warszawa, LOKATOR: KO02NG
http://www.sp6vgx.pl/
(Ten post był ostatnio modyfikowany: 06-07-2016 15:00 przez SP6VGX.)
06-07-2016 15:00
Znajdź wszystkie posty użytkownika Odpowiedz cytując ten post
Odpowiedz 


Wiadomości w tym wątku
RE: Programowanie ARM, nauka, środowiska programistyczne IDE - SP6VGX - 06-07-2016 15:00

Skocz do:


Użytkownicy przeglądający ten wątek: 3 gości