Fixing Compilation Errors

I am trying to implement Jasper's R3 Electronic Load:

I have the hardware built and to the point of loading the Arduino code but I'm getting compilation errors.

I have both Arduino IDE 2.3.2 and Arduino 1.8.3

Maybe this was written in a previous version of Arduino because when I try to upload the code, I get compliation errors such as:

cmdproc.h:16:3: error: conflicting declaration 'typedef struct cmd_t cmd_t'
   16 | } cmd_t;
      |   ^~~~~
// maximum number of arguments (including command itself)
#define CMD_MAX_ARGS 50

// default result codes
#define CMD_OK      0
#define CMD_NO_CMD  -0x7F00
#define CMD_UNKNOWN -0x7F01

typedef int (cmd_fn)(int argc, char *argv[]);

// command table entry
typedef struct {
    const char *name;
    cmd_fn *cmd;
    const char *help;
} cmd_t;

/**
 * Parses the given line into arguments, matches it with a command and executes the command.
 * @param[in] commands command table
 * @param[in] line the line to parse
 * @return the result of command execution
 */
int cmd_process(const cmd_t *commands, char *line);

I am not seasoned enough of a programmer to understand the issue.

There are a bunch of other compilation errors where it talks about conflicting declarations or previous declarations but I'll start with this error.

Can someone help me figure out how to get this to compile?

typedef struct  cmd_t{
    const char *name;
    cmd_fn *cmd;
    const char *help;
};

or maybe

typedef struct  cmd_t{
    const char *name;
    cmd_fn *cmd;
    const char *help;
}cmd_t;

Perfect!

I used:

typedef struct  cmd_t{
    const char *name;
    cmd_fn *cmd;
    const char *help;
};

This cleared up that compilation error. That solution also fixed another struct and enum giving errors. There was also code where header files were listed twice causing a bunch of errors.

I am down to 5 compilation errors.

Hopefully I can figure those out. If not, I will slap them up here.

Thanks!

typedef is soooooo 1980s 'C'. Try:

using cmd_fn = int (*)(int argc, char *argv[]);

// command table entry
struct cmd_t {
  const char *name;
  cmd_fn cmd;
  const char *help;
};

I have been trying to get the code for Jasper's Electronic Load to compile and I am down to one error and I can't figure it out. I can't find where pwmtimer is defined and have no idea how to fix it.

My first thread on trying to get the code to compile is here:

I believe this is my final error:

current.cpp:22:31: error: invalid conversion from 'int' to 'TIM_TypeDef*' [-fpermissive]
   22 | static HardwareTimer pwmtimer(2);
      |                               ^
      |                               |
      |                               int

Does any one have advice on how to tackle this one?

Thanks!

Please follow the forum rules and post the entirety of the code you are trying to compile, using code tags.

The error message makes it clear that "2" is an inappropriate argument to the function you call.

Edit: cross post moved after I posted the above.

Your two or more topics on the same or similar subject have been merged.

Please do not duplicate your questions as doing so wastes the time and effort of the volunteers trying to help you as they are then answering the same thing in different places.

Please create one topic only for your question and choose the forum category carefully. If you have multiple questions about the same project then please ask your questions in the one topic as the answers to one question provide useful context for the others, and also you won’t have to keep explaining your project repeatedly.

Repeated duplicate posting could result in a temporary or permanent ban from the forum.

Could you take a few moments to Learn How To Use The Forum

It will help you get the best out of the forum in the future.

Thank you.

My apologies.

I thought that it would be a good thing to make a new post because it is on the same project but is a slightly different question and will have a different answer. Since I already marked the previous one as "solved" I thought it would be good to reference it and start my new question.

I don't want to waste anyone's time or get banned so I will not do that again.

The problem with starting a new topic is that all of the background information is not immediately available even if you post a link to the previous topic

There is also a chance that someone who helped in the original topic does not realise that the new one is associated with it and does not read the new one

1 Like

After reading through "How to get the best out of this forum"
I am posting the full error copied from the Arduino IDE.

C:\Users\ENG\Desktop\ElectronicLoad-master(1)\ElectronicLoad\current.cpp:22:31: error: invalid conversion from 'int' to 'TIM_TypeDef*' [-fpermissive]
   22 | static HardwareTimer pwmtimer(2);
      |                               ^
      |                               |
      |                               int
In file included from C:\Users\ENG\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.1.0\cores\arduino/stm32/analog.h:45,
                 from C:\Users\ENG\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.1.0\cores\arduino/board.h:8,
                 from C:\Users\ENG\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.1.0\cores\arduino/wiring.h:41,
                 from C:\Users\ENG\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.1.0\cores\arduino/Arduino.h:36,
                 from C:\Users\ENG\Desktop\ElectronicLoad-master(1)\ElectronicLoad\current.cpp:17:
C:\Users\ENG\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.1.0\cores\arduino/HardwareTimer.h:101:32: note:   initializing argument 1 of 'HardwareTimer::HardwareTimer(TIM_TypeDef*)'
  101 |     HardwareTimer(TIM_TypeDef *instance);
      |                   ~~~~~~~~~~~~~^~~~~~~~

exit status 1

Compilation error: invalid conversion from 'int' to 'TIM_TypeDef*' [-fpermissive]

Thank you all for your time and help!

As @jremington stated, the compiler is telling you that the constructor for the HardwareTimer class does not take an integer argument. If you look in HardwareTimer.h, you'll see that:

    HardwareTimer();
    HardwareTimer(TIM_TypeDef *instance);

So, the available constructor overloads take either no argument or a pointer to a TIM_TypeDef object. The code you are trying to copy is very old. It's possible that the API for the STM32 HardwareTimer has changed since then.

It seems that your choices are either to find out which version of the STM32 Arduino Core this code was written for (the most recent version is 2.8.0, you're apparently using 2.1.0) and down grade to that. Or, you'll need to rewrite the application code to use HardwareTimer APIs for the version that you have installed or later.

I would be open to either but I can't seem to get a hold of the STM32 Arduino Core that is older than 2.0.0.

Do you know how to get older cores?

If I can't I get old cores, I will be forced to rewrite with a newer core but I will probably base it off of the 2.1.0 because when I upgraded to the 2.8.0, it generated even more compiliation errors and I don't want to rewrite more than I need to.

The code for all previous releases is here:
https://github.com/stm32duino/Arduino_Core_STM32/releases?page=1
But, I honestly don't know how to install them if the IDE doesn't offer up the version. There are people here on the forum who are much more versed in tool chain management than I. Perhaps someone will chime in.

Thanks!

I grabbed 1.8.0 and 1.9.0 because those were released around the time this code was last modified.

I will try the instructions on here to install the libraries:
https://docs.arduino.cc/software/ide-v1/tutorials/installing-libraries/

With the help of an STM32 core maintainer, I was pointed to the json to install older core versions through the board manager:
https://raw.githubusercontent.com/stm32duino/BoardManagerFiles/master/STM32/package_stm_index.json

I played around with versions between 1.9.0 and 1.6.0.

Unfortunately I end up with compilation errors regardless. With versions 1.9.0 through 1.7.0 I get the same compilation errors as before.

When runnning 1.6.1 and 1.6.0 I start getting:

Using library Wire at version 1.0 in folder: C:\Users\PDI User\AppData\Local\Arduino15\packages\STM32\hardware\stm32\1.6.1\libraries\Wire 
Using library SPI at version 1.0 in folder: C:\Users\PDI User\AppData\Local\Arduino15\packages\STM32\hardware\stm32\1.6.1\libraries\SPI 
exit status 1
'HardwareTimer' does not name a type; did you mean 'HardwareSerial'?

I must be missing something because this open source product was sold on tindie for a while, so the code must have worked with some combination of Arduino version and STM32 core version but I can't figure that one out.

It looks like I will be doing some code modification and get it running with one of the more late version of the STM32 core.

With regards to modifying. I lack some of the finer points of programming and I'm not sure where problematic "pwmtimer" is instantiated. I can't find it in any of the associated .cpp or .h files.

Can some one help me figure out where that comes from?

From some of the associated files, it appears that this was developed using PlatformIO. I am digging into that too but I don't really know how to run that yet either. This is certainly more of a battle than I thought it would be.

Your initial code seems to be written for another Arduino STM32 package - the one from Roger Clark

As far as I know, this syntax

is compatible with Clark's code.

1 Like

Perfect! Thanks @b707

I manually installed that package and it now compiles without issue!

Sketch uses 30512 bytes (46%) of program storage space. Maximum is 65536 bytes.
Global variables use 3608 bytes (17%) of dynamic memory, leaving 16872 bytes for local variables. Maximum is 20480 bytes.
maple_loader v0.1
Resetting to bootloader via DTR pulse
Reset via USB Serial Failed! Did you select the right serial port?
Searching for DFU device [1EAF:0003]...
Assuming the board is in perpetual bootloader mode and continuing to attempt dfu programming...

Found it!

Opening USB Device 0x1eaf:0x0003...
Found Runtime: [0x1eaf:0x0003] devnum=2, cfg=0, intf=0, alt=2, name="STM32duino bootloader v1.0  Upload to Flash 0x8002000"
Setting Configuration 1...
Claiming USB DFU Interface...
Setting Alternate Setting ...
Determining device status: state = dfuIDLE, status = 0
dfuIDLE, continuing
Transfer Size = 0x0400
bytes_per_hash=610
Starting download: [##################################################] finished!
error resetting after download: usb_reset: could not reset device, win error: A device which does not exist was specified.

However, after download, windows says that the device has malfunctioned.

Thanks for all of the help!!!!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.