Giter Site home page Giter Site logo

Comments (10)

Floessie avatar Floessie commented on September 26, 2024

Workaround: using CCPWrite from here.

from dxcore.

SpenceKonde avatar SpenceKonde commented on September 26, 2024

Why not use the compiler provided builtin, _PROTECTED_WRITE()? That is what DxCore uses for setting protected registers...Looks like its... exactly the same as CCPWrite()

from dxcore.

SpenceKonde avatar SpenceKonde commented on September 26, 2024

Except that it has an unnecessary disabling of interrupts (when CCP is written, interrupts are automatically disabled - see datasheet; that implementation disables them around the call to CCP, which just wastes uh... 6 bytes of flash and 3 CPU clocks?

from dxcore.

SpenceKonde avatar SpenceKonde commented on September 26, 2024

(it = CCPWrite() - _PROTECTED_WRITE() does it correctly.... )

Though, I'm surprised that cpufunc has changed? I don't suppose you could post the exact linker error?

from dxcore.

Floessie avatar Floessie commented on September 26, 2024

@SpenceKonde Didn't know that macro. Thanks for the pointer!

Though, I'm surprised that cpufunc has changed? I don't suppose you could post the exact linker error?

I'll prepare a minimal example...

from dxcore.

Floessie avatar Floessie commented on September 26, 2024
#include <avr/cpufunc.h>

void setup() {
   uint8_t temp;
    
    temp = CLKCTRL.OSC32KCTRLA;
    temp |= CLKCTRL_RUNSTDBY_bm;
    ccp_write_io((uint8_t*)&CLKCTRL.OSC32KCTRLA, temp);
}

void loop() {
}
Arduino: 1.8.13 (Linux), Board: "AVR DB-series (no bootloader), AVR128DB28, 24 MHz internal, No, 1.9V, Disabled/Disabled, EEPROM retained, Hardware Reset (recommended), TCB2, Enabled, 8ms"

/opt/arduino-1.8.13/arduino-builder -dump-prefs -logger=machine -hardware /opt/arduino-1.8.13/hardware -hardware /home/user/.arduino15/packages -hardware /home/user/src/Arduino/hardware -tools /opt/arduino-1.8.13/tools-builder -tools /opt/arduino-1.8.13/hardware/tools/avr -tools /home/user/.arduino15/packages -built-in-libraries /opt/arduino-1.8.13/libraries -libraries /home/user/src/Arduino/libraries -fqbn=DxCore:megaavr:avrdb:chip=128DB28,clock=24internal,serialevent=no,bodvoltage=1v9,bodmode=disabled,eesave=enable,resetpin=reset,millis=tcb2,mvio=enabled,startuptime=8 -vid-pid=1A86_7523 -ide-version=10813 -build-path /tmp/arduino_build_302614 -warnings=default -build-cache /tmp/arduino_cache_613580 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avrdude.path=/home/user/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17 -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=/home/user/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17 -prefs=runtime.tools.avr-gcc.path=/home/user/.arduino15/packages/DxCore/tools/avr-gcc/7.3.0-atmel3.6.1-azzy1 -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-azzy1.path=/home/user/.arduino15/packages/DxCore/tools/avr-gcc/7.3.0-atmel3.6.1-azzy1 -prefs=runtime.tools.arduinoOTA.path=/home/user/.arduino15/packages/arduino/tools/arduinoOTA/1.3.0 -prefs=runtime.tools.arduinoOTA-1.3.0.path=/home/user/.arduino15/packages/arduino/tools/arduinoOTA/1.3.0 -verbose /tmp/arduino_modified_sketch_9454/sketch_dec10a.ino
/opt/arduino-1.8.13/arduino-builder -compile -logger=machine -hardware /opt/arduino-1.8.13/hardware -hardware /home/user/.arduino15/packages -hardware /home/user/src/Arduino/hardware -tools /opt/arduino-1.8.13/tools-builder -tools /opt/arduino-1.8.13/hardware/tools/avr -tools /home/user/.arduino15/packages -built-in-libraries /opt/arduino-1.8.13/libraries -libraries /home/user/src/Arduino/libraries -fqbn=DxCore:megaavr:avrdb:chip=128DB28,clock=24internal,serialevent=no,bodvoltage=1v9,bodmode=disabled,eesave=enable,resetpin=reset,millis=tcb2,mvio=enabled,startuptime=8 -vid-pid=1A86_7523 -ide-version=10813 -build-path /tmp/arduino_build_302614 -warnings=default -build-cache /tmp/arduino_cache_613580 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avrdude.path=/home/user/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17 -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=/home/user/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17 -prefs=runtime.tools.avr-gcc.path=/home/user/.arduino15/packages/DxCore/tools/avr-gcc/7.3.0-atmel3.6.1-azzy1 -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-azzy1.path=/home/user/.arduino15/packages/DxCore/tools/avr-gcc/7.3.0-atmel3.6.1-azzy1 -prefs=runtime.tools.arduinoOTA.path=/home/user/.arduino15/packages/arduino/tools/arduinoOTA/1.3.0 -prefs=runtime.tools.arduinoOTA-1.3.0.path=/home/user/.arduino15/packages/arduino/tools/arduinoOTA/1.3.0 -verbose /tmp/arduino_modified_sketch_9454/sketch_dec10a.ino
Using board 'avrdb' from platform in folder: /home/user/.arduino15/packages/DxCore/hardware/megaavr/1.2.0-a
Using core 'dxcore' from platform in folder: /home/user/.arduino15/packages/DxCore/hardware/megaavr/1.2.0-a
Detecting libraries used...
/home/user/.arduino15/packages/DxCore/tools/avr-gcc/7.3.0-atmel3.6.1-azzy1/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=avr128db28 -DF_CPU=24000000L -DARDUINO=10813 -DARDUINO_avrdb -DARDUINO_ARCH_MEGAAVR -DDXCORE=1.1.1 -DDXCORE_MAJOR=1UL -DDXCORE_MINOR=2UL -DDXCORE_PATCH=0UL -DDXCORE_RELEASED=1 -DMILLIS_USE_TIMERB2 -DCLOCK_SOURCE=0 -I/home/user/.arduino15/packages/DxCore/hardware/megaavr/1.2.0-a/cores/dxcore/api/deprecated -I/home/user/.arduino15/packages/DxCore/hardware/megaavr/1.2.0-a/cores/dxcore -I/home/user/.arduino15/packages/DxCore/hardware/megaavr/1.2.0-a/variants/28pin-standard /tmp/arduino_build_302614/sketch/sketch_dec10a.ino.cpp -o /dev/null -DARDUINO_LIB_DISCOVERY_PHASE
Generating function prototypes...
/home/user/.arduino15/packages/DxCore/tools/avr-gcc/7.3.0-atmel3.6.1-azzy1/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=avr128db28 -DF_CPU=24000000L -DARDUINO=10813 -DARDUINO_avrdb -DARDUINO_ARCH_MEGAAVR -DDXCORE=1.1.1 -DDXCORE_MAJOR=1UL -DDXCORE_MINOR=2UL -DDXCORE_PATCH=0UL -DDXCORE_RELEASED=1 -DMILLIS_USE_TIMERB2 -DCLOCK_SOURCE=0 -I/home/user/.arduino15/packages/DxCore/hardware/megaavr/1.2.0-a/cores/dxcore/api/deprecated -I/home/user/.arduino15/packages/DxCore/hardware/megaavr/1.2.0-a/cores/dxcore -I/home/user/.arduino15/packages/DxCore/hardware/megaavr/1.2.0-a/variants/28pin-standard /tmp/arduino_build_302614/sketch/sketch_dec10a.ino.cpp -o /tmp/arduino_build_302614/preproc/ctags_target_for_gcc_minus_e.cpp -DARDUINO_LIB_DISCOVERY_PHASE
/opt/arduino-1.8.13/tools-builder/ctags/5.8-arduino11/ctags -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives /tmp/arduino_build_302614/preproc/ctags_target_for_gcc_minus_e.cpp
Sketch wird kompiliert...
/home/user/.arduino15/packages/DxCore/tools/avr-gcc/7.3.0-atmel3.6.1-azzy1/bin/avr-g++ -c -g -Os -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=avr128db28 -DF_CPU=24000000L -DARDUINO=10813 -DARDUINO_avrdb -DARDUINO_ARCH_MEGAAVR -DDXCORE=1.1.1 -DDXCORE_MAJOR=1UL -DDXCORE_MINOR=2UL -DDXCORE_PATCH=0UL -DDXCORE_RELEASED=1 -DMILLIS_USE_TIMERB2 -DCLOCK_SOURCE=0 -I/home/user/.arduino15/packages/DxCore/hardware/megaavr/1.2.0-a/cores/dxcore/api/deprecated -I/home/user/.arduino15/packages/DxCore/hardware/megaavr/1.2.0-a/cores/dxcore -I/home/user/.arduino15/packages/DxCore/hardware/megaavr/1.2.0-a/variants/28pin-standard /tmp/arduino_build_302614/sketch/sketch_dec10a.ino.cpp -o /tmp/arduino_build_302614/sketch/sketch_dec10a.ino.cpp.o
Compiling libraries...
Compiling core...
Using precompiled core: /tmp/arduino_cache_613580/core/core_e338eab05b22211458d2037f06274d6b.a
Linking everything together...
/home/user/.arduino15/packages/DxCore/tools/avr-gcc/7.3.0-atmel3.6.1-azzy1/bin/avr-gcc -Os -g -flto -fuse-linker-plugin -Wl,--gc-sections,--section-start=.text=0x0,--section-start=.FLMAP_SECTION1=0x8000,--section-start=.FLMAP_SECTION2=0x10000,--section-start=.FLMAP_SECTION3=0x18000 -mmcu=avr128db28 -o /tmp/arduino_build_302614/sketch_dec10a.ino.elf /tmp/arduino_build_302614/sketch/sketch_dec10a.ino.cpp.o /tmp/arduino_build_302614/../arduino_cache_613580/core/core_e338eab05b22211458d2037f06274d6b.a -L/tmp/arduino_build_302614 -lm
/tmp/ccagVgyB.ltrans0.ltrans.o: In function `setup':
/tmp/arduino_modified_sketch_9454/sketch_dec10a.ino:8: undefined reference to `ccp_write_io(unsigned char*, unsigned char)'
exit status 1

from dxcore.

Floessie avatar Floessie commented on September 26, 2024

_PROTECTED_WRITE did the trick. Thanks, again!

As I'm playing with the PIT at the moment, do you know a way to calibrate the internal 32k osc? It's a tad too slow. From the datasheet I see that there's RTC.CALIB, but it's only available for the external 32k crystal...

from dxcore.

SpenceKonde avatar SpenceKonde commented on September 26, 2024

Don't think you can; that is not what it is meant for! It's meant to be a "save as much power as you can by sacrificing accuracy" option... If you want accuracy, they would tell you to use a watch crystal or 32kHz active oscillator.

It's also fairly strongly dependent temperature (used to be dependent on voltage too... but they run the internal oscillators on the Dx-series from Vddcore which is regulated down from Vdd, and varies little - if anything - over operating voltage range.... That's why they are spec'ed for the full 4-24 MHz over the full voltage range; Semiconductor performance = f(p, V, T) - process (manufacturing process, including design, etc), voltage (positive correlation) and temperature (negative correlation)

Actually, now that would be an interesting experiment... monitor the frequency of PWM, on a part with BOD disabled while you sloooooowly lower the voltage. At some Vddlow suddenly the frequency will start to change with voltage. This Vddlow = Vddcore+Vdropout of their core voltage regulator, wouldn't it?

from dxcore.

SpenceKonde avatar SpenceKonde commented on September 26, 2024

By the way, if you do anything spiffy with the PIT, I'd love to hear about it. I just enabled discussions here, so there's a mini-forum attached to DxCore repo now :-)
(that scream you heard in the distance was gitter, the github-repo-focused discussion forum site :-P )

from dxcore.

Floessie avatar Floessie commented on September 26, 2024

Sure. I just thought there was something similar to the SIGROW.TEMPSENSE[01] that I missed...

Nothing spiffy: I'll simply use it as the time source for FreeRTOS on megaavr like we do with the WDT on avr.

from dxcore.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.