'round the world...
Offline
Edison Member
Karma: 21
Posts: 2385
|
 |
« Reply #15 on: October 11, 2011, 05:57:26 pm » |
But why hide something that is SIMPLE ?
To you it is simple... for someone that just started in programming and embedded devices (which is probably the majority of Arduino users) main() makes a lot less sense than setup() and loop(). I can understand you. I only use the board and the bootloader from Arduino, but I also see why Arduino is made the way it is now. But the good thing is that it allows people to evolve and try different ways of using the hardware and software according to their own personal knowledge.
|
|
|
|
|
Logged
|
Eu não sou o teu criado. Se respondo no fórum é para ajudar todos mediante a minha disponibilidade e disposição. Responder por mensagem pessoal iria contra o propósito do fórum e por isso evito-o. Se realmente pretendes que eu te ajude por mensagem pessoal, então podemos chegar a um acordo e contrato onde me pagas pela ajuda que eu fornecer e poderás então definir os termos de confidencialidade do meu serviço. De forma contrária toda e qualquer ajuda que eu der tem de ser visível a todos os participantes do fórum (será boa ideia, veres o significado da palavra fórum). Nota também que eu não me responsabilizo por parvoíces escritas neste espaço pelo que se vais seguir algo dito por mim, entende que o farás por tua conta e risco.
Dito isto, mensagens pessoais só se forem pessoais, ou seja, se já interagimos de alguma forma no passado ou se me pretendes convidar para uma churrascada com cerveja (paga por ti, obviamente).
|
|
|
|
Grand Blanc, MI, USA
Online
Faraday Member
Karma: 47
Posts: 2570
"We're a proud service of the Lost Electricity Reclamation Agency"
|
 |
« Reply #16 on: October 11, 2011, 08:23:07 pm » |
This came up in another thread as well - do you know how to download a sketch via the ICSP pins using the IDE?
Adding entries to boards.txt similar to below works for me (I have others that are just different clock freqs). Your programmer may vary ;-) uno16.name=Arduino Uno ICSP @ 16MHz uno16.upload.using=arduino:usbtinyisp uno16.upload.protocol=stk500 uno16.upload.maximum_size=32256 uno16.upload.speed=115200 uno16.bootloader.low_fuses=0xff uno16.bootloader.high_fuses=0xde uno16.bootloader.extended_fuses=0x05 uno16.bootloader.path=optiboot uno16.bootloader.file=optiboot_atmega328.hex uno16.bootloader.unlock_bits=0x3F uno16.bootloader.lock_bits=0x0F uno16.build.mcu=atmega328p uno16.build.f_cpu=16000000L uno16.build.core=arduino
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Boston area, metrowest
Offline
Brattain Member
Karma: 270
Posts: 17040
Available for Design & Build services
|
 |
« Reply #17 on: October 11, 2011, 09:10:58 pm » |
So you replace
uno16.bootloader.file=optiboot_atmega328.hex
this file with the sketch file to use instead?
|
|
|
|
|
Logged
|
|
|
|
|
"The old Europe"
Offline
Edison Member
Karma: 0
Posts: 2003
Bootloaders suck!
|
 |
« Reply #18 on: October 12, 2011, 05:48:22 am » |
@Nick:
That doesn't seem to work on 1.0 for me. I have to add the 'weak' attribute there.
|
|
|
|
|
Logged
|
• Upload doesn't work? Do a loop-back test. • There's absolutely NO excuse for not having an ISP! • Your AVR needs a brain surgery? Use the online FUSE calculator. • My projects: RGB LED matrix, RGB LED ring, various ATtiny gadgets... • Microsoft is not the answer. It is the question, and the answer is NO!
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 226
Posts: 14101
Lua rocks!
|
 |
« Reply #19 on: October 12, 2011, 02:54:42 pm » |
I don't have version 1.0. I thought I had version 0022, but I suppose that is alpha, right?
I can't find version version 1.0 on the download page.
I wonder why version 0022 works? They don't have the weak attribute.
|
|
|
|
|
Logged
|
|
|
|
|
"The old Europe"
Offline
Edison Member
Karma: 0
Posts: 2003
Bootloaders suck!
|
 |
« Reply #20 on: October 12, 2011, 02:56:40 pm » |
@CrossRoads: no. ############################################################## # # to activate this board, select it and use: # # 'Burn Bootloader' - 'w/ USBtinyISP' just once # this makes sure the correct FUSE settings are used # 8x8RGBLedMatrix1.name=8x8 RGB LED Matrix - ATmega168 / 16MHz Quartz / USBtiny 8x8RGBLedMatrix1.upload.maximum_size=16384 8x8RGBLedMatrix1.upload.speed=115200 8x8RGBLedMatrix1.upload.using=arduino:usbtinyisp 8x8RGBLedMatrix1.bootloader.low_fuses=0xFF 8x8RGBLedMatrix1.bootloader.high_fuses=0xDD 8x8RGBLedMatrix1.bootloader.extended_fuses=0x05
## just so the IDE doesn't throw an error ## it will be overwritten, but we need the correct FUSE settings 8x8RGBLedMatrix1.bootloader.path=optiboot 8x8RGBLedMatrix1.bootloader.file=optiboot_diecimila.hex ##
8x8RGBLedMatrix1.bootloader.unlock_bits=0x3F 8x8RGBLedMatrix1.bootloader.lock_bits=0x3F 8x8RGBLedMatrix1.build.mcu=atmega168 8x8RGBLedMatrix1.build.f_cpu=16000000L 8x8RGBLedMatrix1.build.core=arduino # # # ############################################################## If I want to do without a bootloader, I change the fuse settings, lockbits and the available flash size to respect that fact. Uploading works as usual. Uploading is currently slower with an usbtiny than with optiboot. There is a trivial 'patch' for that, but it was not accepted... it involves adding the bitclock parameter '-B 1' to the programmers.txt and a tiny modification in the java code that deals with uploading. This would increase upload speed at least 10x. programmers.txt usbtinyisp.name=USBtinyISP usbtinyisp.protocol=usbtiny usbtinyisp.bitclock=1
app/src/processing/app/debug/AvrdudeUploader.java @@ -104,6 +104,10 @@ public class AvrdudeUploader extends Uploader { Map<String, String> programmerPreferences = target.getProgrammers().get(programmer); List params = new ArrayList(); params.add("-c" + programmerPreferences.get("protocol")); + + if (programmerPreferences.get("bitclock") != null) { + params.add("-B" + Integer.parseInt(programmerPreferences.get("bitclock"))); + }
if ("usb".equals(programmerPreferences.get("communication"))) { params.add("-Pusb"); I have given up getting anything added/patched in the IDE, it has proven to be pointless for me. I just complain here. This will be ignored too I guess, but it is less painful for me overall.
|
|
|
|
« Last Edit: October 12, 2011, 02:59:35 pm by madworm »
|
Logged
|
• Upload doesn't work? Do a loop-back test. • There's absolutely NO excuse for not having an ISP! • Your AVR needs a brain surgery? Use the online FUSE calculator. • My projects: RGB LED matrix, RGB LED ring, various ATtiny gadgets... • Microsoft is not the answer. It is the question, and the answer is NO!
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 8
|
 |
« Reply #21 on: October 13, 2011, 10:26:13 am » |
Let's just use main:
O.O I had no idea you could do that and this is 100% awesome. I just shaved 132 bytes off my sketch and now have enough space to implement a URL decode function (94 bytes) to fix that bug that's been annoying me for months.
|
|
|
|
|
Logged
|
|
|
|
|
"The old Europe"
Offline
Edison Member
Karma: 0
Posts: 2003
Bootloaders suck!
|
 |
« Reply #22 on: October 13, 2011, 10:33:30 am » |
See! It is useful.
|
|
|
|
|
Logged
|
• Upload doesn't work? Do a loop-back test. • There's absolutely NO excuse for not having an ISP! • Your AVR needs a brain surgery? Use the online FUSE calculator. • My projects: RGB LED matrix, RGB LED ring, various ATtiny gadgets... • Microsoft is not the answer. It is the question, and the answer is NO!
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 226
Posts: 14101
Lua rocks!
|
 |
« Reply #23 on: October 13, 2011, 02:16:28 pm » |
O.O I had no idea you could do that and this is 100% awesome. I just shaved 132 bytes off my sketch and now have enough space to implement a URL decode function (94 bytes) to fix that bug that's been annoying me for months.
Glad that helped. Better not upgrade to version 1.0 though, unless they fix that <hint>.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Sr. Member
Karma: 20
Posts: 426
Always making something...
|
 |
« Reply #24 on: October 16, 2011, 04:05:30 pm » |
You CAN use main() instead of setup() and loop(). Really, yes, you can. void setup() { Serial.begin(9600); Serial.println("setup does not run"); }
void loop() { Serial.println("loop does not run"); }
int main() { init(); Serial.begin(9600); while (1) { Serial.println("My main is running"); delay(1000); } }
This works because main() is inside the core, which gets compiled to a ".a" library archive. If you use any function with the same name, the linker will put your copy into the final output, rather than the one from the library. So go ahead and use main(). The ability to do so has been there all along. Just make sure you call init() to initialize the hardware, so things like millis() and delay() will work properly.
|
|
|
|
|
Logged
|
|
|
|
|
"The old Europe"
Offline
Edison Member
Karma: 0
Posts: 2003
Bootloaders suck!
|
 |
« Reply #25 on: October 16, 2011, 04:39:32 pm » |
Well... this void setup() { Serial.begin(9600); Serial.println("setup does not run"); }
void loop() { Serial.println("loop does not run"); pinMode(13,OUTPUT); }
int main() { init(); Serial.begin(9600); while (1) { Serial.println("My main is running"); delay(1000); } } compiles on 0022 and not on 1.0-rc1. I've had a quick look on the compiler/linker parameters, but can't find a difference. Error on 1.0-rc1: avr-gcc -Os -Wl,--gc-sections -mmcu=atmega168 -o /tmp/build792419732568248348.tmp/sketch_oct16a.cpp.elf /tmp/build792419732568248348.tmp/sketch_oct16a.cpp.o /tmp/build792419732568248348.tmp/core.a -L/tmp/build792419732568248348.tmp -lm core.a(main.cpp.o): In function `main': /XXX/arduino-1.0-rc1/hardware/arduino/cores/arduino/main.cpp:6: multiple definition of `main' sketch_oct16a.cpp.o:sketch_oct16a.cpp:16: first defined here This error vanishes when adding the 'weak' attribute as pointed out before. I feel that if this compiles (works?) on 0022, it should do the same on 1.0
|
|
|
|
|
Logged
|
• Upload doesn't work? Do a loop-back test. • There's absolutely NO excuse for not having an ISP! • Your AVR needs a brain surgery? Use the online FUSE calculator. • My projects: RGB LED matrix, RGB LED ring, various ATtiny gadgets... • Microsoft is not the answer. It is the question, and the answer is NO!
|
|
|
|
Global Moderator
Dallas
Offline
Shannon Member
Karma: 129
Posts: 10379
|
 |
« Reply #26 on: October 18, 2011, 02:57:47 pm » |
The difference is that the pin definition data structures have been moved (through a header file) into main.cpp.
|
|
|
|
|
Logged
|
|
|
|
|
"The old Europe"
Offline
Edison Member
Karma: 0
Posts: 2003
Bootloaders suck!
|
 |
« Reply #27 on: October 18, 2011, 03:12:43 pm » |
Forgive my ignorance, but is using the 'weak' attribute for the linker to only way (correct?) to make it work again in 1.0 ?
Is the reason for the complaint that the user-provided main() is therefore not equivalent to the library one anymore?
|
|
|
|
« Last Edit: October 18, 2011, 03:14:46 pm by madworm »
|
Logged
|
• Upload doesn't work? Do a loop-back test. • There's absolutely NO excuse for not having an ISP! • Your AVR needs a brain surgery? Use the online FUSE calculator. • My projects: RGB LED matrix, RGB LED ring, various ATtiny gadgets... • Microsoft is not the answer. It is the question, and the answer is NO!
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 226
Posts: 14101
Lua rocks!
|
 |
« Reply #28 on: October 18, 2011, 03:22:40 pm » |
The difference is that the pin definition data structures have been moved (through a header file) into main.cpp.
Why do that? In fact why not change main.cpp from: #include <WProgram.h>
int main(void) { init();
setup(); for (;;) loop(); return 0; }
to: void init (); void setup (); void loop ();
int main(void) { init(); setup(); while (true) loop(); return 0; }
Then it compiles on its own without any header files, and will only be used if the user doesn't supply their own main function.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Dallas
Offline
Shannon Member
Karma: 129
Posts: 10379
|
 |
« Reply #29 on: October 18, 2011, 03:39:36 pm » |
Forgive my ignorance, but is using the 'weak' attribute for the linker to only way (correct?) to make it work again in 1.0 ? That is one way. The other way would be to move the pin definition data structures to another module. Where they were (wiring_digital) is a good choice. I would move them to their own module. Is the reason for the complaint that the user-provided main() is therefore not equivalent to the library one anymore? Someone else will have to answer that one.
|
|
|
|
« Last Edit: October 18, 2011, 03:41:20 pm by Coding Badly »
|
Logged
|
|
|
|
|
|