Changing frequency of generator stm32f103

Hi
I can change the frequency by changing manually value if " f " but cant do that using the buttons, how to fix it ?

#include <libmaple/dma.h>
#include <LiquidCrystal.h>
//LiquidCrystal lcd(PB9,PA11,PB15,PB14,PB13,PB12);
LiquidCrystal lcd(PB9, PC14, PB15, PB14, PB13, PB12);
#define SAMPLES_TX 64
#define dt (1.0/SAMPLES_TX)
#define F(x)(0.5*(1+sin(TWO_PI*x)))

HardwareTimer Timer_4(4);
HardwareTimer Timer_2(2);
HardwareTimer Timer_3(3);
int f;
int Sound_schem = 0;
int Faza_b;
unsigned int micros_1, micros_2;
unsigned int millis_1, millis_2;
int adc_data_1, adc_data_2;
int val_TX[SAMPLES_TX];

const int LED_LCD = PA8;
int V_tic = 0;
int V_bat = 0;
int MENU_index = 1;

#define eeprom_adr 1
#define num_prof 4
#pragma pack(push, 1);
struct strMem
{
  float amp_TX[num_prof];
  int F_TX[num_prof];
  int Threshold[num_prof];
  int Comp_Phase[num_prof];
  int need_phase[num_prof];
  int Adjustment_Phase[num_prof];

  int Prof;
} Mem;

const int OUT_TX = PB8;
dma_tube_config dma_cfg_TX, dma_cfg2;
timer_dev *dev_TX = PIN_MAP[OUT_TX].timer_device;//Timer4
uint8 cc_channel_TX = PIN_MAP[OUT_TX].timer_channel;//Channel3

void TX_conf()
{
  Timer_4.pause();
  Timer_3.pause();
  Timer_3.setCount(0);
  Timer_4.setCount(0);

  set_sin_tab(Mem.Comp_Phase[Mem.Prof], Mem.amp_TX[Mem.Prof]);


  timer_dma_set_base_addr(dev_TX,  TIMER_DMA_BASE_CCR3);
  timer_dma_set_burst_len(dev_TX, 1);
  timer_dma_enable_req(dev_TX, cc_channel_TX);
  // timer_set_reload(dev_TX, Mem.F_TX[Mem.Prof] );//++++++++++++++++++++++++++

  timer_set_prescaler(dev_TX, 0);
  Timer_4.setMasterModeTrGo(TIMER_CR2_MMS_COMPARE_OC3REF);

  dma_init(DMA1);
  dma_disable(DMA1, DMA_CH5);
  dma_cfg_TX.tube_dst = &(dev_TX->regs.gen->DMAR);
  dma_cfg_TX.tube_dst_size = DMA_SIZE_32BITS;
  dma_cfg_TX.tube_src = val_TX;
  dma_cfg_TX.tube_src_size = DMA_SIZE_32BITS;
  dma_cfg_TX.tube_nr_xfers = SAMPLES_TX;
  dma_cfg_TX.tube_flags = DMA_CFG_SRC_INC | DMA_CFG_CIRC | DMA_CFG_CMPLT_IE;
  dma_cfg_TX.tube_req_src = DMA_REQ_SRC_TIM4_CH3;
  dma_cfg_TX.target_data = 0;
  dma_tube_cfg(DMA1, DMA_CH5, &dma_cfg_TX);
  dma_enable(DMA1, DMA_CH5);



  Timer_3.setPrescaleFactor(1);
  Timer_3.setOverflow((SAMPLES_TX / 2) - 1);
  timer_oc_set_mode(TIMER3, 3, TIMER_OC_MODE_TOGGLE, TIMER_OC_PE);
  timer_oc_set_mode(TIMER3, 4, TIMER_OC_MODE_TOGGLE, TIMER_OC_PE);
  Timer_3.setCompare(TIMER_CH3, 4);
  Timer_3.setCompare(TIMER_CH4, 20);
  Timer_3.setSlaveFlags( TIMER_SMCR_TS_ITR3 | TIMER_SMCR_SMS_EXTERNAL  );

  Timer_3.refresh();
  Timer_4.refresh();
  Timer_3.resume();
  Timer_4.resume();
}

void set_sin_tab(int faze, float sin_amp)
{

  float y;
  float maxy = 0;
  for (int i = 0; i < (SAMPLES_TX); i++) if ((y = F(dt * i)) > maxy) maxy = y;

  //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  // manually frequency changing = changing of f value = ok 
  //int f = 50;
  //int f = 100;
  //int f = 150;
  //int f = 200;

  //-------------------------------------------- using buttons = not working ----------------------------------
  if (digitalRead(PB3) == LOW)

  {
    if(f>250) f= 250;
    f++;
     delay(100);
  }


  if (digitalRead(PB4) == LOW)

  {
     if(f<0) f= 0;
    f--;
    delay(100);
  }
  //----------------------------------------------------------------------
 for (int i = 0; i < (SAMPLES_TX); i++) val_TX[i] = 1 + sin_amp * ((f - 1) / maxy) * F(dt * (i + faze)) ;
 timer_set_reload(dev_TX, f );
  //++++++++++++++++++++++++++++++++++++++++++++++++++++++
}

//======================================================setup()==============================================================
void setup()
{
  //Serial.begin(9600);
  Serial.begin(115200);
  pinMode(OUT_TX, PWM); //
  pinMode(PB0, PWM); //Yy
  pinMode(PB1, PWM); //Xy
  pinMode(PA7, INPUT_PULLUP);
  pinMode(PA6, INPUT_PULLUP);
  pinMode(PB3, INPUT_PULLUP);
  pinMode(PB4, INPUT_PULLUP);
  pinMode(LED_LCD, OUTPUT); 


  lcd.begin(16, 2);

  init_eeprom_mem();
  TX_conf();
}

//=====================================================loop()============================================================
void loop()
{
  
  Serial.print("f = ");
  Serial.println(f);
}

void init_eeprom_mem()
{
  for (int i = 0; i < num_prof; i++)
  {
    Mem.amp_TX[i] = 1.0;
    Mem.F_TX[i] = 160;
  }
  Mem.Prof = 0;

}

Hi,

because the function "void set_sin_tab()", is only called in setup(),
through the function "TX_conf()".
It is never called in loop().

and solution is ?

calls the function in the loop() function.

Here is your code whre I added printing to the serial monitor what your code is doing

#include <libmaple/dma.h>
#include <LiquidCrystal.h>
//LiquidCrystal lcd(PB9,PA11,PB15,PB14,PB13,PB12);
LiquidCrystal lcd(PB9, PC14, PB15, PB14, PB13, PB12);
#define SAMPLES_TX 64
#define dt (1.0/SAMPLES_TX)
#define F(x)(0.5*(1+sin(TWO_PI*x)))

HardwareTimer Timer_4(4);
HardwareTimer Timer_2(2);
HardwareTimer Timer_3(3);
int f;
int Sound_schem = 0;
int Faza_b;
unsigned int micros_1, micros_2;
unsigned int millis_1, millis_2;
int adc_data_1, adc_data_2;
int val_TX[SAMPLES_TX];

const int LED_LCD = PA8;
int V_tic = 0;
int V_bat = 0;
int MENU_index = 1;

#define eeprom_adr 1
#define num_prof 4
#pragma pack(push, 1);
struct strMem
{
  float amp_TX[num_prof];
  int F_TX[num_prof];
  int Threshold[num_prof];
  int Comp_Phase[num_prof];
  int need_phase[num_prof];
  int Adjustment_Phase[num_prof];

  int Prof;
} Mem;

const int OUT_TX = PB8;
dma_tube_config dma_cfg_TX, dma_cfg2;
timer_dev *dev_TX = PIN_MAP[OUT_TX].timer_device;//Timer4
uint8 cc_channel_TX = PIN_MAP[OUT_TX].timer_channel;//Channel3

void TX_conf()
{
  Timer_4.pause();
  Timer_3.pause();
  Timer_3.setCount(0);
  Timer_4.setCount(0);

  set_sin_tab(Mem.Comp_Phase[Mem.Prof], Mem.amp_TX[Mem.Prof]);


  timer_dma_set_base_addr(dev_TX,  TIMER_DMA_BASE_CCR3);
  timer_dma_set_burst_len(dev_TX, 1);
  timer_dma_enable_req(dev_TX, cc_channel_TX);
  // timer_set_reload(dev_TX, Mem.F_TX[Mem.Prof] );//++++++++++++++++++++++++++

  timer_set_prescaler(dev_TX, 0);
  Timer_4.setMasterModeTrGo(TIMER_CR2_MMS_COMPARE_OC3REF);

  dma_init(DMA1);
  dma_disable(DMA1, DMA_CH5);
  dma_cfg_TX.tube_dst = &(dev_TX->regs.gen->DMAR);
  dma_cfg_TX.tube_dst_size = DMA_SIZE_32BITS;
  dma_cfg_TX.tube_src = val_TX;
  dma_cfg_TX.tube_src_size = DMA_SIZE_32BITS;
  dma_cfg_TX.tube_nr_xfers = SAMPLES_TX;
  dma_cfg_TX.tube_flags = DMA_CFG_SRC_INC | DMA_CFG_CIRC | DMA_CFG_CMPLT_IE;
  dma_cfg_TX.tube_req_src = DMA_REQ_SRC_TIM4_CH3;
  dma_cfg_TX.target_data = 0;
  dma_tube_cfg(DMA1, DMA_CH5, &dma_cfg_TX);
  dma_enable(DMA1, DMA_CH5);



  Timer_3.setPrescaleFactor(1);
  Timer_3.setOverflow((SAMPLES_TX / 2) - 1);
  timer_oc_set_mode(TIMER3, 3, TIMER_OC_MODE_TOGGLE, TIMER_OC_PE);
  timer_oc_set_mode(TIMER3, 4, TIMER_OC_MODE_TOGGLE, TIMER_OC_PE);
  Timer_3.setCompare(TIMER_CH3, 4);
  Timer_3.setCompare(TIMER_CH4, 20);
  Timer_3.setSlaveFlags( TIMER_SMCR_TS_ITR3 | TIMER_SMCR_SMS_EXTERNAL  );

  Timer_3.refresh();
  Timer_4.refresh();
  Timer_3.resume();
  Timer_4.resume();
}

void set_sin_tab(int faze, float sin_amp)
{

  float y;
  float maxy = 0;
  for (int i = 0; i < (SAMPLES_TX); i++) if ((y = F(dt * i)) > maxy) maxy = y;

  //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  // manually frequency changing = changing of f value = ok
  //int f = 50;
  //int f = 100;
  //int f = 150;
  //int f = 200;

  //-------------------------------------------- using buttons = not working ----------------------------------
  if (digitalRead(PB3) == LOW)

  {
    if (f > 250) f = 250;
    f++;
    delay(100);
  }


  if (digitalRead(PB4) == LOW)

  {
    if (f < 0) f = 0;
    f--;
    delay(100);
  }
  //----------------------------------------------------------------------
  for (int i = 0; i < (SAMPLES_TX); i++) val_TX[i] = 1 + sin_amp * ((f - 1) / maxy) * F(dt * (i + faze)) ;
  timer_set_reload(dev_TX, f );
  //++++++++++++++++++++++++++++++++++++++++++++++++++++++
}

//======================================================setup()==============================================================
void setup()
{
  //Serial.begin(9600);
  Serial.begin(115200);
  Serial.println("just started function setup()");
  pinMode(OUT_TX, PWM); //
  pinMode(PB0, PWM); //Yy
  pinMode(PB1, PWM); //Xy
  pinMode(PA7, INPUT_PULLUP);
  pinMode(PA6, INPUT_PULLUP);
  pinMode(PB3, INPUT_PULLUP);
  pinMode(PB4, INPUT_PULLUP);
  pinMode(LED_LCD, OUTPUT);


  lcd.begin(16, 2);

  init_eeprom_mem();
  TX_conf();
  Serial.println("now exiting function setup()");
  Serial.println("and NEVER executing setup() again until Reset ");
  Serial.println("or power off/on");
}

//=====================================================loop()============================================================
void loop()
{

  Serial.print("f = ");
  Serial.println(f);
}

void init_eeprom_mem()
{
  for (int i = 0; i < num_prof; i++)
  {
    Mem.amp_TX[i] = 1.0;
    Mem.F_TX[i] = 160;
  }
  Mem.Prof = 0;

}

best regards Stefan

I moved TX_conf(); to loop = output signals are disappeared

//======================================================setup()==============================================================
void setup()
{
  //Serial.begin(9600);
  Serial.begin(115200);
  pinMode(OUT_TX, PWM); //
  pinMode(PB0, PWM); //Yy
  pinMode(PB1, PWM); //Xy
  pinMode(PA7, INPUT_PULLUP);
  pinMode(PA6, INPUT_PULLUP);
  pinMode(PB3, INPUT_PULLUP);
  pinMode(PB4, INPUT_PULLUP);
  pinMode(LED_LCD, OUTPUT); 


  lcd.begin(16, 2);

  init_eeprom_mem();
  //TX_conf();
}

//=====================================================loop()============================================================
void loop()
{
 TX_conf();
  Serial.print("f = ");
  Serial.println(f);
}

I know that for frequency changing I need to create a new loop for it but I don't know how.

what do you think is the meaning of this function-name?

what does the function

do ??
what does the serial monitor show if you run your code?

best regards Stefan

1 Like

forum

Your code does exactly what you have coded.

You define a variable "f" as global int

int f;

you have to conditions that constrain the value of f between 0 and 250
and depending on button-presses you change variable f

  if (digitalRead(PB3) == LOW) {
    if (f > 250) {
      f = 250;
    }
    f++;
    delay(100);
  }


  if (digitalRead(PB4) == LOW) {
    if (f < 0) {
      f = 0;
    }
    f--;
    delay(100);
  }

To narrow down what is the problem you should print to the serial monitor what is really going on inside your code and what values your variables have
here is a code.version with three debug-macros that do that
run this code-version and then post again what is printed to the serial monitor

// MACRO-START * MACRO-START * MACRO-START * MACRO-START * MACRO-START * MACRO-START *

// a detailed explanation how these macros work is given in this tutorial
// https://forum.arduino.cc/t/comfortable-serial-debug-output-short-to-write-fixed-text-name-and-content-of-any-variable-code-example/888298

#define dbg(myFixedText, variableName) \
  Serial.print( F(#myFixedText " "  #variableName"=") ); \
  Serial.println(variableName);
// usage: dbg("1:my fixed text",myVariable);
// myVariable can be any variable or expression that is defined in scope

#define dbgi(myFixedText, variableName,timeInterval) \
  do { \
    static unsigned long intervalStartTime; \
    if ( millis() - intervalStartTime >= timeInterval ){ \
      intervalStartTime = millis(); \
      Serial.print( F(#myFixedText " "  #variableName"=") ); \
      Serial.println(variableName); \
    } \
  } while (false);
// usage: dbgi("2:my fixed text",myVariable,1000);
// myVariable can be any variable or expression that is defined in scope
// third parameter is the time in milliseconds that must pass by until the next time a
// Serial.print is executed
// end of macros dbg and dbgi
// print only once when value has changed
#define dbgc(myFixedText, variableName) \
  do { \
    static long lastState; \
    if ( lastState != variableName ){ \
      Serial.print( F(#myFixedText " "  #variableName" changed from ") ); \
      Serial.print(lastState); \
      Serial.print( F(" to ") ); \
      Serial.println(variableName); \
      lastState = variableName; \
    } \
  } while (false);
// MACRO-END * MACRO-END * MACRO-END * MACRO-END * MACRO-END * MACRO-END * MACRO-END *


#include <libmaple/dma.h>
#include <LiquidCrystal.h>
//LiquidCrystal lcd(PB9,PA11,PB15,PB14,PB13,PB12);
LiquidCrystal lcd(PB9, PC14, PB15, PB14, PB13, PB12);
#define SAMPLES_TX 64
#define dt (1.0/SAMPLES_TX)
#define F(x)(0.5*(1+sin(TWO_PI*x)))

HardwareTimer Timer_4(4);
HardwareTimer Timer_2(2);
HardwareTimer Timer_3(3);

int f;

int Sound_schem = 0;
int Faza_b;
unsigned int micros_1, micros_2;
unsigned int millis_1, millis_2;
int adc_data_1, adc_data_2;
int val_TX[SAMPLES_TX];

const int LED_LCD = PA8;
int V_tic = 0;
int V_bat = 0;
int MENU_index = 1;

#define eeprom_adr 1
#define num_prof 4
#pragma pack(push, 1);
struct strMem {
  float amp_TX[num_prof];
  int F_TX[num_prof];
  int Threshold[num_prof];
  int Comp_Phase[num_prof];
  int need_phase[num_prof];
  int Adjustment_Phase[num_prof];

  int Prof;
} Mem;

const int OUT_TX = PB8;
dma_tube_config dma_cfg_TX, dma_cfg2;
timer_dev *dev_TX = PIN_MAP[OUT_TX].timer_device;//Timer4
uint8 cc_channel_TX = PIN_MAP[OUT_TX].timer_channel;//Channel3

void TX_conf() {
  Timer_4.pause();
  Timer_3.pause();
  Timer_3.setCount(0);
  Timer_4.setCount(0);

  set_sin_tab(Mem.Comp_Phase[Mem.Prof], Mem.amp_TX[Mem.Prof]);

  timer_dma_set_base_addr(dev_TX,  TIMER_DMA_BASE_CCR3);
  timer_dma_set_burst_len(dev_TX, 1);
  timer_dma_enable_req(dev_TX, cc_channel_TX);
  // timer_set_reload(dev_TX, Mem.F_TX[Mem.Prof] );//++++++++++++++++++++++++++

  timer_set_prescaler(dev_TX, 0);
  Timer_4.setMasterModeTrGo(TIMER_CR2_MMS_COMPARE_OC3REF);

  dma_init(DMA1);
  dma_disable(DMA1, DMA_CH5);
  dma_cfg_TX.tube_dst = &(dev_TX->regs.gen->DMAR);
  dma_cfg_TX.tube_dst_size = DMA_SIZE_32BITS;
  dma_cfg_TX.tube_src = val_TX;
  dma_cfg_TX.tube_src_size = DMA_SIZE_32BITS;
  dma_cfg_TX.tube_nr_xfers = SAMPLES_TX;
  dma_cfg_TX.tube_flags = DMA_CFG_SRC_INC | DMA_CFG_CIRC | DMA_CFG_CMPLT_IE;
  dma_cfg_TX.tube_req_src = DMA_REQ_SRC_TIM4_CH3;
  dma_cfg_TX.target_data = 0;
  dma_tube_cfg(DMA1, DMA_CH5, &dma_cfg_TX);
  dma_enable(DMA1, DMA_CH5);

  Timer_3.setPrescaleFactor(1);
  Timer_3.setOverflow((SAMPLES_TX / 2) - 1);
  timer_oc_set_mode(TIMER3, 3, TIMER_OC_MODE_TOGGLE, TIMER_OC_PE);
  timer_oc_set_mode(TIMER3, 4, TIMER_OC_MODE_TOGGLE, TIMER_OC_PE);
  Timer_3.setCompare(TIMER_CH3, 4);
  Timer_3.setCompare(TIMER_CH4, 20);
  Timer_3.setSlaveFlags( TIMER_SMCR_TS_ITR3 | TIMER_SMCR_SMS_EXTERNAL  );

  Timer_3.refresh();
  Timer_4.refresh();
  Timer_3.resume();
  Timer_4.resume();
}

void set_sin_tab(int faze, float sin_amp) {

  float y;
  float maxy = 0;
  for (int i = 0; i < (SAMPLES_TX); i++) 
    if ((y = F(dt * i)) > maxy) {
      maxy = y;
    }

  //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  // manually frequency changing = changing of f value = ok
  //int f = 50;
  //int f = 100;
  //int f = 150;
  //int f = 200;

  //-------------------------------------------- using buttons = not working ----------------------------------
  // print value of digitalRead ONCE if value has changed
  dbgc("set_sin_tab",digitalRead(PB3));
  if (digitalRead(PB3) == LOW) {
    
    if (f > 250) {
      f = 250;
    }
    f++;
    delay(100);
  }

  dbgc("set_sin_tab",digitalRead(PB4));
  if (digitalRead(PB4) == LOW) {
    if (f < 0) {
      f = 0;
    }
    f--;
    delay(100);
  }
  //----------------------------------------------------------------------
  for (int i = 0; i < (SAMPLES_TX); i++) {
    val_TX[i] = 1 + sin_amp * ((f - 1) / maxy) * F(dt * (i + faze)) ;
  }
  timer_set_reload(dev_TX, f );
  //++++++++++++++++++++++++++++++++++++++++++++++++++++++
}

//======================================================setup()==============================================================
void setup() {
  //Serial.begin(9600);
  Serial.begin(115200);
  Serial.println("just started function setup()");
  pinMode(OUT_TX, PWM); //
  pinMode(PB0, PWM); //Yy
  pinMode(PB1, PWM); //Xy
  pinMode(PA7, INPUT_PULLUP);
  pinMode(PA6, INPUT_PULLUP);
  pinMode(PB3, INPUT_PULLUP);
  pinMode(PB4, INPUT_PULLUP);
  pinMode(LED_LCD, OUTPUT);

  lcd.begin(16, 2);

  init_eeprom_mem();
  TX_conf();
  Serial.println("now exiting function setup()");
  Serial.println("and NEVER executing setup() again until Reset ");
  Serial.println("or power off/on");
}

//=====================================================loop()============================================================
void loop() {
  //print value of digitalRead ONCE if value has changed (since last printing)
  dbgc("loop",digitalRead(PB3));
  dbgc("loop",digitalRead(PB4));
  dbgc("loop",f);

  //Serial.print("f = ");
  //Serial.println(f);

  // if you wish to see the value of the digitalread in intervalls of 1000 milliseconds
  //dbgi("loop",digitalRead(PB3),1000);
  //dbgi("loop",digitalRead(PB4),1000);
  //dbgi("loop",f,1000); 
}

void init_eeprom_mem() {
  for (int i = 0; i < num_prof; i++) {
    Mem.amp_TX[i] = 1.0;
    Mem.F_TX[i] = 160;
  }
  
  Mem.Prof = 0;
}

best regards Stefan

1 Like

error

Arduino: 1.8.13 (Windows 10), Board: "Generic STM32F103C series, STM32F103C8 (20k RAM. 64k Flash), STM32duino bootloader, 72Mhz (Normal), Smallest (default)"





















Warning: Board New folder:arduino:nano328 doesn't define a 'build.board' preference. Auto-set to: ARDUINO_NANO328

Warning: Board New folder:arduino:mini328 doesn't define a 'build.board' preference. Auto-set to: ARDUINO_MINI328

Warning: Board New folder:arduino:pro doesn't define a 'build.board' preference. Auto-set to: ARDUINO_PRO

Warning: Board New folder:arduino:atmega328 doesn't define a 'build.board' preference. Auto-set to: ARDUINO_ATMEGA328

Warning: Board New folder:arduino:bt328 doesn't define a 'build.board' preference. Auto-set to: ARDUINO_BT328

Warning: Board New folder:arduino:diecimila doesn't define a 'build.board' preference. Auto-set to: ARDUINO_DIECIMILA

Warning: Board New folder:arduino:uno doesn't define a 'build.board' preference. Auto-set to: ARDUINO_UNO

Warning: Board New folder:arduino:fio doesn't define a 'build.board' preference. Auto-set to: ARDUINO_FIO

Warning: Board New folder:arduino:atmega8 doesn't define a 'build.board' preference. Auto-set to: ARDUINO_ATMEGA8

Warning: Board New folder:arduino:mega2560 doesn't define a 'build.board' preference. Auto-set to: ARDUINO_MEGA2560

Warning: Board New folder:arduino:pro328 doesn't define a 'build.board' preference. Auto-set to: ARDUINO_PRO328

Warning: Board New folder:arduino:bt doesn't define a 'build.board' preference. Auto-set to: ARDUINO_BT

Warning: Board New folder:arduino:pro5v doesn't define a 'build.board' preference. Auto-set to: ARDUINO_PRO5V

Warning: Board New folder:arduino:ethernet doesn't define a 'build.board' preference. Auto-set to: ARDUINO_ETHERNET

Warning: Board New folder:arduino:lilypad doesn't define a 'build.board' preference. Auto-set to: ARDUINO_LILYPAD

Warning: Board New folder:arduino:pro5v328 doesn't define a 'build.board' preference. Auto-set to: ARDUINO_PRO5V328

Warning: Board New folder:arduino:nano doesn't define a 'build.board' preference. Auto-set to: ARDUINO_NANO

Warning: Board New folder:arduino:atmega168 doesn't define a 'build.board' preference. Auto-set to: ARDUINO_ATMEGA168

Warning: Board New folder:arduino:mega doesn't define a 'build.board' preference. Auto-set to: ARDUINO_MEGA

Warning: Board New folder:arduino:mini doesn't define a 'build.board' preference. Auto-set to: ARDUINO_MINI

Warning: Board New folder:arduino:lilypad328 doesn't define a 'build.board' preference. Auto-set to: ARDUINO_LILYPAD328

Warning: Board New folder:attiny:attiny45-8 doesn't define a 'build.board' preference. Auto-set to: ATTINY_ATTINY45-8

Warning: Board New folder:attiny:attiny85-8 doesn't define a 'build.board' preference. Auto-set to: ATTINY_ATTINY85-8

Warning: Board New folder:attiny:attiny85-20 doesn't define a 'build.board' preference. Auto-set to: ATTINY_ATTINY85-20

Warning: Board New folder:attiny:attiny84 doesn't define a 'build.board' preference. Auto-set to: ATTINY_ATTINY84

Warning: Board New folder:attiny:attiny84-8 doesn't define a 'build.board' preference. Auto-set to: ATTINY_ATTINY84-8

Warning: Board New folder:attiny:attiny85 doesn't define a 'build.board' preference. Auto-set to: ATTINY_ATTINY85

Warning: Board New folder:attiny:attiny44 doesn't define a 'build.board' preference. Auto-set to: ATTINY_ATTINY44

Warning: Board New folder:attiny:attiny44-8 doesn't define a 'build.board' preference. Auto-set to: ATTINY_ATTINY44-8

Warning: Board New folder:attiny:attiny44-20 doesn't define a 'build.board' preference. Auto-set to: ATTINY_ATTINY44-20

Warning: Board New folder:attiny:attiny84-20 doesn't define a 'build.board' preference. Auto-set to: ATTINY_ATTINY84-20

Warning: Board New folder:attiny:attiny45 doesn't define a 'build.board' preference. Auto-set to: ATTINY_ATTINY45

Warning: Board New folder:attiny:attiny45-20 doesn't define a 'build.board' preference. Auto-set to: ATTINY_ATTINY45-20

C:\Users\Galinka\Documents\Arduino\k_forum_2\k_forum_2.ino: In function 'void set_sin_tab(int, float)':

k_forum_2:29:54: error: invalid operands of types 'double' and 'const char [45]' to binary 'operator*'

       Serial.print( F(#myFixedText " "  #variableName" changed from ") ); \

                                                      ^

C:\Users\Galinka\Documents\Arduino\k_forum_2\k_forum_2.ino:45:32: note: in definition of macro 'F'

 #define F(x)(0.5*(1+sin(TWO_PI*x)))

                                ^

C:\Users\Galinka\Documents\Arduino\k_forum_2\k_forum_2.ino:145:3: note: in expansion of macro 'dbgc'

   dbgc("set_sin_tab",digitalRead(PB3));

   ^

k_forum_2:31:23: error: invalid operands of types 'double' and 'const char [5]' to binary 'operator*'

       Serial.print( F(" to ") ); \

                       ^

C:\Users\Galinka\Documents\Arduino\k_forum_2\k_forum_2.ino:45:32: note: in definition of macro 'F'

 #define F(x)(0.5*(1+sin(TWO_PI*x)))

                                ^

C:\Users\Galinka\Documents\Arduino\k_forum_2\k_forum_2.ino:145:3: note: in expansion of macro 'dbgc'

   dbgc("set_sin_tab",digitalRead(PB3));

   ^

k_forum_2:29:54: error: invalid operands of types 'double' and 'const char [45]' to binary 'operator*'

       Serial.print( F(#myFixedText " "  #variableName" changed from ") ); \

                                                      ^

C:\Users\Galinka\Documents\Arduino\k_forum_2\k_forum_2.ino:45:32: note: in definition of macro 'F'

 #define F(x)(0.5*(1+sin(TWO_PI*x)))

                                ^

C:\Users\Galinka\Documents\Arduino\k_forum_2\k_forum_2.ino:155:3: note: in expansion of macro 'dbgc'

   dbgc("set_sin_tab",digitalRead(PB4));

   ^

k_forum_2:31:23: error: invalid operands of types 'double' and 'const char [5]' to binary 'operator*'

       Serial.print( F(" to ") ); \

                       ^

C:\Users\Galinka\Documents\Arduino\k_forum_2\k_forum_2.ino:45:32: note: in definition of macro 'F'

 #define F(x)(0.5*(1+sin(TWO_PI*x)))

                                ^

C:\Users\Galinka\Documents\Arduino\k_forum_2\k_forum_2.ino:155:3: note: in expansion of macro 'dbgc'

   dbgc("set_sin_tab",digitalRead(PB4));

   ^

C:\Users\Galinka\Documents\Arduino\k_forum_2\k_forum_2.ino: In function 'void loop()':

k_forum_2:29:54: error: invalid operands of types 'double' and 'const char [38]' to binary 'operator*'

       Serial.print( F(#myFixedText " "  #variableName" changed from ") ); \

                                                      ^

C:\Users\Galinka\Documents\Arduino\k_forum_2\k_forum_2.ino:45:32: note: in definition of macro 'F'

 #define F(x)(0.5*(1+sin(TWO_PI*x)))

                                ^

C:\Users\Galinka\Documents\Arduino\k_forum_2\k_forum_2.ino:197:3: note: in expansion of macro 'dbgc'

   dbgc("loop",digitalRead(PB3));

   ^

k_forum_2:31:23: error: invalid operands of types 'double' and 'const char [5]' to binary 'operator*'

       Serial.print( F(" to ") ); \

                       ^

C:\Users\Galinka\Documents\Arduino\k_forum_2\k_forum_2.ino:45:32: note: in definition of macro 'F'

 #define F(x)(0.5*(1+sin(TWO_PI*x)))

                                ^

C:\Users\Galinka\Documents\Arduino\k_forum_2\k_forum_2.ino:197:3: note: in expansion of macro 'dbgc'

   dbgc("loop",digitalRead(PB3));

   ^

k_forum_2:29:54: error: invalid operands of types 'double' and 'const char [38]' to binary 'operator*'

       Serial.print( F(#myFixedText " "  #variableName" changed from ") ); \

                                                      ^

C:\Users\Galinka\Documents\Arduino\k_forum_2\k_forum_2.ino:45:32: note: in definition of macro 'F'

 #define F(x)(0.5*(1+sin(TWO_PI*x)))

                                ^

C:\Users\Galinka\Documents\Arduino\k_forum_2\k_forum_2.ino:198:3: note: in expansion of macro 'dbgc'

   dbgc("loop",digitalRead(PB4));

   ^

k_forum_2:31:23: error: invalid operands of types 'double' and 'const char [5]' to binary 'operator*'

       Serial.print( F(" to ") ); \

                       ^

C:\Users\Galinka\Documents\Arduino\k_forum_2\k_forum_2.ino:45:32: note: in definition of macro 'F'

 #define F(x)(0.5*(1+sin(TWO_PI*x)))

                                ^

C:\Users\Galinka\Documents\Arduino\k_forum_2\k_forum_2.ino:198:3: note: in expansion of macro 'dbgc'

   dbgc("loop",digitalRead(PB4));

   ^

k_forum_2:29:54: error: invalid operands of types 'double' and 'const char [23]' to binary 'operator*'

       Serial.print( F(#myFixedText " "  #variableName" changed from ") ); \

                                                      ^

C:\Users\Galinka\Documents\Arduino\k_forum_2\k_forum_2.ino:45:32: note: in definition of macro 'F'

 #define F(x)(0.5*(1+sin(TWO_PI*x)))

                                ^

C:\Users\Galinka\Documents\Arduino\k_forum_2\k_forum_2.ino:199:3: note: in expansion of macro 'dbgc'

   dbgc("loop",f);

   ^

k_forum_2:31:23: error: invalid operands of types 'double' and 'const char [5]' to binary 'operator*'

       Serial.print( F(" to ") ); \

                       ^

C:\Users\Galinka\Documents\Arduino\k_forum_2\k_forum_2.ino:45:32: note: in definition of macro 'F'

 #define F(x)(0.5*(1+sin(TWO_PI*x)))

                                ^

C:\Users\Galinka\Documents\Arduino\k_forum_2\k_forum_2.ino:199:3: note: in expansion of macro 'dbgc'

   dbgc("loop",f);

   ^

Multiple libraries were found for "LiquidCrystal.h"

 Used: C:\Users\Galinka\Documents\Arduino\libraries\LiquidCrystal

 Not used: C:\Program Files (x86)\Arduino\libraries\LiquidCrystal

 Not used: C:\Users\Galinka\Documents\Arduino\hardware\Arduino_STM32-master\STM32F1\libraries\LiquidCrystal

exit status 1

invalid operands of types 'double' and 'const char [45]' to binary 'operator*'



This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

I comment the lines - 5, 6, 15, 29 and error is shorter

Warning: Board New folder:attiny:attiny84 doesn't define a 'build.board' preference. Auto-set to: ATTINY_ATTINY84
k_forum_2:11:2: error: expected unqualified-id before 'do'
  do { 
  ^
k_forum_2:67:23: error: expected declaration before end of line
 #pragma pack(push, 1);
                       ^
Multiple libraries were found for "LiquidCrystal.h"
 Used: C:\Users\Galinka\Documents\Arduino\libraries\LiquidCrystal
 Not used: C:\Program Files (x86)\Arduino\libraries\LiquidCrystal
 Not used: C:\Users\Galinka\Documents\Arduino\hardware\Arduino_STM32-master\STM32F1\libraries\LiquidCrystal
exit status 1
expected unqualified-id before 'do'

simply post this code-version as a complete sketch using the copy for forum function
this is just a few clicks and 30 seconds for you

I will not count line-numbers guessing what you mean.

If you provide links to the libraries that you are using I can install them and then make the code compile

https://github.com/leaflabs/libmaple

when you open the file you can see the lines numbers

// MACRO-START * MACRO-START * MACRO-START * MACRO-START * MACRO-START * MACRO-START *
// Take it for granted at the moment scroll down to void setup
// start of macros dbg and dbgi
#define dbg(myFixedText, variableName) 
 // Serial.print( F(#myFixedText " "  #variableName"=") ); 
//  Serial.println(variableName);
// usage: dbg("1:my fixed text",myVariable);
// myVariable can be any variable or expression that is defined in scope

#define dbgi(myFixedText, variableName,timeInterval) 
 do { 
    static unsigned long intervalStartTime; 
    if ( millis() - intervalStartTime >= timeInterval ){ 
      intervalStartTime = millis(); 
 //     Serial.print( F(#myFixedText " "  #variableName"=") ); 
      Serial.println(variableName); 
    } 
  } while (false);
// usage: dbgi("2:my fixed text",myVariable,1000);
// myVariable can be any variable or expression that is defined in scope
// third parameter is the time in milliseconds that must pass by until the next time a
// Serial.print is executed
// end of macros dbg and dbgi
// print only once when value has changed
#define dbgc(myFixedText, variableName) 
  do { 
    static long lastState; 
    if ( lastState != variableName ){ 
 //     Serial.print( F(#myFixedText " "  #variableName" changed from ") ); 
      Serial.print(lastState); 
      Serial.print( F(" to ") ); 
      Serial.println(variableName); 
      lastState = variableName; 
    } 
  } while (false);
// MACRO-END * MACRO-END * MACRO-END * MACRO-END * MACRO-END * MACRO-END * MACRO-END *


#include <libmaple/dma.h>
#include <LiquidCrystal.h>
//LiquidCrystal lcd(PB9,PA11,PB15,PB14,PB13,PB12);
LiquidCrystal lcd(PB9, PC14, PB15, PB14, PB13, PB12);
#define SAMPLES_TX 64
#define dt (1.0/SAMPLES_TX)
#define F(x)(0.5*(1+sin(TWO_PI*x)))

HardwareTimer Timer_4(4);
HardwareTimer Timer_2(2);
HardwareTimer Timer_3(3);

int f;

int Sound_schem = 0;
int Faza_b;
unsigned int micros_1, micros_2;
unsigned int millis_1, millis_2;
int adc_data_1, adc_data_2;
int val_TX[SAMPLES_TX];

const int LED_LCD = PA8;
int V_tic = 0;
int V_bat = 0;
int MENU_index = 1;

#define eeprom_adr 1
#define num_prof 4
#pragma pack(push, 1);
struct strMem {
  float amp_TX[num_prof];
  int F_TX[num_prof];
  int Threshold[num_prof];
  int Comp_Phase[num_prof];
  int need_phase[num_prof];
  int Adjustment_Phase[num_prof];

  int Prof;
} Mem;

const int OUT_TX = PB8;
dma_tube_config dma_cfg_TX, dma_cfg2;
timer_dev *dev_TX = PIN_MAP[OUT_TX].timer_device;//Timer4
uint8 cc_channel_TX = PIN_MAP[OUT_TX].timer_channel;//Channel3

void TX_conf() {
  Timer_4.pause();
  Timer_3.pause();
  Timer_3.setCount(0);
  Timer_4.setCount(0);

  set_sin_tab(Mem.Comp_Phase[Mem.Prof], Mem.amp_TX[Mem.Prof]);

  timer_dma_set_base_addr(dev_TX,  TIMER_DMA_BASE_CCR3);
  timer_dma_set_burst_len(dev_TX, 1);
  timer_dma_enable_req(dev_TX, cc_channel_TX);
  // timer_set_reload(dev_TX, Mem.F_TX[Mem.Prof] );//++++++++++++++++++++++++++

  timer_set_prescaler(dev_TX, 0);
  Timer_4.setMasterModeTrGo(TIMER_CR2_MMS_COMPARE_OC3REF);

  dma_init(DMA1);
  dma_disable(DMA1, DMA_CH5);
  dma_cfg_TX.tube_dst = &(dev_TX->regs.gen->DMAR);
  dma_cfg_TX.tube_dst_size = DMA_SIZE_32BITS;
  dma_cfg_TX.tube_src = val_TX;
  dma_cfg_TX.tube_src_size = DMA_SIZE_32BITS;
  dma_cfg_TX.tube_nr_xfers = SAMPLES_TX;
  dma_cfg_TX.tube_flags = DMA_CFG_SRC_INC | DMA_CFG_CIRC | DMA_CFG_CMPLT_IE;
  dma_cfg_TX.tube_req_src = DMA_REQ_SRC_TIM4_CH3;
  dma_cfg_TX.target_data = 0;
  dma_tube_cfg(DMA1, DMA_CH5, &dma_cfg_TX);
  dma_enable(DMA1, DMA_CH5);

  Timer_3.setPrescaleFactor(1);
  Timer_3.setOverflow((SAMPLES_TX / 2) - 1);
  timer_oc_set_mode(TIMER3, 3, TIMER_OC_MODE_TOGGLE, TIMER_OC_PE);
  timer_oc_set_mode(TIMER3, 4, TIMER_OC_MODE_TOGGLE, TIMER_OC_PE);
  Timer_3.setCompare(TIMER_CH3, 4);
  Timer_3.setCompare(TIMER_CH4, 20);
  Timer_3.setSlaveFlags( TIMER_SMCR_TS_ITR3 | TIMER_SMCR_SMS_EXTERNAL  );

  Timer_3.refresh();
  Timer_4.refresh();
  Timer_3.resume();
  Timer_4.resume();
}

void set_sin_tab(int faze, float sin_amp) {

  float y;
  float maxy = 0;
  for (int i = 0; i < (SAMPLES_TX); i++) 
    if ((y = F(dt * i)) > maxy) {
      maxy = y;
    }

  //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  // manually frequency changing = changing of f value = ok
  //int f = 50;
  //int f = 100;
  //int f = 150;
  //int f = 200;

  //-------------------------------------------- using buttons = not working ----------------------------------
  // print value of digitalRead ONCE if value has changed
  dbgc("set_sin_tab",digitalRead(PB3));
  if (digitalRead(PB3) == LOW) {
    
    if (f > 250) {
      f = 250;
    }
    f++;
    delay(100);
  }

  dbgc("set_sin_tab",digitalRead(PB4));
  if (digitalRead(PB4) == LOW) {
    if (f < 0) {
      f = 0;
    }
    f--;
    delay(100);
  }
  //----------------------------------------------------------------------
  for (int i = 0; i < (SAMPLES_TX); i++) {
    val_TX[i] = 1 + sin_amp * ((f - 1) / maxy) * F(dt * (i + faze)) ;
  }
  timer_set_reload(dev_TX, f );
  //++++++++++++++++++++++++++++++++++++++++++++++++++++++
}

//======================================================setup()==============================================================
void setup() {
  //Serial.begin(9600);
  Serial.begin(115200);
  Serial.println("just started function setup()");
  pinMode(OUT_TX, PWM); //
  pinMode(PB0, PWM); //Yy
  pinMode(PB1, PWM); //Xy
  pinMode(PA7, INPUT_PULLUP);
  pinMode(PA6, INPUT_PULLUP);
  pinMode(PB3, INPUT_PULLUP);
  pinMode(PB4, INPUT_PULLUP);
  pinMode(LED_LCD, OUTPUT);

  lcd.begin(16, 2);

  init_eeprom_mem();
  TX_conf();
  Serial.println("now exiting function setup()");
  Serial.println("and NEVER executing setup() again until Reset ");
  Serial.println("or power off/on");
}

//=====================================================loop()============================================================
void loop() {
  //print value of digitalRead ONCE if value has changed (since last printing)
  dbgc("loop",digitalRead(PB3));
  dbgc("loop",digitalRead(PB4));
  dbgc("loop",f);

  //Serial.print("f = ");
  //Serial.println(f);

  // if you wish to see the value of the digitalread in intervalls of 1000 milliseconds
  //dbgi("loop",digitalRead(PB3),1000);
  //dbgi("loop",digitalRead(PB4),1000);
  //dbgi("loop",f,1000); 
}

void init_eeprom_mem() {
  for (int i = 0; i < num_prof; i++) {
    Mem.amp_TX[i] = 1.0;
    Mem.F_TX[i] = 160;
  }
  
  Mem.Prof = 0;
}

Arduino IDE 1.8.19 sketch-add-library-add-zip-library
folder does not contain a valid library

#include <libmaple/dma.h>

no file libmaple/dma.h inside the zip-file

https://github.com/leaflabs/libmaple/blob/master/libmaple/stm32f1/include/series/dma.h

so this is the file
but how do I add all the files as a zipfile?
usually this is done from the main-folder of the gipo
or alternatively how did you manage to put the files to your arduino IDE ?

did you switch the board to stm32f103 ?