Go Down

Topic: miniCore issue (cannot figure out nature of the issue) (Read 288 times) previous topic - next topic

Enigma86d

Hi,

I been trying to use the miniCore and found a issue that seems to be related to miniCore and can't get it to work properly.

Background:
I have a sketch done for Arduino Uno running at the default clock freq 16Mhz and I wanted to run it at just 1Mhz to reduce power consumption.
Steps:
  • installed miniCore and set up for atmega328p at 1Mhz internal clock
  • took an Arduino uno, connected to ICE programmer and used Atmel Studio to set the low fuse at 0x62 to run at 1Mhz internal clock - I am using Atmel Studio + ICE programmer because I couldn't program the uC in Arduino
  • comiled my sketch and programmed it but the uC seems to freeze up because I use "Serial.print" but nothing comes out

If I amend the sketch sometimes it works however the change should NOT affect it. For example it happened that the uC was working if I added some extra Serial.print lines but when I deleted them the uC would not print anything to the serial port (not even the lines that were not deleted).
To show the problem better I kept deleting various part of the code while the issue was still present. Now I ended up in a situation where if I make the sketch any more simpler the uC works - it doesn't mater what I change, pretty much any change will make it work... to me this seems like a compilation issue but I don't really understand how that is possible and what is happening.

Please take your time to see these 5 minute videos showing the issue:
https://www.youtube.com/watch?v=h5NGhnzQAKk
https://www.youtube.com/watch?v=h5NGhnzQAKk


PS. why I say it is related to miniCore: if I select "Arduino Uno" board (not miniCore) and I connect a brand new Arduino running at 16Mhz it never freezes up, it always works as expected.

Kind regards,
Marius


hansibull

Hi!

I'm on vacation at the moment, so I don't have any hardware to test on at the moment.
Yesterday, just before I left I uploaded a simple Hello World example to an ATmega8 running at 1 MHz. (inserted into a UNO R3) without any issues.

I did watch both your videos, so I understand the strange issues you're seeing.

First, what happens if you try to use MiniCore with a 16 MHz crystal instead of 1 MHz internal oscillator?

You should also add SPI.endTransaction() at the end of setup().

Why can't you use Arduino IDE to set fuse bits, burn bootloader and upload code?

Are you able to upload using the USB port on your UNO (uploading using bootloader)?

What version of MiniCore are you using? Recently I've done some small changes to the SPI library. Try using MiniCore v2.0.1 to see if it makes a difference.
MightyCore -  ATmega1284, mega644, mega324, mega164, mega32, mega16, mega8535
Github.com/MCUdude/MightyCore

MiniCore - ATmega8, mega48, mega88, mega168, mega328
Github.com/MCUdude/MiniCore

Enigma86d

Hi hansibull,

Hope I'm not bothering you (as you mentioned you are in vacation).

Tried miniCore using 16Mhz external osscilator (standard Arduino Uno configuration) and it doesn't work if I compile it as an miniCore; it does work if I compile it as an Arduino Uno board.
I added SPI start transmission and end transmission before and after every SPI transmissiono (or after every group of transmission if I send multiple bytes) and it still doesn't work as a miniCore.
Tried V2.0.1 as well and it behave the same.

I posted a video here - which also contains the sketch I used in the description: https://www.youtube.com/watch?v=tsqOHouPckg
The sketch is the complete firmware (not the trimmed down one) and is because the trimmed down one, if I do pretty much any changes it starts to work... however, in the complete firmware I did put SPI end transmission everywhere it should be.

I must say your suggestions sounded like clever things to try.

Regarding programming, if I use the Arduino Uno with standard fuses (16Mhz external osscilator) I can program it in Arduino, no problems (both as Uno and as miniCore). The programming issues I have are if I select a different click and fuses and may be because of some lack of understanding some things. I don't know how to change fuses in Arduino and found that Atmel Ice + Atmel Studio seems to work fairly ok to programm the Uno (both fuses and program memory).

Marius



hansibull

Quote
Hope I'm not bothering you (as you mentioned you are on vacation).
Don't worry! Nobody is forcing me to reply to you. It's also much more motivating helping out when most of the necessary information is provided, and I don't have to ask for every single (and obvious) bit of missing information  :).

Please continue to run it on 16 MHz as it makes switching between MiniCore and Arduino UNO much easier.

First, can you try to enable LTO on the tools menu. LTO is enabled by default when compiling for Arduino UNO. I'd like to see if this makes a difference.

If this doesn't work I'd like you to modify this line in boards.txt. Please replace MCUdude_corefiles with arduino:arduino.
Restart Arduino IDE and try again with MiniCore.

By doing this we're replacing the core files used with MiniCore with the official one. This is why I want you to stay at 16 MHz since this frequency is officially supported. No official board as I'm aware of runs at 1 MHz.
MightyCore -  ATmega1284, mega644, mega324, mega164, mega32, mega16, mega8535
Github.com/MCUdude/MightyCore

MiniCore - ATmega8, mega48, mega88, mega168, mega328
Github.com/MCUdude/MiniCore

Enigma86d

Hi hansibull,

Sorry for the delay, had some really busy time, and thanks again for helping me.
I tested now with enabled LTO and it works. I then disabled LTO and it stopped working and enabled/disabled (did this a few times) and it consistently works when I enable LTO and doesn't work if I disable LTO. So it seems this was the issue.
I also tried it the settings of 1Mhz, internal osscilator, and programmed the fuses to use internal osc and enabled CLK DIV8 and programmed the .hex with bootloader using Atmel ICE and Atmel Studio and it works as well.

I just searched on the internet to understand what LTO does and... I don't really understand, but anyway thanks for helping to identify how to make it work.


Kind regards,
Marius

Go Up