Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
7 years, 1 month ago.
Error Status: 0x80FF0100 Code: 256 Module: 255
I am using the Nucleo f401re device with mbed library. I encounter the "Cannot initialize PWM" error whenever writing period to the same PwmOut object more than 10 times.
Can you anybody let me know how to fix it?
There was no problem with the mbed library released two years ago.
1 Answer
7 years, 1 month ago.
Hi Ryan,
We're sorry that it's taken a few days to look at this, but the issue is that your tones[] array has some zero entries and that appears to be a problem for the STM32 driver. We haven't put a debugger on this but you are likely failing the last if-statement in this block of code and that's why you are getting the "Cannot initialize PWM" message:
If we modify Tune() to set any zero values of the period to a reasonable value, then the program runs to completion. We've noted that you are calling Tune() 32 times, but tones[] only has 31 entries so you get one extra lame-duck call that looks benign when we ran it, but is certainly a bug.
Regards,
Ralph, Team Mbed
Hi Ryan,
Could you please update your post to include your source code? Please encapsulate it with code tags as shown in the "Editing tips" so it will properly appear such as this:
Are you building with Online Compiler?
-Ralph, Team Mbed
posted by Ralph Fulchiero 02 Oct 2018I used both Online Compiler and off-line Keil uVision5 Tools. My test code is below.
#include "mbed.h" #define Do3 1000000/131 //C octave3 #define Do3s 1000000/139 //C# #define Re3 1000000/147 //D #define Re3s 1000000/156//D# #define Mi3 1000000/165 //E #define Fa3 1000000/175 //F #define Fa3s 1000000/185 //F# #define So3 1000000/196 //G #define So3s 1000000/208 //G# #define La3 1000000/220 //A #define La3s 1000000/233 //A# #define Ti3 1000000/247 //B #define Do4 1000000/262 //C octave4 #define Do4s 1000000/277 //C# #define Re4 1000000/294 //D #define Re4s 1000000/311//D# #define Mi4 1000000/330 //E #define Fa4 1000000/349 //F #define Fa4s 1000000/370 //F# #define So4 1000000/392 //G #define So4s 1000000/415 //G# #define La4 1000000/440 //A #define La4s 1000000/466 //A# #define Ti4 1000000/494 //B #define Do5 1000000/523 //C octave5 #define Do5s 1000000/554 //C# #define Re5 1000000/587 //D #define Re5s 1000000/622//D# #define Mi5 1000000/659 //E #define Fa5 1000000/699 //F #define Fa5s 1000000/740 //F# #define So5 1000000/784 //G #define So5s 1000000/831 //G# #define La5 1000000/880 //A #define La5s 1000000/932 //A# #define Ti5 1000000/988 //B PwmOut Buzzer(PC_9); Serial pc(USBTX, USBRX); int tones[] = {Mi4, Re4, Do4, Re4, Mi4, Mi4, Mi4, 0, Re4, Re4, Re4, 0, Mi4, So4, So4, 0, Mi4, Re4, Do4, Re4, Mi4, Mi4, Mi4, 0, Re4, Re4, Mi4, Re4, 0, 0, 0}; int tones_num = 32; void Tune(int period, int beat) { int delay; delay = beat*63; Buzzer.period_us(period); Buzzer.write(0.50f); // 50% duty cycle wait_ms(delay); // 1 beat } int main (void) { pc.baud (115200); pc.printf("Buzeer Test Start\r\n"); for (i=0; i<tones_num; i++) { Tune(tones[i], 4); } Buzzer = 0; }