ESP32-C6 baremetal assembly riscv connexion USB

watchdog40
Posts: 8
Joined: Fri Jun 26, 2026 2:20 pm

ESP32-C6 baremetal assembly riscv connexion USB

Postby watchdog40 » Wed Jul 08, 2026 1:48 pm

This program, written in RISC-V assembly without using the IDF SDK, enables a connection from the ESP32-C6 to a terminal program like PuTTY via the USB port.
After compiling and pressing the reset button, the WS2812 LED flashes green twice to indicate that the program has started successfully.
The program then waits for a connection from PuTTY or Minicom.
Once connected, it displays a welcome message and waits for a command to be entered.
The `test` command makes the LED flash blue, while the `aff` command displays the contents of the `PCR_SYSCLK_FREQ_QUERY_0_REG` register.
This program can be modified by adding new commands to explore the capabilities of RISC-V and the ESP32-C6.
Please note: this is by no means professional-grade software! It is intended solely for hobbyists to explore the workings of the ESP32-C6, so it may contain quirks and errors.

program debusbasm4

Code: Select all

/* programm assembly riscv  */
/* connexion usb with putty or  minicom   */
/* blink led ws2812 */
/* display register */
/*******************************************/
/* CONSTANTES                              */
/*******************************************/
.equ  LED_PIN, 8
.equ  WHITE,0
.equ  RED, 1
.equ  GREEN,2       
.equ  BLUE,3
.equ DELAIt0l,     21    # for 80mhz -> 12ùs  12 *(( 3 * 21) + 5 ) = 816
.equ DELAIt0h,     10    #  12 * 35 = 420
.equ DELAIt1l,     15    #  12 * 50 = 600 
.equ DELAIt1h,     18    # 12 * 59 =  708

.equ GPIO_MATRIX,       0x60091000       
.equ GPIO_OUT_REG,      0x4
.equ GPIO_OUT_W1TS_REG, 0x8
.equ GPIO_OUT_W1TC_REG, 0xC
.equ GPIO_ENABLE_REG,   0x20 
.equ GPIO_ENABLE_W1TS_REG,0x24
.equ GPIO_ENABLE_W1TC_REG,0x28
.equ GPIO_PIN_REG,     0x74   +  (4*LED_PIN)
.equ GPIO_FUNC8_OUT_SEL_CFG_REG,  0x554 + (4*LED_PIN)
.equ GPIO_STATUS_REG,     0x44
.equ GPIO_CLOCK_GATE_REG ,0x062C
.equ GPIO_DATE_REG,       0x06FC

.equ PCR,                          0x60096000       # clock, reset 
.equ PCR_SYSCLK_CONF_REG,          0x0110
.equ PCR_IOMUX_CLK_CONF_REG,       0x00EC
.equ PCR_IOMUX_CONF_REG,           0x00E8
.equ PCR_USB_SERIAL_JTAG_CONF_REG, 0x008C
.equ PCR_SYSCLK_FREQ_QUERY_0_REG, 0x0124

.equ TIMG0,                0x60008000
.equ TIMG1,                0x60009000
.equ TIMG_WDTCONFIG0_REG,  0x0048
.equ TIMG_WDTWPROTECT_REG, 0x0064           # paragraphe 14.5
.equ VALUEPROCT,           0x50d83aa1

.equ RTC_WDT,                   0x600B1C00   # RTC Watch Dog Timer
.equ RTC_WDT_CONFIG0_REG,       0x0
.equ RTC_WDT_CONFIG1_REG,       0x4
.equ RTC_WDT_FEED_REG,          0x0014
.equ RTC_WDT_WPROTECT_REG,      0x0018
.equ RTC_WDT_SWD_WPROTECT_REG,  0x0020
.equ RTC_WDT_SWD_CONFIG_REG,    0x001C

.equ USBCTRL,                   0x6000F000 # USB Serial/JTAG Controller
# config registers
.equ USB_SERIAL_JTAG_EP1_REG,      0x0000    # chap 32
.equ USB_SERIAL_JTAG_EP1_CONF_REG, 0x0004
.equ USB_SERIAL_JTAG_INT_ST_REG,   0x000C       # interrup
.equ USB_SERIAL_JTAG_INT_CLR_REG,  0x0014
.equ USB_SERIAL_JTAG_CONF0_REG,    0x0018
.equ USB_SERIAL_JTAG_TEST_REG,     0x001C
.equ USB_SERIAL_JTAG_MISC_CONF_REG, 0x0044
.equ USB_SERIAL_JTAG_MEM_CONF_REG, 0x0048
.equ USB_SERIAL_JTAG_CHIP_RST_REG, 0x004C
.equ USB_SERIAL_JTAG_GET_LINE_CODE_W0_REG, 0x0058
.equ USB_SERIAL_JTAG_GET_LINE_CODE_W1_REG, 0x005C
.equ USB_SERIAL_JTAG_CONFIG_UPDATE_REG,    0x0060
.equ USB_SERIAL_JTAG_SER_AFIFO_CONFIG_REG, 0x0064
# status registers
.equ USB_SERIAL_JTAG_JFIFO_ST_REG,   0x0020
.equ USB_SERIAL_JTAG_FRAM_NUM_REG,   0x0024
.equ USB_SERIAL_JTAG_IN_EP0_ST_REG,  0x0028
.equ USB_SERIAL_JTAG_IN_EP1_ST_REG,  0x002C
.equ USB_SERIAL_JTAG_IN_EP2_ST_REG,  0x0030
.equ USB_SERIAL_JTAG_IN_EP3_ST_REG,  0x0034
.equ USB_SERIAL_JTAG_OUT_EP0_ST_REG, 0x0038
.equ USB_SERIAL_JTAG_OUT_EP1_ST_REG, 0x003C
.equ USB_SERIAL_JTAG_OUT_EP2_ST_REG, 0x0040
/*******************************************/
/* DONNEES INITIALISEES                    */
/*******************************************/ 
.data
szMessDebut:       .asciz "Start assembly riscv program.\r\n"
szCarriageReturn:  .asciz "\r\n"
szMessRegistre:    .asciz "Register value :"

szMessCmd:         .asciz "Enter a command :"
szLibCmdTest:      .asciz "test"
szLibCmdAff:       .asciz "aff"
szLibCmdEnd:       .asciz "end"         # undeveloped
szMessCmdInc:      .asciz "Unknown command.\r\n"
.align 2
inbflash:    .int 2
/***********************************************/
/* Données non initialisées                    */
/***********************************************/
.bss
sZoneConv:  .skip 24
sBuffer:    .skip 80
/*******************************************/
/*  CODE PROGRAMME                         */
/*******************************************/  
.text
.align 2
.global main
/************************************...-..--*****/
/*      Main                                     */
/*************************************************/
main:                       # INFO: main
    .int 0xAEDB041D, 0xAEDB041D # magic number
    
    li sp,0x4080CC00        # stack address
    
    call initStart          # initialisations 
 
    la a0,inbflash          # verify  data copy
    lw a0,(a0)
    li a1,GREEN             # verify start OK
    li a2,20                # 
    call led2812Eclats

    call initUSBctrl        # init controller usb
    la a0,szMessDebut       # display first message
    call envoyerMessage
    
1:
    la a0,szMessCmd
    call envoyerMessage     # display message command
    la a0,sBuffer
    call recevoirMessage    # command entry
    
    la a0,sBuffer
    la a1,szLibCmdTest       # INFO: comand test
    call comparerChaines
    bnez a0,2f
    
    li a0,2
    li a1,BLUE               # verify test command
    li a2,20                 # by 2 blue flash led 
    call led2812Eclats
    j 20f
2:
    la a0,sBuffer
    la a1,szLibCmdAff       # INFO: comand aff
    call comparerChaines
    bnez a0,3f
    li t0,PCR
    lw a0,PCR_SYSCLK_FREQ_QUERY_0_REG(t0)
    call displayRegister

    j 20f
3:
     # other commands
19:                          # unknow command
    la a0,szMessCmdInc
    call envoyerMessage
20:
    j 1b                     # and loop
    

.align 2

/************************************/
/*       Init USB             */
/***********************************/
/* a0  paramètre */
initUSBctrl:                 # INFO: initUSBctrl
    addi    sp, sp, -8       # save registres
    sw      ra, 0(sp)
    sw      s0, 4(sp)
    
    li s0,PCR
    li t0,1                  # enable usb clock
    sw t0,PCR_USB_SERIAL_JTAG_CONF_REG(s0)
    
    li s0,USBCTRL
    li t0,0x4200              # USB_SERIAL_JTAG_DP_PULLUP and USB_SERIAL_JTAG_USB_PAD_ENABLE
    sw t0,USB_SERIAL_JTAG_CONF0_REG(s0)
    
1:                            # loop to wait for a connection
    lw t0,USB_SERIAL_JTAG_OUT_EP0_ST_REG(s0)
    li t1,0x1024              # TODO: This solution needs to be reconsidered !!!
    blt t0,t1,1b
    
100:    
    lw      ra, 0(sp)
    lw      s0, 4(sp)
    addi    sp, sp, 8
    ret 
/************************************/
/*       send message to host             */
/***********************************/
/*  a0  address message */
/*  caution : less 64 caracteres */
envoyerMessage:                 # INFO: envoyerMessage
    addi    sp, sp, -8           # save registres
    sw      ra, 0(sp)
    sw      s0, 4(sp)
    li s0,USBCTRL
1:
    lw t0,USB_SERIAL_JTAG_EP1_CONF_REG(s0)
    andi t0,t0,0b10                # FIFO empty ?
    beqz t0,1b                     # no loop
    
    li t0,0
2:                                 # copy loop message char in FIFO
    add t1,a0,t0
    lbu t2,(t1)
    beqz t2,3f
    sb t2,USB_SERIAL_JTAG_EP1_REG(s0)
    addi t0,t0,1
    j 2b
3:
    li t0,1                         # write FIFO
    sw t0,USB_SERIAL_JTAG_EP1_CONF_REG(s0)

100:    
    lw      ra, 0(sp)
    lw      s0, 4(sp)
    addi    sp, sp, 8
    ret 
/************************************/
/*       Exemple             */
/***********************************/
/* a0  buffer address */
recevoirMessage:                 # INFO: recevoirMessage
    addi    sp, sp, -8           # save registres
    sw      ra, 0(sp)
    sw      s0, 4(sp)
    li s0,USBCTRL
    li t2,0
1:                               # wait loop
    lw t0,USB_SERIAL_JTAG_EP1_CONF_REG(s0)
    andi t0,t0,0b100             # USB_SERIAL_JTAG_SERIAL_OUT_EP_DATA_AVAIL
    beqz t0,1b

    lbu t0,USB_SERIAL_JTAG_EP1_REG(s0)     # read character
    beqz t0,2f                             # end if zero or cr or lf
    li t1,0x10
    beq t0,t1,2f
    li t1,0xD
    beq t0,t1,2f
 
    sw t0,USB_SERIAL_JTAG_EP1_REG(s0)      # display character
    li t4,1                                # write FIFO
    sw t4,USB_SERIAL_JTAG_EP1_CONF_REG(s0)
    
    add t3,a0,t2
    sb t0,(t3)                             # store char in buffer
    addi t2,t2,1                           # and increment size
    j 1b
2:
    add t3,a0,t2
    sb x0,(t3)                # final zero
    la a0,szCarriageReturn
    call envoyerMessage
    addi a0,t2,-1             # return size (without a trailing zero)
100:    
    lw      ra, 0(sp)
    lw      s0, 4(sp)
    addi    sp, sp, 8
    ret
/************************************/
/*       initialisation             */
/***********************************/
initStart:                       # INFO: initStart
    addi    sp, sp, -8           # save registres
    sw      ra, 0(sp)
    li t0,0x28010200 
    li t1,PCR 
    sw t0,PCR_SYSCLK_CONF_REG(t1)
    
    
    li t0,TIMG0                           # disable timer watchdog
    li t1,VALUEPROCT
    sw t1,TIMG_WDTWPROTECT_REG(t0)
    li t1,0
    sw t1,TIMG_WDTCONFIG0_REG(t0)
    li t1,1
    sw t1,TIMG_WDTWPROTECT_REG(t0)
    
    
    li t1,RTC_WDT                         # disable watchdog
    li t0,0x50D83AA1
    sw t0,RTC_WDT_WPROTECT_REG(t1)
    li t0,0x50D83AA1
    sw t0,RTC_WDT_SWD_WPROTECT_REG(t1)
    li t0,0x40000000
    sw t0,RTC_WDT_SWD_CONFIG_REG(t1)
    sw x0,RTC_WDT_CONFIG0_REG(t1)
    sw x0,RTC_WDT_CONFIG1_REG(t1)
    li t0,1
    sw t0,RTC_WDT_SWD_WPROTECT_REG(t1)
    
    la t1,iFlashdata
    lw t1,(t1)

    la t2,iRamdata 
    lw t2,(t2)
    la t3,iRamBss
    lw t3,(t3)

1:                           # copy flash data 
    lw t0,(t1)               # to ram data
    sw t0,(t2)
    addi t1,t1,4
    addi t2,t2,4
    bltu t2,t3,1b
                             #  initialisation  .bss
    la t2,iFinRamBss
    lw t2,(t2)
2:
    sw x0,(t3)               # load zero in bss
    addi t3,t3,4
    bltu t3,t2,2b
    
100:    
    lw      ra, 0(sp)
    addi    sp, sp, 8
    ret 
.align 2
iFlashdata:   .int _debutFlashData   
iRamdata:     .int _debutRamData 
iRamBss:      .int _debutRamBss
iFinRamBss:   .int _finRamBss
iDebutTas:    .int _debutTas

/************************************/
/*       init gpio               */ 
/***********************************/
/* a0 pin led */
initGpioLed:                   # INFO: initGpioLed

    addi    sp, sp, -8
    sw      ra, 0(sp)
    li    t4,GPIO_MATRIX
    li t0,1
    sll    t2,t0,a0                  # bit pin 8
    sw t2,GPIO_ENABLE_W1TS_REG(t4)
    li t0,0x280                       # 
    sw t0,GPIO_FUNC8_OUT_SEL_CFG_REG(t4)
    
    li    t4,GPIO_MATRIX
    li t0,0
    sw t0,GPIO_PIN_REG(t4)

100:
    lw      ra, 0(sp)
    addi    sp, sp, 8
    ret
 
/************************************/
/*       boucle attente            */
/***********************************/
/* a0 valeur en milliseconde   */
.align 2
attendre:                     # INFO: attendre
    addi    sp, sp, -12        # save des registres
    sw      ra, 0(sp)
    sw      t0, 4(sp)
    sw      t1, 8(sp)

    li t0,16                  # approximatif 
    sll t1,a0,t0
    li t0,12
    sll a0,a0,t0
    add a0,a0,t1
1:                            # loop 
    addi a0,a0, -1            # decrement indice
    bne a0,x0,1b
    lw      ra, 0(sp)
    lw      t0, 4(sp)
    lw      t1, 8(sp)
    addi    sp, sp, 12         # restaur registres
    jr ra
.align 2
/************************************/
/*       Exemple             */
/***********************************/
/* a0  nombre eclats */
/* a1 contient la couleur 0 blanc 1 red 2 green 3 blue */
/* a2 contient le niveau */
led2812Eclats:                 # INFO: led2812Eclats
    addi    sp, sp, -16           # save registres
    sw      ra, 0(sp)
    sw      s0, 4(sp)
    sw      s1, 8(sp)
    sw      s2, 12(sp)
    mv s0,a0
    mv s1,a1
    mv s2,a2
    
    li a0,LED_PIN
    call initGpioLed

    li a0,000       # raz led 
    li a1,000
    li a2,000
    call envoiComLed
    li a0,10
    call attendre
1:
    li t0,RED
    bne s1,t0,2f
    mv a0,s2
    li a1,000
    li a2,000
    j 5f
2:
    li t0,GREEN
    bne s1,t0,3f
    li a0,0
    mv a1,s2
    li a2,000
    j 5f
3:
    li t0,BLUE
    bne s1,t0,4f
    li a0,0
    li a1,0
    mv a2,s2
    j 5f
4:
    mv a0,s2
    mv a1,s2
    mv a2,s2
5:
    call envoiComLed
    li a0,500         # avant 250
    call attendre
    li a0,000       # raz led 
    li a1,000
    li a2,000
    call envoiComLed
    li a0,500
    call attendre
    addi s0,s0,-1
    bgtz s0,1b           # et boucle
    
100:    
    lw      ra, 0(sp)
    lw      s0, 4(sp)
    lw      s1, 8(sp)
    lw      s2, 12(sp)
    addi    sp, sp, 16
    ret 
.align 2
/************************************/
/*    envoi des codes couleurs vers le pin LED    */
/***********************************/
/* a0 contient la couleur rouge  0 255   */
/* a1 contient la couleur verte  0 255   */
/* a2 contient la couleur bleue 0 255 */
/* attention ne rien mettre entre chaque envoi de couleur */
envoiComLed:                     # INFO: envoiComLed
    addi    sp, sp, -12           # save registres
    sw      ra, 0(sp)
    sw      s0, 4(sp)
    sw      s1, 8(sp)
    mv s0,a0
    li s1,1
    slli s1,s1,LED_PIN
    li t1,7               # debut par le bit 7
    li t4,GPIO_MATRIX
1:                        # couleur verte
    srl t3,s0,t1
    andi t3,t3,1          # test bit 0
    bnez t3,2f
    sw s1,GPIO_OUT_W1TS_REG(t4)
    li a0,DELAIt0h                # 1 cycle
    call cycleLedWs2812           # 2 cycles
    sw s1,GPIO_OUT_W1TC_REG(t4)
    li a0,DELAIt0l                # 1 cycle
    call cycleLedWs2812           # 2 cycles
    j 3f
2:
    sw s1,GPIO_OUT_W1TS_REG(t4)
    li a0,DELAIt1h                # 1 cycle
    call cycleLedWs2812           # 2 cycles
    sw s1,GPIO_OUT_W1TC_REG(t4)          # clear
    li a0,DELAIt1l                # 1 cycle
    call cycleLedWs2812           # 2 cycles
    
3:
    addi t1,t1,-1
    bgez t1,1b
    li t1,7
4:                          # couleur rouge
    srl t3,a1,t1
    andi t3,t3,1
    bnez t3,5f
    sw s1,GPIO_OUT_W1TS_REG(t4)
    li a0,DELAIt0h                # 1 cycle
    call cycleLedWs2812           # 2 cycles
    sw s1,GPIO_OUT_W1TC_REG(t4)    # clear
    li a0,DELAIt0l                # 1 cycle
    call cycleLedWs2812           # 2 cycles
    j 6f
5:
    sw s1,GPIO_OUT_W1TS_REG(t4)
    li a0,DELAIt1h                # 1 cycle
    call cycleLedWs2812           # 2 cycles
    sw s1,GPIO_OUT_W1TC_REG(t4)
    li a0,DELAIt1l                # 1 cycle
    call cycleLedWs2812           # 2 cycles

6:
    addi t1,t1,-1
    bgez t1,4b
    li t1,7
7:                           # coukeur bleue
    srl t3,a2,t1
    andi t3,t3,1
    
    bnez t3,8f
    sw s1,GPIO_OUT_W1TS_REG(t4)
    li a0,DELAIt0h                # 1 cycle
    call cycleLedWs2812           # 2 cycles
    sw s1,GPIO_OUT_W1TC_REG(t4)
    li a0,DELAIt0l                # 1 cycle
    call cycleLedWs2812           # 2 cycles
    j 9f
8:
    sw s1,GPIO_OUT_W1TS_REG(t4)
    li a0,DELAIt1h                # 1 cycle
    call cycleLedWs2812           # 2 cycles
    sw s1,GPIO_OUT_W1TC_REG(t4)        # clear
    li a0,DELAIt1l                # 1 cycle
    call cycleLedWs2812           # 2 cycles
9:
    addi t1,t1,-1
    bgez t1,7b
    
100:    
    lw      ra, 0(sp)
    lw      s0, 4(sp)
    lw      s1, 8(sp)
    addi    sp, sp, 12
    ret 
.align 2
/************************************/
/*          loop cycles Led    */
/***********************************/
/* a0  loop number */
cycleLedWs2812:             # INFO: cycleLedWs2812
1:  
    addi a0,a0,-1           # 1 cycle * N
    bnez a0,1b              # 2 cycles * N + 1 cycle end
    ret                     # 2 cycles 
.align 2

/************************************/       
/* comparaison de chaines           */
/************************************/      
/* a0 et a1 contiennent les adresses des chaines */
/* retour 0 dans r0 si egalite */
/* retour -1 si chaine r0 < chaine r1 */
/* retour 1  si chaine r0> chaine r1 */
comparerChaines:          # INFO: comparerChaines
    addi    sp, sp, -4
    sw      ra, 0(sp)

    li t0,0
1:
    add t1,t0,a0
    lb t1,(t1)
    add t2,t0,a1
    lb t2,(t2)
    beq t1,t2,2f
    bgt t1,t2,3f
    blt t1,t2,4f
2:                         # egal
    addi t0,t0,1
    bne t1,x0,1b           # fin chaine
    li a0,0                # egalité
    j 100f
3:                         # plus haut
    li a0,1
    j 100f
4:                         # plus bas
    li a0,-1
    j 100f
    
100:
    lw      ra, 0(sp)
    addi    sp, sp, 4
    ret
    
/**********************************************/
/*    Display  one register                    */
/**********************************************/
/* a0    nombre a convertir */
/* registres t0 t1 t2 non sauvegardés */
displayRegister:              # INFO: displayRegister
    addi    sp, sp, -12     # reserve pile
    sw      ra, 0(sp)      # Adresse de retour
    la a1,sZoneConv
    call conversion16
    la a0,szMessRegistre
    call envoyerMessage
    la a0,sZoneConv
    call envoyerMessage
    la a0,szCarriageReturn
    call envoyerMessage
100:    
    lw      ra, 0(sp)
    addi    sp, sp, 12
    ret 
/**********************************************/
/* conversion hexadecimale                    */
/**********************************************/
/* a0    nombre a convertir */
/* a1    adresse zone de conversion */
/* registres t0 t1 t2 non sauvegardés */
.equ LGZONECONV,   20
conversion16:              # INFO: conversion16
    addi    sp, sp, -12     # reserve pile
    sw      ra, 0(sp)      # Adresse de retour 	Appelant
    sw      s1, 4(sp)  
    sw      s2, 8(sp)
    li t0,28               # start bit position
    li t1,0xF0000000       # mask
    mv t2,a0               # save entry value
1:                         # start loop
    and a0,t2,t1           # value register and mask
    srl a0,a0,t0           # shift right 
    li s2,10               # move 10
    blt a0,s2,2f           # compare value
    addi a0,a0,55          # letters A-F
    j 3f
2:
    addi a0,a0,48          # number
3:
    
    sb a0,(a1)            # store digit on area and + 1 in area address
    addi a1,a1,1
    srli t1,t1,4           # shift mask 4 positions
    addi t0,t0,-4          #  counter bits - 4 <= zero  ?
    bge t0,x0,1b           #  no -> loop
    sb x0,(a1)             # store final zero
    li a0,8                # return size 
    
100:
    lw      ra, 0(sp)      # restaur registre
    lw      s1, 4(sp)
    lw      s2, 8(sp)
    addi    sp, sp, 12      # liberer pile
    ret
/************************************/
/*       Exemple             */
/***********************************/
/* a0  paramètre */
exempleFonction:                 # INFO: exempleFonction
    addi    sp, sp, -8           # save registres
    sw      ra, 0(sp)
    
100:    
    lw      ra, 0(sp)
    addi    sp, sp, 8
    ret 
makefile
Change Tools path and port com

Code: Select all

ARMGNU ?= C:/Espressif/tools/riscv32-esp-elf/esp-15.2.0_20251204/riscv32-esp-elf/bin
#ARMGNU ?= C:\Espressif\tools\riscv32-esp-elf\esp-15.2.0_20251204\riscv32-esp-elf\riscv32-esp-elf\bin
ARMGNU1 ?=  C:\PrincipalA\Outils\tools\arm-gnu-toolchain-13.3.rel1-mingw-w64-i686-arm-none-eabi\arm-none-eabi\bin
AOPS =   -mabi=ilp32 -march=rv32i_m_zbs_zicsr_f_zba
all : debusbasm4.flash

debusbasm4.o : debusbasm4.s 
	$(ARMGNU)/riscv32-esp-elf-as.exe  $(AOPS) debusbasm4.s -o debusbasm4.o

debusbasm4.bin :   debusbasm4.o
	$(ARMGNU)/riscv32-esp-elf-ld.exe -T memmap.ld   debusbasm4.o -o debusbasm4.elf  -M >debusbasm4_map.txt
	$(ARMGNU)/riscv32-esp-elf-objcopy -O binary debusbasm4.elf debusbasm4.bin
	$(ARMGNU)/riscv32-esp-elf-objdump.exe -D debusbasm4.elf > debusbasm4_list.txt
debusbasm4.flash : debusbasm4.bin
	C:\Espressif\tools\python\v6.0.1\venv\Scripts\esptool --chip esp32c6 -p com14  -b 460800  write-flash --flash-mode dio  --flash-freq 80m --flash-size 2MB 0x0  debusbasm4.bin
file memmap.ld

Code: Select all

MEMORY
{
  flash     (rx)  : ORIGIN = 0x42000000, LENGTH = 2048k
  ram      (rwx)  : ORIGIN = 0x40800000, LENGTH = 0x80000
}

STACK_SIZE = 0x4000;

RAM_SIZE =  0x80000;

/* Section Definitions */
SECTIONS
{
    .text :
    {
       /*  KEEP(*(.vectors .vectors.*)) */
        *(.text*)
        *(.rodata*)
    } > flash

    . = ALIGN(4);
    _debutFlashData = . ;
    .data :
    {
      . = ALIGN(2);

      _debutRamData = . ;
      . = ALIGN(2);

        *(.data*);
    } > ram AT > flash
     /* .bss section which is used for uninitialized data */
    . = ALIGN(4); /* aligne bss pour initialisation dans pgm */
     _debutRamBss = . ;
    .bss (NOLOAD) :
    {
        *(.bss*)
        *(COMMON)
    } > ram
    _finRamBss = . ;

    .SC1 (NOLOAD):
    {
        . = ALIGN(8);
     _debutTas = . ;
    . = _debutRamData - . + RAM_SIZE - (STACK_SIZE) ;
    } > ram
    _finTas = . ;

   /* stack section */
    .stack (NOLOAD):
    {
        . = ALIGN(8);
        . = . + STACK_SIZE;
        _stack = .;
        . = ALIGN(8);
    } > ram

    _end = . ;
}
Example compilation :
(There are error messages, but they do not interfere with the program's execution in any way.)
(venv) PS C:\Principal\esp32c6\projets\debutUSB\debusbasm4> make
C:/Espressif/tools/riscv32-esp-elf/esp-15.2.0_20251204/riscv32-esp-elf/bin/riscv32-esp-elf-as.exe -mabi=ilp32 -march=rv32i_m_zbs_zicsr_f_zba debusbasm4.s -o debusbasm4.o
C:/Espressif/tools/riscv32-esp-elf/esp-15.2.0_20251204/riscv32-esp-elf/bin/riscv32-esp-elf-ld.exe -T memmap.ld debusbasm4.o -o debusbasm4.elf -M >debusbasm4_map.txt
C:/Espressif/tools/riscv32-esp-elf/esp-15.2.0_20251204/riscv32-esp-elf/bin/riscv32-esp-elf-objcopy -O binary debusbasm4.elf debusbasm4.bin
C:/Espressif/tools/riscv32-esp-elf/esp-15.2.0_20251204/riscv32-esp-elf/bin/riscv32-esp-elf-objdump.exe -D debusbasm4.elf > debusbasm4_list.txt
C:\Espressif\tools\python\v6.0.1\venv\Scripts\esptool --chip esp32c6 -p com14 -b 460800 write-flash --flash-mode dio --flash-freq 80m --flash-size 2MB 0x0 debusbasm4.bin
esptool v5.3.0
Connected to ESP32-C6 on com14:
Chip type: ESP32-C6FH8 (QFN32) (revision v0.2)
Features: Wi-Fi 6, BT 5 (LE), IEEE802.15.4, Single Core + LP Core, 160MHz, Embedded Flash 8MB
Crystal frequency: 40MHz

Failed to get VID/PID of a device on com14, using standard reset sequence.

Failed to get VID/PID of a device on com14, using standard reset sequence.
MAC: ac:eb:e6:ff:fe:2c:bf:cc
BASE MAC: ac:eb:e6:2c:bf:cc
MAC_EXT: ff:fe

Stub flasher running.
Changing baud rate to 460800...
Changed.

Configuring flash size...
Warning: Image file at 0x0 doesn't look like an image file, so not changing any flash settings.
Flash will be erased from 0x00000000 to 0x00000fff...
Wrote 1696 bytes (1035 compressed) at 0x00000000 in 0.0 seconds (1267.1 kbit/s).
Hash of data verified.

Hard resetting via RTS pin...

Failed to get VID/PID of a device on com14, using standard reset sequence.
Example display result :
Start assembly riscv program.
Enter a command :test
Enter a command :aff
Register value :0001E014
Enter a command :

Who is online

Users browsing this forum: No registered users and 0 guests