#avr Logs

Nov 06 2017

#avr Calendar

12:04 AM day__ is now known as daey
12:46 AM day__ is now known as daey
10:05 AM enick_212 is now known as A001
10:05 AM A001 is now known as Guest86075
10:41 AM nuxil: mornings.
10:43 AM nuxil: is it possible to use the reset pin to increment a value and store it before the reset occures ?
10:53 AM enh: Can't you have an initializer that reads a velue at eeprom and increments it?
10:53 AM enh: valu*
10:53 AM enh: value*
10:53 AM nuxil: yup. i can
10:53 AM nuxil: was just thinking about that.
10:54 AM enh: almost the same
10:54 AM nuxil: but do i need to set some fuse to be able to rw to the storage ?
10:55 AM nuxil: like the self Programming enable
10:55 AM enh: not that i know of. But I'm not the most knowledgeable person here. Just anewbie
10:55 AM nuxil: no.. im da newbie :p
11:09 AM Guest86075 is now known as A001
11:09 AM A001: has anyone got jtag debugging working on any arduino boards
11:10 AM A001: specifically yun/leonardo which have mega32u4
11:11 AM A001: mixed commentary online about being able to enable jtag fuse
11:43 AM polprog: nuxil: some avrs have a RSTDISBL [reset disable] or something like that in fuses. But keep in mind that it will disable the reset function
11:43 AM polprog: as usual it's in the datasheet ;)
11:46 AM nuxil: yea. but as enh pointed out i dont need it. im just reading the eeprom on starup and write a new value as needed..
11:48 AM robinak is now known as robink
12:30 PM cehteh: nuxil: you can easily increment a value after reset occured
12:30 PM cehteh: no need to change fuse
12:31 PM cehteh: just have a counter in NOINIT section, figure out the boot reason (powerup -> clear the counter, reset -> increment the counter)
12:38 PM polprog: that's advanced wizardry but it's definitely a more elegant solution ;)
12:49 PM polprog: cehteh: https://i.ytimg.com/vi/KEkrWRHCDQU/maxresdefault.jpg
12:50 PM nuxil: cehteh, do you have a example ?
12:50 PM cehteh: nuxil: yes moment
12:50 PM polprog: you just write it in a metod with proper attribute section
12:51 PM cehteh: in my battery watchdog i use reset to trigger though different calibration modes
12:52 PM polprog: __attribute__ ((section (".noinit")));
12:52 PM nuxil: so.. like example int myname __attribute__ ((section (".noinit"))); ? then myname = whatever ?
12:52 PM cehteh: http://git.pipapo.org/?p=battswitch.git;a=blob;f=src/battswitch.c
12:52 PM polprog: not , a whole method
12:54 PM polprog: http://www.nongnu.org/avr-libc/user-manual/mem_sections.html on the very end
12:54 PM cehteh: sometimes i wish one could just give a global flag that the cruntime doesnt init anything, not standard C anymore but can be useful
12:54 PM cehteh: mhm maybe there is such a flag,
12:55 PM cehteh: just search "NOINIT, reset and calibrate" in my code then you'll see
12:55 PM cehteh: i'd NOINIT everything because it gets initialized by code
12:56 PM nuxil: ah. thanks :)
12:56 PM polprog: how would you know if it's a powerup or reset>
12:56 PM polprog: ?
12:56 PM polprog: doesnt the CPU start from 0x0000 every time?
12:58 PM nuxil: idk
12:59 PM cehteh: see code
01:00 PM cehteh: 495 void
01:00 PM cehteh: 496 init (void)
01:00 PM cehteh: 497 {
01:00 PM cehteh: 498 mcusr = MCUSR;
01:00 PM cehteh: 499 MCUSR = 0;
01:01 PM cehteh: .. MCUSR is the MCU status register which indicated the boot reason
01:01 PM polprog: clever
01:01 PM cehteh: but you need to put that info aside for later consumption asap
01:01 PM polprog: that makes sense
01:01 PM polprog: id even put it as volatile asm()
01:01 PM cehteh: anyone here reads datasheets? :)
01:01 PM polprog: just to be sure
01:01 PM cehteh: no need
01:01 PM * polprog doesbut not whole
01:03 PM polprog: hmm cant find it in my mega8 register
01:03 PM polprog: probably it doesnt have that feature
01:03 PM cehteh: dunno, all tinys i know and mega328p have it
01:04 PM polprog: wait
01:04 PM polprog: theres a single drawing
01:04 PM cehteh: maybe its named slightly different on older parts
01:04 PM polprog: brb
01:04 PM cehteh: avr likes to confuse people by naming interrupts and other registers slightly differently
01:13 PM polprog: https://screenshots.firefox.com/GbC6KScemhviJXyj/www.atmel.com
01:13 PM polprog: that's nice but those fields are nonexistent in MCUCR
01:13 PM polprog: MCUSR*
01:14 PM polprog: oh god im stupid
01:14 PM polprog: i searched for MCUCR not MCUSR
01:14 PM polprog: lol
01:14 PM polprog: good job polprog
01:16 PM polprog: wonder what GPIORs are for, they dont exist anywhere else in the datasheet except for the register summary
01:17 PM nuxil: ah i think i see what your doing now.. so you check the EXTRF or PORF bits in the MCUSR. so if the PORF bit is set its a powerup and the EXTRF its a manual reset ??
01:17 PM polprog: that's right
01:17 PM nuxil: oki
01:17 PM polprog: i like this trick ;) first time i heard of this register :P
01:42 PM nuxil: that method of yours cehteh, worked like a charm, thanks :)
01:43 PM polprog: ill make an experiment with that
02:04 PM Lambda_Aurigae: A001, if you want jtag then you have to enable it in the fuse first. otherwise it won't work.
02:27 PM A001: Lambda_Aurigae (IRC): thanks, is it ever possible that after setting the fuse jtag can still be disabled?
02:28 PM polprog: A001: you can unset the fuse or disable it in software
02:29 PM A001: Thanks polprog
02:43 PM JanC is now known as Guest24940
03:56 PM Lambda_Aurigae: it's,,,in the datasheet.
03:57 PM enh: Hi
03:58 PM Lambda_Aurigae: out of the good stuff here, so, not anymore.
03:58 PM Lambda_Aurigae: err...hello.
03:58 PM enh: Today I learnt the avr-gcc compiler produces really unusual code in some circumstances.
03:58 PM Lambda_Aurigae: yeah
03:59 PM Lambda_Aurigae: so does pretty much every compiler out there.
03:59 PM enh: Even with volatile variables, it was not evaluating a boolean correctly. When the value changed, the behaviour did not reflect it.
04:00 PM enh: I spent a lot of time trying to find the bug. Could not find it. So i rewrote the code to be as linear as possible and everything worked
04:00 PM enh: Complete nonsense
04:01 PM nuxil: but is boolean a valid datatype ?
04:01 PM nuxil: isnt it just a int ?
04:02 PM Lambda_Aurigae: I can see that...boolean variables are not exactly native after all...kind of a "relatively" recent addon.
04:03 PM Lambda_Aurigae: I've never looked into the bool type so not sure how it's handled...I suspect it is a packed variable, where you can get up to 8 of them in one byte of ram....
04:03 PM enh: Did not know that. I'll put a link to the diff here, if anybody is interested
04:03 PM Lambda_Aurigae: at least, that's how I would handle it.
04:03 PM Lambda_Aurigae: to save space and all.
04:03 PM Lambda_Aurigae: but, gcc could be doing other stupid stuff with it too.
04:03 PM nuxil: well you can do that already using a char or int. :p
04:04 PM Lambda_Aurigae: that's what I do actually, rather than using the bool datatype.
04:04 PM Lambda_Aurigae: I just play with the bits myself.
04:05 PM Lambda_Aurigae: enh, could be a bug in the bool/volatile code too.
04:07 PM enh: I had an if that evaluated a bool. If true, it would run some code and exit the function. But after that if, there was more code that should run in case the bool was not true. That code never ran.
04:07 PM enh: I did not use an else, just put the alternative code after the if.
04:07 PM enh: Execution never reached there.
04:08 PM enh: I had to place flags everywhere to find this bug. Took me more than a week.
04:13 PM enh: This is not the kind of thing that makes sense. Very hard to find.
04:13 PM Lambda_Aurigae: it's called debugging
04:14 PM Lambda_Aurigae: at least you aren't searching for a moth in a relay....
04:14 PM Lambda_Aurigae: https://thenextweb.com/shareables/2013/09/18/the-very-first-computer-bug/
04:16 PM enh: http://www.youtube.com/watch?v=au8uFIWkcRs
04:17 PM enh: It more like a moth in the compiler