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

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.

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


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
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
Mon Sep 25, 2017 7:58 am
I think this is the environment:
Arduino: 1.6.9 (Windows XP), Board: "Discovery, STM32F100RB-DISCVL, STLink, None, None"

RogerClark
Mon Sep 25, 2017 8:11 am
[stevestrong – Mon Sep 25, 2017 7:58 am] –
I think this is the environment:
Arduino: 1.6.9 (Windows XP), Board: "Discovery, STM32F100RB-DISCVL, STLink, None, None"

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
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
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
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
Arduino_STM32
ss-Arduino_STM32

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


RogerClark
Mon Sep 25, 2017 10:18 am
Frank

I think you are installing correctly.

Did you restart the IDE after copying the files into the hardware folder

Also. You need to have the ARM compiler installed, so if you have uninstalled STM’s core, you’ll need to install the Arduino Due or Zero as either will install the ARM compiler that my repo uses.


zmemw16
Mon Sep 25, 2017 10:41 am
this is my way of handling multiple cores of libmaple or stm32generic in residence, standard disclaimers apply.
@hdleng
ok, my hardware directory is under ‘/home/stephen/sketchbook’ that is set in preferences

i’ve just edited platform.txt in the STM32F1 directory and added ‘srp-‘ to the beginning of the name string.
fired up Arduino, then via tools->board-manager and had to scroll down a lot.
my drop-down has a black downward pointing triangle at the bottom.
~/sketchbook/hardware/Arduino_STM32/STM32F1/platform.txt


RogerClark
Mon Sep 25, 2017 11:11 am
There should be no need to edit files.

All STM32 cores should co-exist OK without renaming etc

I have my “LibMaple” based core and Daniel’s STM32GENERIC in my hardware folder and they both work fine.


zmemw16
Mon Sep 25, 2017 2:49 pm
there is a preponderance of ‘i’ in the post. i’ll edit in a warning.

the cores reside together very nicely if you only have one of each i.e. one libmaple and one stm32generic, however i found that as boards exist in multiple cores, the ‘core description’ text in the drop down is identical.
i don’t know how the hardware directory is read, which core is processed first etc.
so which core am i actually selecting a board from ?
if i want to try something in steves core, i’d need to rename it’s top directory or delete yours, the same is true for stm32generic.
also seems i’d installed the ST cores.

that post describes how i dealt with it.

stephen


hdleng
Mon Sep 25, 2017 7:56 pm
@zmemw16 and @roger,

Thank you for the continued help. I went to bed; I haven’t been ignoring you. I see that we’re in three widely separated time zones.

I seem to have Arduino IDE working for STM32. I simply uninstalled everything and then reinstalled according to your instructions. I am not aware that I did anything differently this time, but the results are successful. So, I must have mangled something on the previous attempt.

I appreciate your patience.

I can successfully compile the TimerInterrupts.ino for the Generic STM32F103C. The mcu on my Discovery Board is STM32F100RBT6B microcontroller, 128 KB Flash, 8 KB RAM in 64-pin LQFP. I can, of course, edit source files to address different I/O mapping. But the are differences in memory sizes (and perhaps on-chip peripherals). Is the a good way to adjust for that?

Thank you again for sticking with me,

Frank


zmemw16
Mon Sep 25, 2017 10:18 pm
i don’t think you’ll need to do anything as a suitable linker file is provided in the core.
i don’t know where or how it’s generated.
the linker file does change with the particular board variant selected, not a good idea to try a larger chip :D
i think if you go through the boards.txt & platform.txt as an ‘exercise’, you’ll probably find something.
stephen

RogerClark
Mon Sep 25, 2017 10:31 pm
You will need to make a new “variant” if you want to make extensive changes

There is a variant folder for each main type F103 MCU.

But initially I would recommend you just edit one of the existing variants, as it will save messing around with adding a new section in boards.txt to use a new “variant”


hdleng
Mon Sep 25, 2017 11:30 pm
@zmemw16, @roger,

An example of the incompatibility of the Discovery STM32F100 board with the Generic STM32F103C is the error ” ‘PC8’ was not declared in this scope”. I’ve determined that the board.h file does not have PC8 enumerated. Editing the enum fixes the compiler error (but, of course, that will create a bad binary). The board.cpp file contains the pin mapping, and I will have to edit it to correspond to my board. Then there’s the board.txt and platform.txt that will need to be adjusted. I think that I will follow Roger’s advice and simply edit an existing variant and get it working. I can add the Discovery Board properly afterwards.

You have been helpful in my learning the Arduino structure as it pertains to STM32.

Regards,

Frank


RogerClark
Mon Sep 25, 2017 11:56 pm
Frank

You don’t need to edit platform.txt for these sorts of changes.

You would only need to edit platform.txt if you have a different sort of upload method e.g. some other type of hardware programmer etc. Or you want to do something with the compiler options etc etc

The sort of changes you need can be done by editing the files in the variant folder and eventually, also changing boards.txt

BTW. The linker settings are in the *.ld files, its easy to change the RAM and Flash size

However 8k is not much RAM to play with… An empty sketch with USB support uses nearly.
You can often reduce RAM usage by selecting a different Optimisation setting. The default is for the smallest binary file, but I’ve noticed that this can result in more RAM usage.
AFIK 99% of things work on the default optimisation setting, but some things may not work if you select the higher optimisations (though I have not personally had any problems even at -O3 )


hdleng
Tue Sep 26, 2017 12:06 am
Roger,

I’m working on it now, following your instructions as best as I can understand. It will take a day or so along with the rest of my work load. I will post again when I am successful (or at a hopeless stand still).

It has become obvious, as I explore the inner workings of STM32duino, that you have done a great deal of work. You are very generous, and you have my thanks.

Frank


hdleng
Tue Sep 26, 2017 12:32 am
Roger,

One more thing. The Discovery STM32F100 board has two processors. An STM32F103C8T6 handles the USB. It can actually be used as a stand-alone ST-Link connected to other boards. The STM32F100R8T6B is for user code, but it does not need to execute USB functions itself. So, 8K of RAM is not so limiting.

Frank


RogerClark
Tue Sep 26, 2017 2:53 am
Hi Frank

I’d like to claim all the credit, but about 90% of the core comes from the original code that LeafLabs wrote for their Maple products in 2012.

Leaflabs abandoned it around 2015 and I picked it up after @bobc did some work to make it compatible with Arduino 1.5

Since then, I’ve changed / enhanced a lot of things, but there have been numerous contributions by various other people, so now its very much a community driven thing.

BTW. I also maintain the bootloader… But as your board probably has an STLink on it, you won’t be using that


zmemw16
Tue Sep 26, 2017 4:50 am
is this a DiscoveryVL ?
if yes, two thoughts
1. do the ST cores support it directly ?
2. do a search for “Geoff Brown Discovering the STM32 Microcontroller”
helpful link to the pdf :D
https://www.google.co.uk/url?sa=t&rct=j … nCPLiIB-dQ
admittedly it’s using the classical ‘C’ approach, but it does provide a great amount of information. :lol:

adding a definitive 3. :lol: :lol:
3. http://stm32duino.com/viewtopic.php?t=1741#p22876
stephen


RogerClark
Tue Sep 26, 2017 5:45 am
It had crossed my mind that Frank could look at STM’s own core.

https://github.com/stm32duino/Arduino_Core_STM32

However, STM don’t have a variant for his board, so he’d need to do the same thing.

Also, AFIK STM don’t have any examples of how to use the hardware timers, so he would need to learn how to use STM’s HAL programming API before he could do anything.

I looked at the PDF of that online book, but it days

Throughout this book we utilize the ST Standard Peripheral Library

Not the HAL, so its not necessarily that useful in terms of learning how to program using STM’s core


zmemw16
Tue Sep 26, 2017 6:48 am
@hdleng
something tells me i shouldn’t, but does a STM32F100RB have a Timer2 ?
if yes then something is wrong in the variant files, typo ? maybe it’s something mis-spelt, Timner2 ? ? ?
if no then solved :D

i’ll assume you can re-apply ideas from linux based tutorials to a windows setup if needed
that’s a seriously hard sentence for me to type :!:

there is a book, i got it from Amazon; not a recommendation – on the off-chance, it does use CubeMX and eclipse with the gnu arm eclipse plug-in, for £2 why not ?

Getting Started With STM32 Nucleo Development (Kindle Edition) by Agus Kurniawan

found a couple of sites/blogs/tuts, this has a bit
http://elastic-notes.blogspot.co.uk/
another with bits
http://www.scienceprog.com/driving-grap … 2f103zet6/
and then there’s ST Community
https://community.st.com/thread/15404
and this
http://scaluza.com/stm32f4/intro-in-stm32f4cubemx/

just browse around those, they’re just some of my open tabs from several firefox windows
actually i should just zip up my history file or bookmarks from firefox or my mega-booklist.html file :lol:

and then of course, there’s youtube :roll:
i find watching a video tutorial is more off-putting, can never hit pause fast enough and iterating back and forth to the frame … … and then there’s the music and then it’s audio is in russian or german or french

stephen


hdleng
Tue Sep 26, 2017 8:14 am
Roger and Stephen,

Your advice has been helpful, and I’m now well on my way. I’ll update my progress.

Prior to my foray into Arduino, I had been using linux command line and scripts to develop with gcc for ARM. I use the ST peripheral libraries. Geoff Brown’s book is a good one, and I pretty much followed his methodology. I’ve used that development environment for most of my STM32F1 work.

Separately, I use Eclipse running on Windows for STM32F4 work. That makes the work a little more automated. And, I wanted to learn Eclipse anyway. Carmine Noviello’s book, Mastering STM32, is a very good reference in setting up the tools and for doing STM32F4 specific work.

I’ve modified one of the STM32F103 variants to work with my STM32F100 board. I could compile and upload the timerinterrupt.ino, but it did not execute properly. As Stephen anticipated, timer2 is not implemented as called for in the program. Timer1 is the advanced timer on the processor, and by changing the code to use it, I have managed to get it working.

The work that I had done using bare metal code and the ST libraries gave me low-level familiarity with the timers; so, it wasn’t very difficult to troubleshoot the problems.

Now the I’m past most of the learning curve for STM32duino, I will be able to make fast work of projects that can tolerate the software overhead that accompanies Arduino. Sometimes my work involves prototyping a design, running it once, then tearing it apart. Arduino makes good sense on those occasions. On the other hand, I get right down next to the hardware using C or even assembly when performance requires it, and volume justifies it.

Even using this ST Discovery board doesn’t make very much sense except as a learning tool. I have already ordered some STM32F103-based boards; so, I can take advantage of the STM32duino configurations that are already in place.

Thank both of you gentlemen for your help. I’m sure we’ll correspond again someday on other matters.

Best Regards,

Frank


RogerClark
Tue Sep 26, 2017 10:24 am
Hi Frank

I’m glad you are getting to grips with things..

I’ve marked the thread as SOLVED and changed the title a bit to help anyone else who may be trying to use the same board.

I’ll move this thread to the appropriate section (again to help anyone else with the same board – as most of the problems were related to this being a type of board no one had tried running Arduino on before)


Leave a Reply

Your email address will not be published. Required fields are marked *