Square wave output from timer pin

fredbox
Mon Feb 11, 2019 5:52 am
I’m attempting to convert a libmaple project to the official fpiSTM core. I spent a good portion of the afternoon researching how to create a 50 percent duty cycle square wave on a timer pin that wasn’t too complicated.

The code needed turned out to be simple:
//void pwm_start(PinName pin, uint32_t clock_freq, uint32_t period, uint32_t value, uint8_t do_init)
// set pwm frequency to 60.0 khz at 50% duty cycle on PA_6
pwm_start(PA_6, F_CPU, 1200, 600, 1);


ted
Wed Feb 20, 2019 3:46 am
Looks simple but is not working.
//pinMode(PA6, PWM);
//void pwm_start(PinName pin, uint32_t clock_freq, uint32_t period, uint32_t value, uint8_t do_init)
// set pwm frequency to 60.0 khz at 50% duty cycle on PA_6
//void pwm_start(PA_6, F_CPU, 1200, 600, 1);
pwm_start(PA_6, F_CPU, 1200, 600, 1);
void setup()
{
pinMode(PA6, PWM);
}

fredbox
Wed Feb 20, 2019 5:12 am
That example is for the official STM core v1.5.0 installed with the board manager. If you are using Roger’s core, then you would use the Leaflabs Timer API to configure the pwm pin:HardwareTimer pwmtimer(3);
setup() {
pinMode(PA6,PWM );
pwmtimer.pause();
pwmtimer.setPrescaleFactor(1);
pwmtimer.setOverflow(1200 - 1); // 72MHZ / 1200 = 60KHZ
pwmtimer.setCompare(TIMER_CH1, 600 - 1); // 50% duty cycle
pwmtimer.refresh();
pwmtimer.resume();
}

ted
Wed Feb 20, 2019 5:27 pm
this is the error for when I switched board from SM32Fduino.com to SM32 Boars ( selected from submenu)

Build options changed, rebuilding all
exec: “C:\\Users\\ted\\AppData\\Local\\Arduino15\\packages\\STM32\\tools\\arm-none-eabi-gcc\\6-2017-q2-update/bin/arm-none-eabi-g++”: file does not exist
Error compiling for board Generic STM32F103 series.


martinayotte
Wed Feb 20, 2019 8:36 pm
[ted – Wed Feb 20, 2019 5:27 pm] –
exec: “C:\\Users\\ted\\AppData\\Local\\Arduino15\\packages\\STM32\\tools\\arm-none-eabi-gcc\\6-2017-q2-update/bin/arm-none-eabi-g++”: file does not exist

This looks like a mixture of windows path with linux path together … :?


ted
Thu Feb 21, 2019 3:33 am
I just thinking how to fix this error: expected constructor, destructor, or type conversion before ‘(‘ token

fredbox
Thu Feb 21, 2019 5:44 pm
void setup()
{
// pinMode(PA6, PWM); // this line isn't needed
pwm_start(PA_6, F_CPU, 1200, 600, 1); // this line goes in setup()
}

ted
Thu Feb 21, 2019 6:46 pm
int (PA_6);
//int (pwm_start);
//pinMode(PA6, PWM);
//pwm_start(PA_6, F_CPU, 1200, 600, 1);

void setup()
{
pinMode(PA_6, PWM);
//void pwm_start(PinName pin, uint32_t clock_freq, uint32_t period, uint32_t value, uint8_t do_init)
//pwm_start(PA_6, uint32_t 72000000, uint32_t 1200, uint32_t 600, uint8_t 1);
// set pwm frequency to 60.0 khz at 50% duty cycle on PA_6
//void pwm_start(PA_6, F_CPU, 1200, 600, 1);
pwm_start(PA_6, F_CPU, 1200, 600, 1);
}
void loop()
{}


ted
Thu Feb 21, 2019 6:50 pm
with this line
int (PA_6);
int (pwm_start);
//pinMode(PA6, PWM);
//pwm_start(PA_6, F_CPU, 1200, 600, 1);

fredbox
Thu Feb 21, 2019 8:30 pm
void setup() {
pwm_start(PA_6, F_CPU, 1200, 600, 1);
}
void loop() {
}

ted
Thu Feb 21, 2019 9:30 pm
I was trying to find it here = no luck, can you give me the link ?
https://www.st.com/content/st_com/en/search.html#q=stm32f103 board-t=tools-page=1

fredbox
Thu Feb 21, 2019 10:02 pm
Install from the board manager. Tools->Board xxx -> Board manager. Type STM32 in search field.

stm32bm.png
stm32bm.png (4.73 KiB) Viewed 249 times

ted
Thu Feb 21, 2019 10:42 pm
this is what i get
Image
I remember this board, but is not on the list now
even if i type only stm32

fredbox
Thu Feb 21, 2019 11:04 pm
Your screen capture is from Library Manager – the one I posted was Boards Manager.

See https://github.com/stm32duino/Arduino_Core_STM32

Getting Started
This repo is available as a package usable with Arduino Boards Manager.
Use this link in the “Additional Boards Managers URLs” field:
https://github.com/stm32duino/BoardMana … index.json


ted
Fri Feb 22, 2019 1:24 am
oops – Library instead Board.
I update from 1.4 to 1.5
No blue pill on the list – yet
Image

Image


ted
Fri Feb 22, 2019 2:40 am
I removed STM32 cores and installed again
Blue pill still not on the list and the new error confirmed that, what to do ?

Arduino: 1.8.8 (Windows Vista), Board: “Generic STM32F1 series, BluePill F103C6 (32K), STLink, Enabled (generic ‘Serial’), None, Low/Full Speed, Smallest (-Os default), Newlib Nano (default)”

exec: “C:\\Users\\ted\\AppData\\Local\\Arduino15\\packages\\STM32\\tools\\arm-none-eabi-gcc\\6-2017-q2-update/bin/arm-none-eabi-g++”: file does not exist
Error compiling for board Generic STM32F1 series.

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


fredbox
Fri Feb 22, 2019 3:27 am
You should also install Arduino SAM Boards from the boards manager, I show v1.6.12 installed.

ted
Fri Feb 22, 2019 3:50 am
I updated it – still no blue pill on the list
Image

ted
Fri Feb 22, 2019 3:53 am
Image

ted
Fri Feb 22, 2019 3:59 am
I also added arduino core to Hardware folderImage

fpiSTM
Fri Feb 22, 2019 4:54 am
This is not the right place.
https://github.com/stm32duino/wiki/wiki … repository


ted
Fri Feb 22, 2019 5:50 am
Thanks for links, I have followed to similar links as the second one, the first one – I do not really want to touch it

ted
Fri Feb 22, 2019 5:53 am
Should I have here listed – blue pill ?

ted
Fri Feb 22, 2019 6:25 am
Are you using Windows ?
The error ;
Arduino: 1.8.8 (Windows Vista), Board: “Generic STM32F1 series, BluePill F103C6 (32K), STLink, Enabled (generic ‘Serial’), None, Low/Full Speed, Smallest (-Os default), Newlib Nano (default)”

Build options changed, rebuilding all
exec: “C:\\Users\\ted\\AppData\\Local\\Arduino15\\packages\\STM32\\tools\\arm-none-eabi-gcc\\6-2017-q2-update/bin/arm-none-eabi-g++”: file does not exist

Is explained here


fpiSTM
Fri Feb 22, 2019 6:31 am
Don’t know how you handle install but Arduino_Core_STM32 require arm gcc v6.
So install it from the board manager then it will install all required dependencies (tools, arm gcc and CMSIS).

ted
Fri Feb 22, 2019 6:37 am
I have no problems with other programs, only this one = title of the thread

BennehBoy
Fri Feb 22, 2019 8:35 am
[ted – Fri Feb 22, 2019 5:53 am] –
Should I have here listed – blue pill ?

The menu section you posted is not STM’s core, it’s Roger’s.

I think you need to start afresh and follow the instructions linked by fpistm.

I suspect the folder ‘maple’ in your hardware folder is Roger’s – to save yourself confusion you should remove it.

This is what you should see from the official core:

STMmenu.jpg
STMmenu.jpg (11.01 KiB) Viewed 160 times

ted
Fri Feb 22, 2019 4:05 pm
I have both, I using Rogers to run other programs, which do not work without it.

ted
Fri Feb 22, 2019 4:31 pm
I will try on Windows 10

BennehBoy
Fri Feb 22, 2019 4:48 pm
In that case I think you just need to reinstall the STM one via the board manager.

ted
Fri Feb 22, 2019 4:58 pm
I will use my wife PC, keep that in secret or she will kill me. :evil: :lol:

fredbox
Fri Feb 22, 2019 7:09 pm
I normally use Linux Mint, but today I installed W10 on a spare hard drive followed by a fresh install of Arduino and the STM core from the board manager. The test program using pwm_start compiled to 9868 bytes in W10.

ted
Fri Feb 22, 2019 7:44 pm
In Windows 10 is compiling, but st link is not working

A subdirectory or file sketch already exists.

Sketch uses 11348 bytes (34%) of program storage space. Maximum is 32768 bytes.

Global variables use 856 bytes (8%) of dynamic memory, leaving 9384 bytes for local variables. Maximum is 10240 bytes.

STM32 ST-LINK CLI v3.2.0.0

STM32 ST-LINK Command Line Interface

ST-LINK SN : 48FF6E065067545651410687

ST-LINK Firmware version : V2J32S7

Connected via SWD.

SWD Frequency = 4000K.

Target voltage = 3.2 V.

Connection mode : Normal.

Device ID:0x410

Device flash Size : 64 Kbytes

Device family :STM32F10xx Medium-density

Loading file…

Unable to open file!

MCU Reset.

run application to exit

Application started.

An error occurred while uploading the sketch


fredbox
Fri Feb 22, 2019 9:03 pm
Open a command window and navigate to the folder that contains ST-LINK_CLI.exe. See if you can run this program from a command prompt.

On my fresh W10 install, I get an error about two missing DLLs. There are probably MSVC runtime files that need to be installed.

From Arduino, I see the same error message.


ted
Fri Feb 22, 2019 9:49 pm
Finally I have uploaded using serial port ,I added a second channel with some phase shift.
https://www.stm32duino.com/viewtopic.php?f=19&t=4523
Thanks for your support, letter I will work on st link, I saw that some guys have a problem to make it working with W10

fredbox
Fri Feb 22, 2019 11:45 pm
Installing the Visual C++ 2010 runtime files from Microsoft resolves the DLL missing error but st-link upload still fails with “unable to load file.”

ted
Sat Feb 23, 2019 1:28 am
I was trying to use st link on MAC using this link
https://github.com/rogerclarkmelbourne/ … stallation
may be you have similar problem.

fredbox
Sat Feb 23, 2019 5:19 am
After editing stlink_upload.bat to change set str=%4 to set str=%3, upload now works on Windows 10. This is possibly the same issue that Roger fixed here: https://github.com/rogerclarkmelbourne/ … issues/584

ted
Sat Feb 23, 2019 3:04 pm
I glad that you fix the problem, I will stay with USB (not my PC).
Your code allows to make the simplest program for 3 phase generator with 120 deg. shift using only one timer = unique

Leave a Reply

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