0

If I understood the AVR instruction manual correctly, the ATtiny 25 can disable the BODlevel2 fuse by software, but when compiling with Studio 7 (version 7.0.132), I get the error "Undefined symbol: BODS & BODSE".

  • BODLEVEL fuses are set correctly. L:0x62 H:0xDD E:0xFF
; init brown out detection disable for sleep mode
        ldi     r23, (1<<BODS)|(1<<BODSE) ; En 2 fois 1- pour autoriser ecriture 
        out     MCUCR, r23                ; Envoyer autorisation ecriture 
        ldi     r23, (1<<BODS)|(0<<BODSE) ; Ecrire valeur a envoyer dans R23 
        out     MCUCR, r23                ; Envoyer R23 dans MCUCR

        
; init WDT for interrupt mode
        ldi     r23, (1<<WDCE)|(1<<WDE)
        out     WDTCR, r23
        ldi     r23, (1<<WDIE)|(0<<WDE)|(0<<WDP0)|(1<<WDP1)|(0<<WDP2)|(0<<WDP3) ; sec time out WDT interrupt; no system reset
        out     WDTCR, r23
        sei                   ; global interrupt enable bit is active
    
L1_INTERIEUR:                 ; init sleep modes
        ldi     r23, (1<<SM1) ; Power-down mode
        out     MCUCR, r23
        in      r23, MCUCR
        ldi     r23, (1<<SE)  ; sleep mode enabled
        out     MCUCR, r23    ; put MCU into sleep

L1A_INTERIEUR:  
        in R15,SREG
        wdr
        sleep   
8
  • which AVR instruction manual are you referring to? ... which section?
    – jsotola
    Commented Jan 27 at 23:58
  • So the assembler doesn't recognize "BODS" symbol, as those "bit names", unlike registers or instructions, are the part of user manual existing for human convenience only. What's so surprising? Use numbers or define symbolic constants yourself...
    – Matt
    Commented Jan 28 at 4:58
  • 1
    run cat iotn25.h | grep BODS in where the toolchain is stalled give me this #define BODS 7, and #define BODSE 2.
    – hcheung
    Commented Jan 28 at 5:16
  • @hcheung What does some C include file do with assembler?
    – Matt
    Commented Jan 28 at 5:24
  • 1
    @Matt Of course this is possible. The GCC frontend pipes the assembler source through the preprocessor before giving it to the actual assembler, if the file extension is upper-case "S". Been there, did it. Commented Jan 28 at 8:31

1 Answer 1

2

The Microchip Studio uses the GNU toolchain or the XC8 toolchain. Unfortunately you did not tell us, which you use for your project.

The common solution is to include the corresponding header file to let the preprocessor replace the symbols with the defined values:

#include <iotn25.h>

; init brown out detection disable for sleep mode
        ldi     r23, (1<<BODS)|(1<<BODSE) ; En 2 fois 1- pour autoriser ecriture 

; ...

Or to add "iotn25.h" to the dependencies in the "Solution Explorer".

Now you need to make sure that the preprocessor runs before the assembler. Both toolchains behave identically, if you name the assembler source with an uppercase extension of ".S".

The GNU toolchain does this according to its documentation:

You can use the GNU C compiler driver to get other “CPP” style preprocessing by giving the input file a ‘.S’ suffix.

For the XC8 toolchain, the documentation tells us explicitly about this and an interesting option in chapter 8.3.4.1:

The -x assembler-with-cpp language option ensures assembly source files are preprocessed before they are assembled, thus allowing the use of preprocessor directives, such as #include and C-style comments with assembly code. By default, assembly files not using the .S or .sx extension are not preprocessed.

Not the answer you're looking for? Browse other questions tagged or ask your own question.