Page 1 of 1

Loading assembler program on esp32-s3

Posted: Thu Aug 15, 2024 2:42 pm
by blurrpp
Hi. Im trying to compile and load on esp32 simple assembler code:

pin15.S
  1. [code]
  2. .section .text
  3. .global _start
  4.  
  5. _start:
  6.  
  7.     movi a2, 0x3FF44000  
  8.     movi a3, 1 << 15
  9.     s32i a3, a2, 0x4      # Set output bit for GPIO 15
  10.  
  11. loop:
  12.     movi a2, 0x3FF44000  
  13.     movi a3, 1 << 15      
  14.     s32i a3, a2, 0x4      
  15.  
  16.     call0 delay
  17.  
  18.  
  19.     movi a2, 0x3FF44000   # GPIO base address
  20.     movi a3, 1 << 15      # Mask for GPIO 15
  21.     s32i a3, a2, 0x8      # Clear output bit for GPIO 15
  22.  
  23.     call0 delay
  24.  
  25.  
  26.     j loop
  27.  
  28. delay:
  29.     movi a1, 0x3FFFFF
  30. delay_loop:
  31.     addi a1, a1, -1      
  32.     bnez a1, delay_loop  
  33.     ret                  
  34. [/code]
i compile it with:
  1.        xtensa-esp32s3-elf-as -o pin15.o pin15.S
  2.        xtensa-esp32s3-elf-ld -T linkerscript2.ld -o pin15.elf pin15.o
where linkerscript2.ld
  1. ENTRY(_start)
  2.  
  3. SECTIONS
  4. {
  5.     . = 0x400C0000; // i tried many addresses   like 0x40080000 etc. with similar problem
  6.  
  7.     .literal : {
  8.         *(.literal)
  9.     }
  10.     . = 0x400C00F0;
  11.     .text : {
  12.         *(.text)
  13.         *(.text.*)
  14.     }
  15.  
  16.     . = 0x3FFB0000;
  17.  
  18.     .data : {
  19.         *(.data)
  20.         *(.data.*)
  21.     }
  22.  
  23.     .bss : {
  24.         *(.bss)
  25.         *(.bss.*)
  26.     }
  27. }
Then add proper header:
  1.         esptool.py --chip esp32s3 elf2image pin15.elf  
Then write to esp32-s3:
  1. esptool.py --chip esp32-s3 --port /dev/ttyACM0 --baud 115200 write_flash 0x10000 pin15.bin
On /dev/ttyACM0 i get:


ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x3 (RTC_SW_SYS_RST),boot:0x8 (SPI_FAST_FLASH_BOOT)
Saved PC:0x403cdd11
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fce3810,len:0x1798
load:0x403c9700,len:0x4
load:0x403c9704,len:0xcbc
load:0x403cc700,len:0x2d98
entry 0x403c9914
I (31) boot: ESP-IDF v5.2-dirty 2nd stage bootloader
I (31) boot: compile time Aug 5 2024 03:46:49
I (31) boot: Multicore bootloader
I (35) boot: chip revision: v0.2
I (38) boot.esp32s3: Boot SPI Speed : 80MHz
I (43) boot.esp32s3: SPI Mode : DIO
I (48) boot.esp32s3: SPI Flash Size : 2MB
I (53) boot: Enabling RNG early entropy source...
I (58) boot: Partition Table:
I (62) boot: ## Label Usage Type ST Offset Length
I (69) boot: 0 nvs WiFi data 01 02 00009000 00005000
I (76) boot: 1 otadata OTA data 01 00 0000e000 00002000
I (84) boot: 2 app0 factory app 00 00 00010000 00140000
I (91) boot: 3 spiffs Unknown data 01 82 00150000 000a0000
I (99) boot: End of partition table
I (103) boot: Defaulting to factory image
I (108) esp_image: segment 0: paddr=00010020 vaddr=400c0000 size=00010h ( 16) load


E (116) esp_image: Segment 0 0x400c0000-0x400c0010 invalid: bad load address range
E (124) boot: Factory app partition is not bootable
E (130) boot: No bootable app partitions in the partition table


Im trying to understand where is problem. Maybe i should prepare another partition table an write it

Re: Loading assembler program on esp32-s3

Posted: Fri Aug 16, 2024 3:30 am
by ESP_Sprite
Your linker script is telling the bootloader to take your code and copy it to the indicated address, which won't work as it's a ROM region. Try either specifying an IRAM region or try adding a MEMORY segment with an iram0_2_seg line to your linker file that indicates the ROM region is RX.

Re: Loading assembler program on esp32-s3

Posted: Sat Aug 17, 2024 3:34 pm
by blurrpp
ESP_Sprite wrote:
Fri Aug 16, 2024 3:30 am
Your linker script is telling the bootloader to take your code and copy it to the indicated address, which won't work as it's a ROM region. Try either specifying an IRAM region or try adding a MEMORY segment with an iram0_2_seg line to your linker file that indicates the ROM region is RX.
Unfortunately i tried for example linker file :
ENTRY(_start)

MEMORY
{
iram0_0_seg : ORIGIN = 0x40080000, LENGTH = 0x20000 /* Instruction RAM */
dram0_0_seg : ORIGIN = 0x3FFB0000, LENGTH = 0x20000 /* Data RAM */
}

SECTIONS
{
.literal : {
*(.literal)
} > iram0_0_seg

.text : {
*(.text)
*(.text.*)
} > iram0_0_seg

.data : {
*(.data)
*(.data.*)
} > dram0_0_seg

.bss : {
*(.bss)
*(.bss.*)
} > dram0_0_seg
}

Witch the same result:


E (116) esp_image: Segment 0 0x40080000-0x40080044 invalid: bad load address range
E (124) boot: Factory app partition is not bootable
E (130) boot: No bootable app partitions in the partition table


Maybe partition table is wrong.