switched to arduino framework because libopencm3 is too hard :-(

master
loooph 2021-08-23 20:20:58 +02:00
parent 21e0c3a7d6
commit 125a548ddf
4 changed files with 63 additions and 173 deletions

59
.ccls
View File

@ -1,20 +1,57 @@
clang
%c -Wimplicit-function-declaration -Wmissing-prototypes -Wstrict-prototypes -Os -ffunction-sections -fdata-sections -Wall -Wextra -Wredundant-decls -Wshadow -fno-common -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16
%cpp -fno-rtti -fno-exceptions -Os -ffunction-sections -fdata-sections -Wall -Wextra -Wredundant-decls -Wshadow -fno-common -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16
%c -std=gnu11 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -Os -mcpu=cortex-m4 -mthumb -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500
%cpp -std=gnu++14 -fno-threadsafe-statics -fno-rtti -fno-exceptions -fno-use-cxa-atexit -mfpu=fpv4-sp-d16 -mfloat-abi=hard -Os -mcpu=cortex-m4 -mthumb -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500
-I/home/loooph/projects/synth/include
-I/home/loooph/projects/synth/src
-I/home/loooph/.platformio/packages/framework-libopencm3
-I/home/loooph/.platformio/packages/framework-libopencm3/include
-I/home/loooph/.platformio/packages/toolchain-gccarmnoneeabi@1.70201.0/arm-none-eabi/include/c++/7.2.1
-I/home/loooph/.platformio/packages/toolchain-gccarmnoneeabi@1.70201.0/arm-none-eabi/include/c++/7.2.1/arm-none-eabi
-I/home/loooph/.platformio/packages/toolchain-gccarmnoneeabi@1.70201.0/lib/gcc/arm-none-eabi/7.2.1/include-fixed
-I/home/loooph/.platformio/packages/toolchain-gccarmnoneeabi@1.70201.0/lib/gcc/arm-none-eabi/7.2.1/include
-I/home/loooph/.platformio/packages/toolchain-gccarmnoneeabi@1.70201.0/arm-none-eabi/include
-I/home/loooph/.platformio/packages/framework-arduinoststm32/cores/arduino/avr
-I/home/loooph/.platformio/packages/framework-arduinoststm32/cores/arduino/stm32
-I/home/loooph/.platformio/packages/framework-arduinoststm32/cores/arduino/stm32/LL
-I/home/loooph/.platformio/packages/framework-arduinoststm32/cores/arduino/stm32/usb
-I/home/loooph/.platformio/packages/framework-arduinoststm32/cores/arduino/stm32/OpenAMP
-I/home/loooph/.platformio/packages/framework-arduinoststm32/cores/arduino/stm32/usb/hid
-I/home/loooph/.platformio/packages/framework-arduinoststm32/cores/arduino/stm32/usb/cdc
-I/home/loooph/.platformio/packages/framework-arduinoststm32/system/Drivers/STM32F3xx_HAL_Driver/Inc
-I/home/loooph/.platformio/packages/framework-arduinoststm32/system/Drivers/STM32F3xx_HAL_Driver/Src
-I/home/loooph/.platformio/packages/framework-arduinoststm32/system/STM32F3xx
-I/home/loooph/.platformio/packages/framework-arduinoststm32/system/Middlewares/ST/STM32_USB_Device_Library/Core/Inc
-I/home/loooph/.platformio/packages/framework-arduinoststm32/system/Middlewares/ST/STM32_USB_Device_Library/Core/Src
-I/home/loooph/.platformio/packages/framework-arduinoststm32/system/Middlewares/OpenAMP
-I/home/loooph/.platformio/packages/framework-arduinoststm32/system/Middlewares/OpenAMP/open-amp/lib/include
-I/home/loooph/.platformio/packages/framework-arduinoststm32/system/Middlewares/OpenAMP/libmetal/lib/include
-I/home/loooph/.platformio/packages/framework-arduinoststm32/system/Middlewares/OpenAMP/virtual_driver
-I/home/loooph/.platformio/packages/framework-cmsis/CMSIS/Core/Include
-I/home/loooph/.platformio/packages/framework-arduinoststm32/system/Drivers/CMSIS/Device/ST/STM32F3xx/Include
-I/home/loooph/.platformio/packages/framework-arduinoststm32/system/Drivers/CMSIS/Device/ST/STM32F3xx/Source/Templates/gcc
-I/home/loooph/.platformio/packages/framework-cmsis/CMSIS/DSP/Include
-I/home/loooph/.platformio/packages/framework-cmsis/CMSIS/DSP/PrivateInclude
-I/home/loooph/.platformio/packages/framework-arduinoststm32/cores/arduino
-I/home/loooph/.platformio/packages/framework-arduinoststm32/variants/STM32F3xx/F302R(6-8)T
-I/home/loooph/.platformio/packages/framework-arduinoststm32/libraries/CMSIS_DSP/src
-I/home/loooph/.platformio/packages/framework-arduinoststm32/libraries/EEPROM/src
-I/home/loooph/.platformio/packages/framework-arduinoststm32/libraries/IWatchdog/src
-I/home/loooph/.platformio/packages/framework-arduinoststm32/libraries/Keyboard/src
-I/home/loooph/.platformio/packages/framework-arduinoststm32/libraries/Mouse/src
-I/home/loooph/.platformio/packages/framework-arduinoststm32/libraries/SPI/src
-I/home/loooph/.platformio/packages/framework-arduinoststm32/libraries/Servo/src
-I/home/loooph/.platformio/packages/framework-arduinoststm32/libraries/SoftwareSerial/src
-I/home/loooph/.platformio/packages/framework-arduinoststm32/libraries/SrcWrapper/src
-I/home/loooph/.platformio/packages/framework-arduinoststm32/libraries/Wire/src
-I/home/loooph/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/9.2.1
-I/home/loooph/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/9.2.1/arm-none-eabi
-I/home/loooph/.platformio/packages/toolchain-gccarmnoneeabi/lib/gcc/arm-none-eabi/9.2.1/include-fixed
-I/home/loooph/.platformio/packages/toolchain-gccarmnoneeabi/lib/gcc/arm-none-eabi/9.2.1/include
-I/home/loooph/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include
-I/home/loooph/.platformio/packages/tool-unity
-DPLATFORMIO=50101
-DSTM32F302x8
-DSTM32F3
-DF_CPU=72000000L
-DSTM32F3xx
-DARDUINO=10808
-DARDUINO_ARCH_STM32
-DARDUINO_NUCLEO_F302R8
-DBOARD_NAME="NUCLEO_F302R8"
-DHAL_UART_MODULE_ENABLED
-DUSE_FULL_LL_DRIVER
-DVARIANT_H="variant_NUCLEO_F302R8.h"

View File

@ -11,4 +11,4 @@
[env:nucleo_f302r8]
platform = ststm32
board = nucleo_f302r8
framework = libopencm3
framework = arduino

View File

@ -1,161 +0,0 @@
/*
* This file is part of the libopencm3 project.
*
* Copyright (C) 2014 Karl Palsson <karlp@tweak.net.au>
*
* 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 <errno.h>
#include <stdio.h>
#include <unistd.h>
#include <libopencm3/cm3/nvic.h>
#include <libopencm3/stm32/adc.h>
#include <libopencm3/stm32/dac.h>
#include <libopencm3/stm32/gpio.h>
#include <libopencm3/stm32/rcc.h>
#include <libopencm3/stm32/usart.h>
#define LED_DISCO_GREEN_PORT GPIOD
#define LED_DISCO_GREEN_PIN GPIO12
#define USART_CONSOLE USART2
int _write(int file, char *ptr, int len);
static void clock_setup(void)
{
rcc_clock_setup_hsi(&rcc_hsi_configs[RCC_CLOCK_HSI_64MHZ]);
/* Enable GPIOD clock for LED & USARTs. */
rcc_periph_clock_enable(RCC_GPIOD);
rcc_periph_clock_enable(RCC_GPIOA);
/* Enable clocks for USART2 and dac */
rcc_periph_clock_enable(RCC_USART2);
rcc_periph_clock_enable(RCC_DAC1);
/* And ADC*/
rcc_periph_clock_enable(RCC_ADC12);
}
static void usart_setup(void)
{
/* Setup GPIO pins for USART2 transmit. */
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);
usart_set_baudrate(USART_CONSOLE, 115200);
usart_set_databits(USART_CONSOLE, 8);
usart_set_stopbits(USART_CONSOLE, USART_STOPBITS_1);
usart_set_mode(USART_CONSOLE, USART_MODE_TX);
usart_set_parity(USART_CONSOLE, USART_PARITY_NONE);
usart_set_flow_control(USART_CONSOLE, USART_FLOWCONTROL_NONE);
/* Finally enable the USART. */
usart_enable(USART_CONSOLE);
}
/**
* Use USART_CONSOLE as a console.
* This is a syscall for newlib
* @param file
* @param ptr
* @param len
* @return
*/
int _write(int file, char *ptr, int len)
{
int i;
if (file == STDOUT_FILENO || file == STDERR_FILENO) {
for (i = 0; i < len; i++) {
if (ptr[i] == '\n') {
usart_send_blocking(USART_CONSOLE, '\r');
}
usart_send_blocking(USART_CONSOLE, ptr[i]);
}
return i;
}
errno = EIO;
return -1;
}
static void adc_setup(void)
{
gpio_mode_setup(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO0);
gpio_mode_setup(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO1);
adc_power_off(ADC1);
adc_set_clk_prescale(ADC1, ADC_CCR_CKMODE_DIV2);
adc_set_sample_time_on_all_channels(ADC1, ADC_SMPR_SMP_61DOT5CYC);
adc_power_on(ADC1);
}
static void dac_setup(void)
{
gpio_mode_setup(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO5);
dac_disable(CHANNEL_1);
dac_disable_waveform_generation(CHANNEL_1);
dac_enable(CHANNEL_1);
dac_set_trigger_source(DAC_CR_TSEL2_SW);
}
static uint16_t read_adc_naiive(uint8_t channel)
{
uint8_t channel_array[16];
channel_array[0] = channel;
adc_set_regular_sequence(ADC1, 1, channel_array);
adc_start_conversion_regular(ADC1);
while (!adc_eoc(ADC1));
uint16_t reg16 = adc_read_regular(ADC1);
return reg16;
}
int main(void)
{
int i;
int j = 0;
clock_setup();
usart_setup();
printf("hi guys!\n");
adc_setup();
dac_setup();
/* green led for ticking */
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);
uint16_t target = input_adc0 / 2;
dac_load_data_buffer_single(target, RIGHT12, CHANNEL_2);
dac_software_trigger(CHANNEL_1);
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);
/* 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;
}

14
src/main.cpp Normal file
View File

@ -0,0 +1,14 @@
#include <Arduino.h>
constexpr unsigned SWITCH_DELAY_MS = 2000;
void setup() {
delay(3000);
}
void loop() {
int val = analogRead(A0);
delay(20);
analogWrite(PA_4, val);
delay(20);
}