How do I get my AWU ISR into the interrupt vector table? [SOLVED -- RTFM!]

Arduino on the STM8 (8 bit processor)
dannyf
Posts: 231
Joined: Wed May 11, 2016 4:29 pm

Re: How do I get my AWU ISR into the interrupt vector table? [SOLVED -- RTFM!]

Post by dannyf » Thu Jan 11, 2018 7:05 pm

Time and again, reading the manual has been the most effective way of understanding how a compiler works.

Btw, that requirement of declaring the ISRs in the main.c is a weird one. In my book it makes the compiler not workable.

zmemw16
Posts: 1687
Joined: Wed Jul 08, 2015 2:09 pm
Location: St Annes, Lancs,UK

Re: How do I get my AWU ISR into the interrupt vector table? [SOLVED -- RTFM!]

Post by zmemw16 » Thu Jan 11, 2018 8:18 pm

totally random thought, in a way isn't it a forward declaration so maybe main.h or is it explicitly stated as being in main.c
or it's being used much earlier than you think, maybein the startup code ?
srp

Jimmus
Posts: 16
Joined: Tue Nov 28, 2017 4:08 am

Re: How do I get my AWU ISR into the interrupt vector table? [SOLVED -- RTFM!]

Post by Jimmus » Thu Jan 11, 2018 8:57 pm

Yeah, it is a pretty strange requirement. Not at all intuitive.

@zmemw16 well, that's what the manual said -- "a prototype of the isr MUST be present in the file that contains the function 'main'." Main.c included <Arduino.h>, which included "stm8s_it.h", which is where I ultimately uncommented the prototype. I tried putting the prototype into main.c instead, and that worked as well.

Another thing that worked was creating my own main() function in my .ino file. I did have to go comment out all the stuff in main.c so it didn't complain about that, but it did work.

dannyf
Posts: 231
Joined: Wed May 11, 2016 4:29 pm

Re: How do I get my AWU ISR into the interrupt vector table? [SOLVED -- RTFM!]

Post by dannyf » Sat Jan 13, 2018 12:19 am

I haven't had much luck with sdcc. last time i tried it (a few years back), i couldn't get it to trim off unused code. as i develop my code modularly, each project contains all sorts of pieces that may not be used for a given project. the inability to cut out unused code produces gigantic hex files.

this notion of having to declare your isrs in main.c is equally idiotic, in my view.

IAR or Cosmic is my choice on STM8.

User avatar
mrburnette
Posts: 2236
Joined: Mon Apr 27, 2015 12:50 pm
Location: Greater Atlanta
Contact:

Re: How do I get my AWU ISR into the interrupt vector table? [SOLVED -- RTFM!]

Post by mrburnette » Sat Jan 13, 2018 3:41 am

Jimmus wrote:
Thu Jan 11, 2018 8:57 pm
Yeah, it is a pretty strange requirement. Not at all intuitive.

@zmemw16 well, that's what the manual said -- "a prototype of the isr MUST be present in the file that contains the function 'main'." Main.c included <Arduino.h>, which included "stm8s_it.h", which is where I ultimately uncommented the prototype. I tried putting the prototype into main.c instead, and that worked as well.

Another thing that worked was creating my own main() function in my .ino file. I did have to go comment out all the stuff in main.c so it didn't complain about that, but it did work.
Guess I discovered the weirdness so long ago that I now believe it is intuitive :lol:

It's the way the IDE works that makes this a requirement; ArduinoIDE generally tries to build the prototyping for you... all of the files in the Arduino sketch directory are concatenated and then that temp file is sent to the compiler as one file. In my projects, I generally put library files into the sketch folder (so I can ZIP everything needed and snapshot the version), so the prototyping (forward declaration) must appear in the sketch.ino before the setup() section.

Ray

Jimmus
Posts: 16
Joined: Tue Nov 28, 2017 4:08 am

Re: How do I get my AWU ISR into the interrupt vector table? [SOLVED -- RTFM!]

Post by Jimmus » Mon Jan 15, 2018 6:59 am

So I have a question about this, Ray. It wasn't just in my .ino file that I had to make the declaration. I had already tried that. I actually had to go find the stm8_it.h file and modify that. I don't have a major problem with that, because it's my system and I can do it any way I want as long as it works. That's the beauty of open source. But it would be nice if I could kinda compartmentalize things and keep them in their nice little places and only modify things in my little branch of the directory structure. Is there an include file in my project directory that Arduino.h would include if it were there?

Because I'm seeing a little bit of what dannyf mentioned about trimming out unused code. The UART is great for debugging and certain kinds of projects, but my little standalone mailbox detector doesn't need serial communication. The AVR platform automatically trims all that stuff out if you don't use it. I can see that there are some things in the STM8 code to do the same thing, but some of them still have issues. For example, if I don't do any pinMode() or digitalWrite() kinds of calls, it saves me about 580 bytes of program space. But it still links in the UART stuff, even if I never call serial_begin() or any serial calls. If I just go in and #define NO_SERIAL somewhere, it saves me 775 bytes of program space and 42 bytes of RAM. But where is the generally accepted place to do that? I have been doing it in HardwareSerial.h, but again, that's not a file I wrote, so I would prefer to do it in one of my own files. How is it supposed to be done?

I still haven't figured out how to get it to not link in all the timer stuff. millis() and micros(). Even if I don't use it at all.

dannyf
Posts: 231
Joined: Wed May 11, 2016 4:29 pm

Re: How do I get my AWU ISR into the interrupt vector table? [SOLVED -- RTFM!]

Post by dannyf » Tue Jan 16, 2018 12:06 pm


still haven't figured out how to get it to not link in all the timer stuff. millis() and micros(). Even if I don't use it at all
Check the manual to see if the compiler can put each function into it's own section and then if the linker can discard unused code. Enable both and you are done.

If not, you are out of luck, unless you want to change the code to support conditional compilation - where you would manually specify if a function is used or not.

tenbaht
Posts: 12
Joined: Wed Oct 11, 2017 3:10 pm

Re: How do I get my AWU ISR into the interrupt vector table? [SOLVED -- RTFM!]

Post by tenbaht » Tue Jan 16, 2018 3:13 pm

Jimmus wrote:
Mon Jan 15, 2018 6:59 am
Because I'm seeing a little bit of what dannyf mentioned about trimming out unused code. The UART is great for debugging and certain kinds of projects, but my little standalone mailbox detector doesn't need serial communication. The AVR platform automatically trims all that stuff out if you don't use it. I can see that there are some things in the STM8 code to do the same thing, but some of them still have issues. For example, if I don't do any pinMode() or digitalWrite() kinds of calls, it saves me about 580 bytes of program space. But it still links in the UART stuff, even if I never call serial_begin() or any serial calls. If I just go in and #define NO_SERIAL somewhere, it saves me 775 bytes of program space and 42 bytes of RAM. But where is the generally accepted place to do that? I have been doing it in HardwareSerial.h, but again, that's not a file I wrote, so I would prefer to do it in one of my own files. How is it supposed to be done?
Best would be to define a compiler option: -DNO_SERIAL

It would be great to leave it out automatically if no Serial_begin() is present in the sources. Right now that does not happen, because HardwareSerial.c is only one file containing all serial function, including the initialization code. And the SDCC linker follows an all-or-nothing approach: It can leave out complete .rel files, but not individual functions. So if only one label (function or variable) is referenced from the outside, the whole module gets pulled in.

This is why I split the SPL into many single function files when compiling. Something similar would be possible for the Arduino core files. The initialization code would still be there, but at least the rest if left out.

I have this in mind, but it will influence the complete source structure, so I didn't do it yet. Hopefully someday later...

Michael
https://github.com/tenbaht/sduino - Programming the STM8 the Arduino way

Post Reply