[SOLVED] Discovery STM32F100RB - Trouble with timers and library structure

STM32F103 Nucleo boards e.g. STM Nucleo F103RB
hdleng
Posts: 10
Joined: Sat Sep 23, 2017 3:21 am
Location: Arizona, USA

[SOLVED] Discovery STM32F100RB - Trouble with timers and library structure

Post by hdleng » Mon Sep 25, 2017 4:18 am

I am a retired embedded developer who worked in industrial controls and defense systems. I've continued this work as a hobby, and I am working on designs for digital communications modes in amateur radio.

I've developed STM32 software on the Eclipse IDE, and I've used the Arduino IDE for some Atmel 8-bit work. But, I'm new the STM32duino.

I am using a Discovery STM32F100RB board. I tested the tool chain and board successfully with Arduino\hardware\Arduino_STM32-master\STM32F1\libraries\A_STM32_Examples\examples\Digital\Blink\Blink.ino.

I next attempted Arduino\hardware\Arduino_STM32-master\STM32F1\libraries\A_STM32_Examples\examples\Maple\TimerInterrupts\TimerInterrupts.ino.

Code: Select all

/*
 Timer Interrupts Example

 Demonstrates usage of the HardwareTimer classes by blinking the LED
 
 Created 22 April 2010, last updated 8 June 2010
 By Bryan Newbold for LeafLabs
 This code is released with no strings attached.
 
 */

#define LED_PIN 13
#define BUTTON_PIN 38
#define LED_RATE 500000    // in microseconds; should give 0.5Hz toggles

void handler_led(void);
void handler_count1(void);
void handler_count2(void);

int toggle = 0;

int count1 = 0;
int count2 = 0;

void setup()
{
	Serial.begin(115200); // Ignored by Maple. But needed by boards using hardware serial via a USB to Serial adaptor
    // Set up the LED to blink 
    pinMode(LED_PIN, OUTPUT);

    // Set up BUT for input
    pinMode(BUTTON_PIN, INPUT_PULLUP);

    // Setup LED Timer
    Timer2.setChannel1Mode(TIMER_OUTPUTCOMPARE);
    Timer2.setPeriod(LED_RATE); // in microseconds
    Timer2.setCompare1(1);      // overflow might be small
    Timer2.attachCompare1Interrupt(handler_led);

    // Setup Counting Timers
    Timer3.setChannel1Mode(TIMER_OUTPUTCOMPARE);
    Timer4.setChannel1Mode(TIMER_OUTPUTCOMPARE);
    Timer3.pause();
    Timer4.pause();
    Timer3.setCount(0);
    Timer4.setCount(0);
    Timer3.setOverflow(30000);
    Timer4.setOverflow(30000);
    Timer3.setCompare1(1000);   // somewhere in the middle
    Timer4.setCompare1(1000);   
    Timer3.attachCompare1Interrupt(handler1);
    Timer4.attachCompare1Interrupt(handler2);
    Timer3.resume();
    Timer4.resume();

}

void loop() {

    // Display the running counts
    Serial.print("Count 1: "); 
    Serial.print(count1);
    Serial.print("\t\tCount 2: "); 
    Serial.println(count2);

    // Run... while BUT is held, pause Count2
    for(int i = 0; i<1000; i++) {
        if(digitalRead(BUTTON_PIN)) {
            Timer4.pause();
        } else {
            Timer4.resume();
        }
        delay(1);
    }
}

void handler_led(void) {
    toggle ^= 1;
    digitalWrite(LED_PIN, toggle);
} 

void handler1(void) {
    count1++;
} 
void handler2(void) {
    count2++;
} 
I get the error:

Code: Select all

Arduino: 1.6.9 (Windows XP), Board: "Discovery, STM32F100RB-DISCVL, STLink, None, None"

Build options changed, rebuilding all
C:\Documents and Settings\Jim\My Documents\Arduino\hardware\Arduino_STM32-master\STM32F1\libraries\A_STM32_Examples\examples\Maple\TimerInterrupts\TimerInterrupts.ino: In function 'void setup()':

TimerInterrupts:35: error: 'Timer2' was not declared in this scope

     Timer2.setChannel1Mode(TIMER_OUTPUTCOMPARE);

TimerInterrupts:35: error: 'TIMER_OUTPUTCOMPARE' was not declared in this scope

     Timer2.setChannel1Mode(TIMER_OUTPUTCOMPARE);

TimerInterrupts:41: error: 'Timer3' was not declared in this scope

     Timer3.setChannel1Mode(TIMER_OUTPUTCOMPARE);

TimerInterrupts:42: error: 'Timer4' was not declared in this scope

     Timer4.setChannel1Mode(TIMER_OUTPUTCOMPARE);

C:\Documents and Settings\Jim\My Documents\Arduino\hardware\Arduino_STM32-master\STM32F1\libraries\A_STM32_Examples\examples\Maple\TimerInterrupts\TimerInterrupts.ino: In function 'void loop()':

TimerInterrupts:69: error: 'Timer4' was not declared in this scope

             Timer4.pause();

TimerInterrupts:71: error: 'Timer4' was not declared in this scope

             Timer4.resume();

exit status 1
'Timer2' was not declared in this scope
Rather that trying to figure out all of the unresolved references, I decided to start small by adding a call to a timer function in the Blink.ino. I added "timer_init_all();" This is the source code:

Code: Select all

/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.

  Most Arduinos have an on-board LED you can control. On the Uno and
  Leonardo, it is attached to digital pin 13. If you're unsure what
  pin the on-board LED is connected to on your Arduino model, check
  the documentation at http://arduino.cc

  This example code is in the public domain.

  modified 8 May 2014
  by Scott Fitzgerald
  
  Modified by Roger Clark. www.rogerclark.net for Maple mini 25th April 2015 , where the LED is on PC8
  
 */
 
// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin PC8 as an output.
  pinMode(PC8, OUTPUT);
  pinMode(PC9, OUTPUT);
  timer_init_all();
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(PC8, HIGH);   // turn the LED on (HIGH is the voltage level)
  digitalWrite(PC9, LOW);
  delay(200);              // wait for a 1/5 second
  digitalWrite(PC8, LOW);    // turn the LED off by making the voltage LOW
  digitalWrite(PC9, HIGH);
  delay(200);              // wait for a 1/5 second
}
These are the errors:

Code: Select all

Arduino: 1.6.9 (Windows XP), Board: "Discovery, STM32F100RB-DISCVL, STLink, None, None"

Build options changed, rebuilding all
C:\Documents and Settings\Jim\My Documents\Arduino\sketch_sep21a\sketch_sep21a.ino: In function 'void setup()':

sketch_sep21a:29: error: 'timer_init_all' was not declared in this scope

   timer_init_all();

                  ^

exit status 1
'timer_init_all' was not declared in this scope
I added #include "..." with full path names, but that resulted in other *.h files not found.

I suspect that I have failed to configure the IDE for include paths needed to find the needed files.

I will be appreciate any guidance.

Frank

User avatar
RogerClark
Posts: 7475
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: trouble with timers and library structure

Post by RogerClark » Mon Sep 25, 2017 5:33 am

Welcome Frank

I've just tried to compile that example and I'm not getting any errors

I tried 2 different boards the Generic STM32F103C and also the Nucleo F103RB

The only difference I can see if that you are using quite an old version of the Arduino IDE (1.6.9) where as I'm using 1.8.3
(It looks like 1.8.4 is the latest and is probably OK)

Though I can't see how the IDE version could be causing this issue.

I presume you recently downloaded the zip or cloned my repo ?

Anyway.

You should not need to debug it, as it appears to compile OK.


Can you confirm what board you selected ?

hdleng
Posts: 10
Joined: Sat Sep 23, 2017 3:21 am
Location: Arizona, USA

Re: trouble with timers and library structure

Post by hdleng » Mon Sep 25, 2017 7:55 am

Roger,

Thanks for the quick reply.

The board selection was Tools: Board part number: "STM32F100RB-DISCVL".

When I selected Generic STM32F103C, the compile was successful.

I downloaded the repo within the last week.

I am going to start over by updating to the most recent Arduino IDE then adding the STM32 stuff.

Thanks again,

Frank

stevestrong
Posts: 1821
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: trouble with timers and library structure

Post by stevestrong » Mon Sep 25, 2017 7:58 am

I think this is the environment:

Code: Select all

Arduino: 1.6.9 (Windows XP), Board: "Discovery, STM32F100RB-DISCVL, STLink, None, None"
Arduino 1.6.9. should work ok.
Upload via ST-Link (V2?).
Just wondering, the Arduino_STM32 core does not have any variant named "Discovery, STM32F100RB-DISCVL".
Which target did you select from the Arduino IDE menu for that?

Is it possible that you mixed up two different cores?

User avatar
RogerClark
Posts: 7475
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: trouble with timers and library structure

Post by RogerClark » Mon Sep 25, 2017 8:11 am

stevestrong wrote:
Mon Sep 25, 2017 7:58 am
I think this is the environment:

Code: Select all

Arduino: 1.6.9 (Windows XP), Board: "Discovery, STM32F100RB-DISCVL, STLink, None, None"
Arduino 1.6.9. should work ok.
Upload via ST-Link (V2?).
Just wondering, the Arduino_STM32 core does not have any variant named "Discovery, STM32F100RB-DISCVL".
Which target did you select from the Arduino IDE menu for that?

Is it possible that you mixed up two different cores?
Good call...

Perhaps he's trying to use LibMaple examples with STM's core

hdleng
Posts: 10
Joined: Sat Sep 23, 2017 3:21 am
Location: Arizona, USA

Re: trouble with timers and library structure

Post by hdleng » Mon Sep 25, 2017 8:52 am

In file: preferences: Additional Boards Manager URLs: , I added https://github.com/stm32duino/BoardMana ... index.json.

Then under Tools: Boards: Board Manager..., I selected Type: Contributed. I then found and installed "STM32 Cores by ST-Microelectronics version 2017.8.17". Boards included in this package ..., STM32F100RB-DISCVL, ...

Does this shed any light on whether I have the proper core?

I just downloaded Arduino_STM32-master.zip. It is 37.7 MB. The file that I downloaded on 9/17/2017 was 39.0 MB. Does this matter?

Thanks for you help and patience,

Frank

stevestrong
Posts: 1821
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: trouble with timers and library structure

Post by stevestrong » Mon Sep 25, 2017 9:03 am

Well, indeed, you mixed up the STM32DUINO core from ST (available over the library manager in Arduino IDE) with the Arduino_STM32 (Libmaple) core managed by Roger, available only as downloadable ZIP package.
You should only use one of them, delete the other one.

hdleng
Posts: 10
Joined: Sat Sep 23, 2017 3:21 am
Location: Arizona, USA

Re: trouble with timers and library structure

Post by hdleng » Mon Sep 25, 2017 9:30 am

Steve,

Thanks for the suggestion. Maybe I'm getting closer to getting this to work. I went to Tools: Board: Board Manager... and selected and uninstalled STM32DUINO core from ST. I restarted Arduino. Now I see no STM32 boards under Tools: Board.
I put Roger's repo in Documents/Arduino/hardware; is there something else I need to do to make the IDE aware of it?

Thanks,

Frank

zmemw16
Posts: 1486
Joined: Wed Jul 08, 2015 2:09 pm
Location: St Annes, Lancs,UK

Re: trouble with timers and library structure

Post by zmemw16 » Mon Sep 25, 2017 9:41 am

@hdleng
extract the core zip files under the 'hardware' directory and rename them by adding a prefix
for steve i add ss-, for the STM32GENERIC i'll add cm- or dan-
so if i had rogers installed and steves as well, hardware directory would have

Code: Select all

Arduino_STM32
ss-Arduino_STM32
if you look in the STM32F1 folders for each and at the beginning of each 'platform.txt' file there's a NAME = some string; that string appears in the boards menu.

Code: Select all

name=STM32 Boards (STM32duino.com)
as i do for the directorries i also prefix the NAME string similarly again with nothing for the original Arduino_STM32, ss for steve, cm chrismicro, vpv for victor and dan for the original STM32GENERIC.
for steve's

Code: Select all

name=ss-STM32 Boards (STM32duino.com)
in addition, i've noticed that the examples menu under file seems to reflect only the examples for the selected board.
at least in some cases, no idea how to customise that further.

i do agree it can be quite confusing to have multiple cores installed, that's how the above evolved.

i7 with debian stretch and arduino 1.8.3 linux64 stock binary, usually Arduino_STM32 as a minimum.

stephen

hdleng
Posts: 10
Joined: Sat Sep 23, 2017 3:21 am
Location: Arizona, USA

Re: trouble with timers and library structure

Post by hdleng » Mon Sep 25, 2017 10:05 am

@zmemw16,

Thanks for the help. I think I'm following directions, but I'm obviously getting something wrong. So, I'll try to explain the steps I've taken in detail.

I downloaded Arduino_STM32-master.zip from Roger's github. I extracted (all) to Documents/Arduino/hardware. I did not put anything into Program Files/Arduino/hardware.

In My Documents\Arduino\hardware\Arduino_STM32-master\STM32F1\ there is a file 'platform.txt'. There is a line in that file: "name=STM32 Boards (STM32duino.com)".

But, there is no listing under Tools: Board showing "STM32 Boards".

Can you see what I may be doing wrong?

Thanks,

Frank

Post Reply