Author Topic: importing arduino "sketch" to Microchip Studio  (Read 6162 times)

0 Members and 1 Guest are viewing this topic.

Online Simon

  • Global Moderator
  • *****
  • Posts: 16653
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: importing arduino "sketch" to Microchip Studio
« Reply #25 on: October 10, 2021, 07:35:48 pm »
OK, I got it, that is a list of the libraries that depend on this one, not really useful, I need to know what other libraries this one depends on. If i look at the api documentation page I get a list of files, do I need these? I mean it's not like someone is intentionally not very well documenting this stuff are they. It seems everywhere I go to involving programming assumes I know something but no one explains the stuff that apparently I should know already from some secret source!
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 3715
  • Country: us
Re: importing arduino "sketch" to Microchip Studio
« Reply #26 on: October 10, 2021, 08:19:42 pm »
Quote
The specific chip is irrelevant to the discussion. We were talking about how to open the Arduino code in Microchip studio.
My experience (limited) with the Studio "Import Arduino Sketch" is that it works pretty well for Official AVR-based Arduino boards, but is pretty questionable on the SAMD boards (even the Arduino official SAMD boards.)  And it may be pretty hopeless on 3rd party boards/packages :-(

AFAIK, this feature was added to Studio back during the infancy of the current Board and Library management system, and has not been very actively maintained :-(


Quote
I don'n know C++ yet so have some books on the way
Unfortunately, most C++ books are likely to send you off in unproductive directions, if your goal is to understand Arduino/embedded C++.
(Not unlike C books, if you want to write embedded C.)

Quote
I believe one of the big potential pitfalls of the Arduino is that it tries to have a uniform usage on many different micro controllers.
Silly me.  I thought platform independence was a good thing, most of the time.

Quote
// Arduino.h should properly define PROGMEM, PGM_P, strcpy_P, pgm_read_byte, pgm_read_ptr
PROGMEM, strcpy_P, etc, are the special functions for AVR's Harvard architecture to access data in flash memory.  They're completely unnecessary on ARM CPUs, but it "would be nice" for them to be aliased for backward compatibility.  Many Arduino non-AVR platforms do that.

Quote
// if any this becomes unnecessary as platforms improve, please send a pull req.
"Pull Request" is a github thing.  This is approximately "if you fix this, let us know what you did."


Quote
there does not seem to be a well defined way to have a program in multiple files in the arduino "IDE".
There is, although I don't know whether the Microchip Studio continues to follow it.
Multiple .ino files are concatenated into a single file, which then goes through arduino "pre-processing" to generate prototypes and derive library paths.
Assembler, C and C++ (.S, .c, .cpp) files are compiled individually and "normally"; that means they need their own prototypes to allow forward references, plus "extern" declarations (even in the .ino files), and probably at least "#include <Arduino.h>" to pull in the Arduino definitions.
So you can split a .ino file into multiple .ino files relatively easily, but extracting some of the code into .cpp files will require more effort.

 

Online Simon

  • Global Moderator
  • *****
  • Posts: 16653
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: importing arduino "sketch" to Microchip Studio
« Reply #27 on: October 10, 2021, 08:35:14 pm »

Quote
I believe one of the big potential pitfalls of the Arduino is that it tries to have a uniform usage on many different micro controllers.
Silly me.  I thought platform independence was a good thing, most of the time.


Yes providing it does not introduce bugs and make a mess of things. I have come across a a few funnies in the little amount I have used arduino and prefer to be truly platform independant not locked to some system. Right now I spend more time trying to work out what is what than just looking at programming the thing.

I tried making everything an ino file but it fell over. So is the ino file like a C file, so I create an accompanying header file for each for function prototypes? if so why all the bat shit crazy stuff on arduino forums about how to do it? that is why I do not like it, everyone is suddenly an expert and the ones that do most the talking are the ones doing it wrong!
 

Offline Nusa

  • Super Contributor
  • ***
  • Posts: 2223
  • Country: us
Re: importing arduino "sketch" to Microchip Studio
« Reply #28 on: October 10, 2021, 10:12:44 pm »
You might find this useful: https://arduino.github.io/arduino-cli/0.19/sketch-build-process/

From a user viewpoint, ino files are cpp files with the usual stuff like function prototypes added in preprocessing and arduino.h included at the top before it's handed to the usual compiler. Makes it very easy for newbies to get off the ground with no h file required.

The arduino-style setup() loop() structure is implemented by the default main() that looks very much like (it's in main.cpp in the core, if you want to find it):
Code: [Select]
int main(void){
  init(); // init hardware timers, etc
  setup(); // user setup function
  for(;;){
    loop(); // user run function
  }
  return 0;
}
If you provide your own main(), it'll override the default one and you can do what you want. Remember to still call init() or otherwise initialize stuff.
 

Online Simon

  • Global Moderator
  • *****
  • Posts: 16653
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: importing arduino "sketch" to Microchip Studio
« Reply #29 on: October 11, 2021, 12:19:23 pm »
So I have created a new project in studio and added the files from SDfilesystem and FATfilesystem on the mbed website. The empty project compiles file using over 5kB of RAM so I assume that these files were compiled in and all is fine. Now I just need to work out what to do with them.....
 

Offline DrG

  • Super Contributor
  • ***
  • !
  • Posts: 1203
  • Country: us
Re: importing arduino "sketch" to Microchip Studio
« Reply #30 on: October 13, 2021, 12:34:22 pm »
So now the fun starts....locating every usage of the the Arduino SD lib in the original Arduino code and then writing functions that mimic those calls using "your" library. Actually, this may not be too much of a pita since the original is, hopefully just doing the usual; open/create file, write value, read values, close file; error reporting.

Wait until you get to the BLE part :)
- Invest in science - it pays big dividends. -
 

Online Simon

  • Global Moderator
  • *****
  • Posts: 16653
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: importing arduino "sketch" to Microchip Studio
« Reply #31 on: October 14, 2021, 07:26:48 pm »
Well I will reuse all that I can and just write the hardware stuff.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf