Menu

FlashForth for Atmega 32u4 with integrated USB operator console

2020-11-04
2021-11-27
  • Glaukon Ariston

    Glaukon Ariston - 2021-11-13

    I am trying to put Forth on Pro Micro (ATmega32U4) unsuccessfully. When I upload the 32u4-16MHz-USB.hex file and connect the Pro Micro to a Windows 10 PC I either get nothing or the device gets recognised but with errors. More details can be found here.

    Can somebody verify the hex file in the current distribution is working on Pro Micro boards, please?

     

    Last edit: Glaukon Ariston 2021-11-13
  • Mikael Nordman

    Mikael Nordman - 2021-11-13

    You are using the wrong fuse values.
    Check here.
    https://flashforth.com/atmega.html

    And you have to use the 16 MHz version of the Pro Micro. Not the 8 MHz version.

     

    Last edit: Mikael Nordman 2021-11-13
  • Glaukon Ariston

    Glaukon Ariston - 2021-11-13

    Thanks for the quick reply. I have verified I have the 5V, 16MHz version of Pro Micro (16MHz crystal on board). Uploading the 32u4-16MHz-USB.hex file again with the recommended fuses I get the following output from avrdude. The efuse got set to CF instead of FF. Upon connecting it to the PC I get the device enumerated but with the exclamation mark in the Device Manager. The USB Device Tree View app shows the descriptors with the relevant Status and Problem Code.

    Status                   : 0x01806400 (DN_HAS_PROBLEM, DN_DISABLEABLE, DN_REMOVABLE, DN_NT_ENUMERATOR, DN_NT_DRIVER)
    Problem Code             : 10 (CM_PROB_FAILED_START)
    

    avrdude

    C:\app\electro\AVRDUDESS>avrdude -u -c usbasp-clone -p m32u4 -U flash:w:"D:\RE\Electronics\Arduino\flashforth\avr\hex\32u4-16MHz-USB.hex":a -U lfuse:w:0xFF:m -U hfuse:w:0xDF:m -U efuse:w:0xFF:m
    
    avrdude: warning: cannot set sck period. please check for usbasp firmware update.
    avrdude: AVR device initialized and ready to accept instructions
    
    Reading | ################################################## | 100% 0.03s
    
    avrdude: Device signature = 0x1e9587 (probably m32u4)
    avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed
             To disable this feature, specify the -D option.
    avrdude: erasing chip
    avrdude: warning: cannot set sck period. please check for usbasp firmware update.
    avrdude: reading input file "D:\RE\Electronics\Arduino\flashforth\avr\hex\32u4-16MHz-USB.hex"
    avrdude: input file D:\RE\Electronics\Arduino\flashforth\avr\hex\32u4-16MHz-USB.hex auto detected as Intel Hex
    avrdude: writing flash (32608 bytes):
    
    Writing | ################################################## | 100% 5.94s
    
    avrdude: 32608 bytes of flash written
    avrdude: verifying flash memory against D:\RE\Electronics\Arduino\flashforth\avr\hex\32u4-16MHz-USB.hex:
    avrdude: load data flash data from input file D:\RE\Electronics\Arduino\flashforth\avr\hex\32u4-16MHz-USB.hex:
    avrdude: input file D:\RE\Electronics\Arduino\flashforth\avr\hex\32u4-16MHz-USB.hex auto detected as Intel Hex
    avrdude: input file D:\RE\Electronics\Arduino\flashforth\avr\hex\32u4-16MHz-USB.hex contains 32608 bytes
    avrdude: reading on-chip flash data:
    
    Reading | ################################################## | 100% 5.26s
    
    avrdude: verifying ...
    avrdude: 32608 bytes of flash verified
    avrdude: reading input file "0xFF"
    avrdude: writing lfuse (1 bytes):
    
    Writing | ################################################## | 100% 0.02s
    
    avrdude: 1 bytes of lfuse written
    avrdude: verifying lfuse memory against 0xFF:
    avrdude: load data lfuse data from input file 0xFF:
    avrdude: input file 0xFF contains 1 bytes
    avrdude: reading on-chip lfuse data:
    
    Reading | ################################################## | 100% 0.02s
    
    avrdude: verifying ...
    avrdude: 1 bytes of lfuse verified
    avrdude: reading input file "0xDF"
    avrdude: writing hfuse (1 bytes):
    
    Writing | ################################################## | 100% 0.02s
    
    avrdude: 1 bytes of hfuse written
    avrdude: verifying hfuse memory against 0xDF:
    avrdude: load data hfuse data from input file 0xDF:
    avrdude: input file 0xDF contains 1 bytes
    avrdude: reading on-chip hfuse data:
    
    Reading | ################################################## | 100% 0.02s
    
    avrdude: verifying ...
    avrdude: 1 bytes of hfuse verified
    avrdude: reading input file "0xFF"
    avrdude: writing efuse (1 bytes):
    
    Writing | ################################################## | 100% 0.02s
    
    avrdude: 1 bytes of efuse written
    avrdude: verifying efuse memory against 0xFF:
    avrdude: load data efuse data from input file 0xFF:
    avrdude: input file 0xFF contains 1 bytes
    avrdude: reading on-chip efuse data:
    
    Reading | ################################################## | 100% 0.02s
    
    avrdude: verifying ...
    avrdude: verification error, first mismatch at byte 0x0000
             0xcf != 0xff
    avrdude: verification error; content mismatch
    
    avrdude done.  Thank you.
    

    USB Device Tree View

        =========================== USB Port2 ===========================
    
    Connection Status        : 0x01 (Device is connected)
    Port Chain               : 1-2
    Properties               : 0x01
     IsUserConnectable       : yes
     PortIsDebugCapable      : no
     PortHasMultiCompanions  : no
     PortConnectorIsTypeC    : no
    ConnectionIndex          : 2
    CompanionIndex           : 0
     CompanionHubSymLnk      : USB#ROOT_HUB30#4&2664ba56&0&0#{f18a0e88-c30c-11d0-8815-00a0c906bed8}
     CompanionPortNumber     : 11
     -> CompanionPortChain   : 1-11
    
          ======================== USB Device ========================
    
            +++++++++++++++++ Device Information ++++++++++++++++++
    Friendly Name            : USB Serial Device (COM13)
    Device Description       : USB Serial Device
    Device ID                : USB\VID_FAF0&PID_FAF0\5&1779F47&0&2
    Hardware IDs             : USB\VID_FAF0&PID_FAF0&REV_0000 USB\VID_FAF0&PID_FAF0
    Driver KeyName           : {4d36e978-e325-11ce-bfc1-08002be10318}\0010 (GUID_DEVCLASS_PORTS)
    Driver                   : \SystemRoot\System32\drivers\usbser.sys (Version: 10.0.19041.1202  Date: 2021-09-17)
    Driver Inf               : C:\WINDOWS\inf\usbser.inf
    Legacy BusType           : PNPBus
    Class                    : Ports
    Class GUID               : {4d36e978-e325-11ce-bfc1-08002be10318} (GUID_DEVCLASS_PORTS)
    Service                  : usbser
    Enumerator               : USB
    Location Info            : Port_#0002.Hub_#0002
    Container ID             : {2a24f566-3c15-11ec-b83e-e8b1fc69d704}
    Manufacturer Info        : Microsoft
    Capabilities             : 0x04 (Removable)
    Status                   : 0x01806400 (DN_HAS_PROBLEM, DN_DISABLEABLE, DN_REMOVABLE, DN_NT_ENUMERATOR, DN_NT_DRIVER)
    Problem Code             : 10 (CM_PROB_FAILED_START)
    HcDisableSelectiveSuspend: 0
    EnableSelectiveSuspend   : 0
    SelectiveSuspendEnabled  : 0
    EnhancedPowerMgmtEnabled : 0
    IdleInWorkingState       : 0
    WakeFromSleepState       : 0
    Power State              : D3 (supported: D0, D3, wake from D0)
    COM-Port                 : COM13 (none assigned)
    
            ---------------- Connection Information ---------------
    Connection Index         : 0x02 (2)
    Connection Status        : 0x01 (DeviceConnected)
    Current Config Value     : 0x00
    Device Address           : 0x06 (6)
    Is Hub                   : 0x00 (no)
    Device Bus Speed         : 0x01 (Full-Speed)
    Number Of Open Pipes     : 0x00 (0 pipes to data endpoints)
    Data (HexDump)           : 02 00 00 00 12 01 10 01 02 00 00 20 F0 FA F0 FA   ........... ....
                               00 00 00 01 00 01 00 01 00 06 00 00 00 00 00 01   ................
                               00 00 00                                          ...
    
            --------------- Connection Information V2 -------------
    Connection Index         : 0x02 (2)
    Length                   : 0x10 (16 bytes)
    SupportedUsbProtocols    : 0x03
     Usb110                  : 1 (yes)
     Usb200                  : 1 (yes)
     Usb300                  : 0 (no)
     ReservedMBZ             : 0x00
    Flags                    : 0x00
     DevIsOpAtSsOrHigher     : 0 (Is not operating at SuperSpeed or higher)
     DevIsSsCapOrHigher      : 0 (Is not SuperSpeed capable or higher)
     DevIsOpAtSsPlusOrHigher : 0 (Is not operating at SuperSpeedPlus or higher)
     DevIsSsPlusCapOrHigher  : 0 (Is not SuperSpeedPlus capable or higher)
     ReservedMBZ             : 0x00
    Data (HexDump)           : 02 00 00 00 10 00 00 00 03 00 00 00 00 00 00 00   ................
    
        ---------------------- Device Descriptor ----------------------
    bLength                  : 0x12 (18 bytes)
    bDescriptorType          : 0x01 (Device Descriptor)
    bcdUSB                   : 0x110 (USB Version 1.10)
    bDeviceClass             : 0x02 (Communications and CDC Control)
    bDeviceSubClass          : 0x00
    bDeviceProtocol          : 0x00 (No class specific protocol required)
    bMaxPacketSize0          : 0x20 (32 bytes)
    idVendor                 : 0xFAF0
    idProduct                : 0xFAF0
    bcdDevice                : 0x0000
    iManufacturer            : 0x00 (No String Descriptor)
    iProduct                 : 0x01 (String Descriptor 1)
    iSerialNumber            : 0x00 (No String Descriptor)
    bNumConfigurations       : 0x01 (1 Configuration)
    Data (HexDump)           : 12 01 10 01 02 00 00 20 F0 FA F0 FA 00 00 00 01   ....... ........
                               00 01                                             ..
    
        ------------------ Configuration Descriptor -------------------
    bLength                  : 0x09 (9 bytes)
    bDescriptorType          : 0x02 (Configuration Descriptor)
    wTotalLength             : 0x003E (62 bytes)
    bNumInterfaces           : 0x02 (2 Interfaces)
    bConfigurationValue      : 0x01 (Configuration 1)
    iConfiguration           : 0x00 (No String Descriptor)
    bmAttributes             : 0x80
     D7: Reserved, set 1     : 0x01
     D6: Self Powered        : 0x00 (no)
     D5: Remote Wakeup       : 0x00 (no)
     D4..0: Reserved, set 0  : 0x00
    MaxPower                 : 0x32 (100 mA)
    Data (HexDump)           : 09 02 3E 00 02 01 00 80 32 09 04 00 00 01 02 02   ..>.....2.......
                               01 00 05 24 00 10 01 04 24 02 02 05 24 06 00 01   ...$....$...$...
                               07 05 82 03 08 00 10 09 04 01 00 02 0A 00 00 00   ................
                               07 05 03 02 08 00 00 07 05 84 02 08 00 00         ..............
    
            ---------------- Interface Descriptor -----------------
    bLength                  : 0x09 (9 bytes)
    bDescriptorType          : 0x04 (Interface Descriptor)
    bInterfaceNumber         : 0x00
    bAlternateSetting        : 0x00
    bNumEndpoints            : 0x01 (1 Endpoint)
    bInterfaceClass          : 0x02 (Communications and CDC Control)
    bInterfaceSubClass       : 0x02 (Abstract Control Model)
    bInterfaceProtocol       : 0x01 (AT Commands defined by ITU-T V.250 etc)
    iInterface               : 0x00 (No String Descriptor)
    Data (HexDump)           : 09 04 00 00 01 02 02 01 00                        .........
    
            -------------- CDC Interface Descriptor ---------------
    bFunctionLength          : 0x05 (5 bytes)
    bDescriptorType          : 0x24 (Interface)
    bDescriptorSubType       : 0x00 (Header Functional Descriptor)
    bcdCDC                   : 0x110 (CDC Version 1.10)
    Data (HexDump)           : 05 24 00 10 01                                    .$...
    
            -------------- CDC Interface Descriptor ---------------
    bFunctionLength          : 0x04 (4 bytes)
    bDescriptorType          : 0x24 (Interface)
    bDescriptorSubType       : 0x02 (Abstract Control Management Functional Descriptor)
    bmCapabilities           : 0x02
     D7..4                   : 0x00 (Reserved)
     D3                      : 0x00 (not supports the notification Network_Connection)
     D2                      : 0x00 (not supports the request Send_Break)
     D1                      : 0x01 (supports the request combination of Set_Line_Coding, Set_Control_Line_State, Get_Line_Coding, and the notification Serial_State)
     D0                      : 0x00 (not supports the request combination of Set_Comm_Feature, Clear_Comm_Feature, and Get_Comm_Feature)
    Data (HexDump)           : 04 24 02 02                                       .$..
    
            -------------- CDC Interface Descriptor ---------------
    bFunctionLength          : 0x05 (5 bytes)
    bDescriptorType          : 0x24 (Interface)
    bDescriptorSubType       : 0x06 (Union Functional Descriptor)
    bControlInterface        : 0x00
    bSubordinateInterface[0] : 0x01
    Data (HexDump)           : 05 24 06 00 01                                    .$...
    
            ----------------- Endpoint Descriptor -----------------
    bLength                  : 0x07 (7 bytes)
    bDescriptorType          : 0x05 (Endpoint Descriptor)
    bEndpointAddress         : 0x82 (Direction=IN EndpointID=2)
    bmAttributes             : 0x03 (TransferType=Interrupt)
    wMaxPacketSize           : 0x0008 (8 bytes)
    bInterval                : 0x10 (16 ms)
    Data (HexDump)           : 07 05 82 03 08 00 10                              .......
    
            ---------------- Interface Descriptor -----------------
    bLength                  : 0x09 (9 bytes)
    bDescriptorType          : 0x04 (Interface Descriptor)
    bInterfaceNumber         : 0x01
    bAlternateSetting        : 0x00
    bNumEndpoints            : 0x02 (2 Endpoints)
    bInterfaceClass          : 0x0A (CDC-Data)
    bInterfaceSubClass       : 0x00
    bInterfaceProtocol       : 0x00
    iInterface               : 0x00 (No String Descriptor)
    Data (HexDump)           : 09 04 01 00 02 0A 00 00 00                        .........
    
            ----------------- Endpoint Descriptor -----------------
    bLength                  : 0x07 (7 bytes)
    bDescriptorType          : 0x05 (Endpoint Descriptor)
    bEndpointAddress         : 0x03 (Direction=OUT EndpointID=3)
    bmAttributes             : 0x02 (TransferType=Bulk)
    wMaxPacketSize           : 0x0008 (8 bytes)
    bInterval                : 0x00 (ignored)
    Data (HexDump)           : 07 05 03 02 08 00 00                              .......
    
            ----------------- Endpoint Descriptor -----------------
    bLength                  : 0x07 (7 bytes)
    bDescriptorType          : 0x05 (Endpoint Descriptor)
    bEndpointAddress         : 0x84 (Direction=IN EndpointID=4)
    bmAttributes             : 0x02 (TransferType=Bulk)
    wMaxPacketSize           : 0x0008 (8 bytes)
    bInterval                : 0x00 (ignored)
    Data (HexDump)           : 07 05 84 02 08 00 00                              .......
    
          -------------------- String Descriptors -------------------
    String descriptors are not available  (because the device has problem code CM_PROB_FAILED_START)
    
     
  • Mikael Nordman

    Mikael Nordman - 2021-11-13

    I am using linux so I have not tested it with windows. There seems to be a descriptor problem.
    Windows is more strict than linux with the descriptors.,

    I will check.

     
  • Mikael Nordman

    Mikael Nordman - 2021-11-13

    I have updated the code and hex files to work with windows.
    It now works with TeraTerm. MyFFshell does not work for some reason.

     
  • Glaukon Ariston

    Glaukon Ariston - 2021-11-14

    Thank you for your effort! I can confirm that the new hex file works. At least I got the command prompt ok<#,ram>, I haven't investigated further yet. Also, it works only in TeraTerm -- it does not work with PuTTY or RealTerm (at least I haven't managed to make it work). PuTTY complains that it cannot connect to COM port saying Unable to open connection to COM13. Unable to configure serial port.

     
  • Mikael Nordman

    Mikael Nordman - 2021-11-16

    The code and hex files are now updated to work also with PuTTY and and MyFFshell.
    There was a protocol handling error in the SET_LINE_CODING message code.

    So hopefully FF now works with all terminal programs.

     
    • Glaukon Ariston

      Glaukon Ariston - 2021-11-22

      @oh2aun I tried compiling the source code myself. The resulting hex file does not enumerate under Windows 10. Any ideas what am I doing wrong?

       
      • Mikael Nordman

        Mikael Nordman - 2021-11-23

        I have only updated the XC8 source files.
        I will remove the AVRASM2 source files from git soon.

        See https://flashforth.com/atmega.html

         
        • Glaukon Ariston

          Glaukon Ariston - 2021-11-26

          @oh2aun I have managed to successfully compile the hex file. Now, I would like to add some Forth words to the image (e.g. port definitions) -- how do I do that?

           
          • Mikael Nordman

            Mikael Nordman - 2021-11-27

            Here is one example.
            Notice the dictionary links (fdw ...)

             fdw      MEMHI_L
            L_FETCH_P:
                    .byte      NFA|INLINE|2
                    .ascii  "@p"
                    .align  1
            FETCH_P:
                    m_dup
                    movw    tosl, pl
                    ret
            
                    fdw      L_FETCH_P
            L_PORTB:
                    .byte      NFA|5
                    .ascii  "portb"
                    .align  1
                    m_dup
                    mov     tosl, lo8(PORTB)
                    mov     tosh, hi8(PORTB)
                    ret
            
                    fdw     L_PORTB
            L_PCFETCH:
                    .byte     NFA|3
                    .ascii  "pc@" ; ( -- c ) Fetch char from pointer
                    .align  1
            PCFETCH:
                    m_dup
                    movw    tosl, pl
                    jmp     CFETCH
            
             

            Last edit: Mikael Nordman 2021-11-27
            • Mikael Nordman

              Mikael Nordman - 2021-11-27

              It is also possible to write the dictionary links with a reusable label '9' and refer with '9b' backwards to the previous label.
              Then a macro could be made to read the ports from a file instead. This has already been implemented for the PIC24.

              See pic24/src/registers.inc

              These reusable labels are a feature of GNU assembler which is used for Atmega and PIC24.

              Sadly the assembler used by the XC8 for PIC18 is not based on GNU and it is highly optimzed for the PIC18 C compiler.

               

              Last edit: Mikael Nordman 2021-11-27
          • Mikael Nordman

            Mikael Nordman - 2021-11-27

            Now you can add your register definitions in
            avr/src/registers.inc

             
            • Glaukon Ariston

              Glaukon Ariston - 2021-11-27

              That was really quick. Thanks! I see you made a macro mreg for simplifying the port definitions. I will play around with it and come back with more questions ;-)

               
            • Glaukon Ariston

              Glaukon Ariston - 2021-11-27

              Is it possible for the assembler to calculate the length of the name? For example length("\name") in the mreg macro. Also, where can I find documentation for the .macro directive?

               
              • Mikael Nordman

                Mikael Nordman - 2021-11-27

                google 'gnu assembler manual'

                 
            • Glaukon Ariston

              Glaukon Ariston - 2021-11-27

              I have changed the definition of mreg so it does not require the name length parameter.

              ; Macros for registers
              .macro mreg reg, name, flags
                      fdw     9b
              .equ name_len, 2f-1f
              9:
                      .byte   NFA|\flags|name_len
              1:
                      .ascii  "\name"
              2:
                      .align  1
                      m_dup
                      ldi     tosl,lo8(\reg)
                      ldi     tosh,hi8(\reg)
                      ret
              .endm
              

              I have also expanded the port definitions in the registers.inc

              ; list here the registers you want to include in the FF core dictionary
              ; The parameters are
              ; register name, word name, word flags (inline=0x20)
              mreg PORTB,portb,0
              mreg DDRB,ddrb,0
              mreg PINB,pinb,0
              mreg PORTC,portc,0
              mreg DDRC,ddrc,0
              mreg PINC,pinc,0
              mreg PORTD,portd,0
              mreg DDRD,ddrd,0
              mreg PIND,pind,0
              mreg TIMSK1,timsk1,0
              mreg TIFR1,tifr1,0
              mreg TCNT1,tcnt1,0
              mreg OCR1A,ocr1a,0
              mreg OCR1B,ocr1b,0
              mreg ICR1,icr1,0
              mreg GTCCR,gtccr,0
              mreg ADMUX,admux,0
              mreg ADCSRA,adcsra,0
              mreg ADCSRB,adcsrb,0
              mreg DIDR0,didr0,0
              mreg EICRA,eicra,0
              mreg EIMSK,eimsk,0
              mreg EIFR,eifr,0
              mreg PCICR,pcicr,0
              mreg PCMSK0,pcmsk0,0
              

              Now I would like to implement a similar set of Forth words as in this YouTube video, e.g. .pins, mem, .pullup, flush, times, many, extend, ... Do I have to implement them all in assembler or is it possible to bundle Forth words written in Forth inside the hex file?

               
              • Mikael Nordman

                Mikael Nordman - 2021-11-27

                Well Done ! I will include the new macro into FF.

                You have the write those words in assembler.

                One could implement a mechanism that interprets and compiles forth from a text buffer in flash.
                But that does not exist in FF.

                 

                Last edit: Mikael Nordman 2021-11-27
                • Glaukon Ariston

                  Glaukon Ariston - 2021-11-27

                  I did a little bit of refactoring. Now there is a separate macro m_header that you can use to initialise the word header. This can simplify and shorten the code and make it more robust against the errors. Also you would not need to define all those extra link labels (e.g. SCAN_L).

                  .macro m_header name, flags
                          fdw     9b
                  .equ name_len, 2f-1f
                  9:
                          .byte   NFA|\flags|name_len
                  1:
                          .ascii  "\name"
                  2:
                          .align  1
                  .endm
                  
                  ; Macros for registers
                  .macro mreg reg, name, flags
                          m_header \name, \flags
                          m_dup
                          ldi     tosl,lo8(\reg)
                          ldi     tosh,hi8(\reg)
                          ret
                  .endm
                  
                   
  • Glaukon Ariston

    Glaukon Ariston - 2021-11-19

    I can confirm that it now works well with TeraTerm, PuTTY and RealTerm on Windows 10.

     
  • Simon Bridger

    Simon Bridger - 2021-11-19

    @glaukon btw, In recent realterm versions (43+) it will show you what windows knows about the USB device when it enumerates. https://sourceforge.net/p/realterm/news/2017/10/30141/

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.