Browse Source

* more riscv32-freertos-esp32c3 stuff added

florian 2 years ago
parent
commit
e9ec4a8bb3

+ 4 - 4
compiler/globals.pas

@@ -262,12 +262,12 @@ interface
        { specified with -FW and -Fw }
        wpofeedbackinput,
        wpofeedbackoutput : TPathStr;
-{$ifdef XTENSA}
+{$if defined(XTENSA) or defined(RISCV32)}
        { specified with -Ff }
        idfpath           : TPathStr;
        { specified with }
        idf_version       : longint;
-{$endif XTENSA}
+{$endif defined(XTENSA) or defined(RISCV32)}
        { external assembler extra option }
        asmextraopt       : string;
 
@@ -1668,9 +1668,9 @@ implementation
         cshared:=false;
         rlinkpath:='';
         sysrootpath:='';
-{$ifdef XTENSA}
+{$if defined(XTENSA) or defined(RISCV32)}
         idfpath:='';
-{$endif XTENSA}
+{$endif defined(XTENSA) or defined(RISCV32)}
 
         { Search Paths }
         unicodepath:='';

+ 2 - 2
compiler/options.pas

@@ -2138,10 +2138,10 @@ begin
                          ParaFrameworkPath.AddPath(More,false)
                        else
                          frameworksearchpath.AddPath(More,true)
-{$ifdef XTENSA}
+{$if defined(XTENSA) or defined(RISCV32)}
                      else if (target_info.system=system_xtensa_freertos) then
                        idfpath:=FixPath(More,true)
-{$endif XTENSA}
+{$endif defined(XTENSA) or defined(RISCV32)}
                      else
                        IllegalPara(opt);
                  'F' :

+ 1 - 1
compiler/riscv32/cpuinfo.pas

@@ -133,7 +133,7 @@ Const
       (controllertypestr:'CH32V307RC'; controllerunitstr:'CH32V307';    cputype:cpu_rv32imac; fputype:fpu_fd; flashbase:$00000000; flashsize:$00040000; srambase:$20000000; sramsize:$00010000),
       (controllertypestr:'CH32V307WC'; controllerunitstr:'CH32V307';    cputype:cpu_rv32imac; fputype:fpu_fd; flashbase:$00000000; flashsize:$00040000; srambase:$20000000; sramsize:$00010000),
       (controllertypestr:'CH32V307VC'; controllerunitstr:'CH32V307';    cputype:cpu_rv32imac; fputype:fpu_fd; flashbase:$00000000; flashsize:$00040000; srambase:$20000000; sramsize:$00010000),
-      (controllertypestr:'ESP32C3'; controllerunitstr:'ESP32C3';    cputype:cpu_rv32imc; fputype:fpu_none; flashbase:$00000000; flashsize:$00040000; srambase:$20000000; sramsize:$00010000)
+      (controllertypestr:'ESP32C3'; controllerunitstr:'ESP32C3';    cputype:cpu_rv32imc; fputype:fpu_none; flashbase:$00000000; flashsize:2*1024*1024; srambase:$20000000; sramsize:$00010000)
    );
    {$POP}
 

+ 28 - 5
compiler/systems/t_freertos.pas

@@ -1296,14 +1296,14 @@ var
 {$ifdef XTENSA}
   memory_script,
   sections_script: AnsiString;
-  {$endif XTENSA}
+ {$endif XTENSA}
 begin
-{$ifdef XTENSA}
+{$if defined(XTENSA) or defined(RISCV32)}
   { idfpath can be set by -Ff, else default to environment value of IDF_PATH }
   if idfpath='' then
     idfpath := trim(GetEnvironmentVariable('IDF_PATH'));
   idfpath:=ExcludeTrailingBackslash(idfpath);
-{$endif XTENSA}
+{$endif defined(XTENSA) or defined(RISCV32)}
 
   { for future use }
   StaticStr:='';
@@ -1413,7 +1413,7 @@ begin
   if success and not(cs_link_nolink in current_settings.globalswitches) then
     success:=PostProcessExecutable(FixedExeFileName,false);
 
-{$ifdef XTENSA}
+{$if defined(XTENSA)}
   if success then
    begin
 {$ifdef UNIX}
@@ -1445,7 +1445,30 @@ begin
         end
    end
   else
-{$endif XTENSA}
+{$elseif defined(RISCV32)}
+  if success then
+   begin
+{$ifdef UNIX}
+      binstr:=TargetFixPath(idfpath,false)+'/components/esptool_py/esptool/esptool.py';
+      cmdstr:='';
+{$else}
+      binstr:='python';
+      cmdstr:=idfpath+'/components/esptool_py/esptool/esptool.py ';
+{$endif UNIX}
+      if source_info.exeext<>'' then
+        binstr:=binstr+source_info.exeext;
+      if (current_settings.controllertype = ct_esp32c3) then
+        begin
+          success:=DoExec(binstr,cmdstr+'--chip esp32c3 elf2image --flash_mode dio --flash_freq 80m '+
+            '--flash_size '+tostr(embedded_controllers[current_settings.controllertype].flashsize div (1024*1024))+'MB '+
+            '--elf-sha256-offset 0xb0 --min-rev 3 '+
+            '-o '+maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.bin')))+' '+
+            FixedExeFileName,
+            true,false);
+        end;
+   end
+  else
+{$endif defined(RISCV32)}
     if success then
       success:=DoExec(FindUtil(utilsprefix+'objcopy'),'-O binary '+
         FixedExeFileName+' '+

+ 19 - 4
rtl/freertos/Makefile

@@ -2,7 +2,7 @@
 # Don't edit, this file is generated by FPCMake Version 2.0.0
 #
 default: all
-MAKEFILETARGETS=i386-linux i386-go32v2 i386-win32 i386-os2 i386-freebsd i386-beos i386-haiku i386-netbsd i386-solaris i386-netware i386-openbsd i386-wdosx i386-darwin i386-emx i386-watcom i386-netwlibc i386-wince i386-embedded i386-symbian i386-nativent i386-iphonesim i386-android i386-aros m68k-linux m68k-netbsd m68k-amiga m68k-atari m68k-palmos m68k-macosclassic m68k-embedded m68k-sinclairql powerpc-linux powerpc-netbsd powerpc-amiga powerpc-macosclassic powerpc-darwin powerpc-morphos powerpc-embedded powerpc-wii powerpc-aix sparc-linux sparc-netbsd sparc-solaris sparc-embedded x86_64-linux x86_64-freebsd x86_64-haiku x86_64-netbsd x86_64-solaris x86_64-openbsd x86_64-darwin x86_64-win64 x86_64-embedded x86_64-iphonesim x86_64-android x86_64-aros x86_64-dragonfly arm-linux arm-netbsd arm-palmos arm-wince arm-gba arm-nds arm-embedded arm-symbian arm-android arm-aros arm-freertos arm-ios powerpc64-linux powerpc64-darwin powerpc64-embedded powerpc64-aix avr-embedded armeb-linux armeb-embedded mips-linux mipsel-linux mipsel-embedded mipsel-android mips64-linux mips64el-linux jvm-java jvm-android i8086-embedded i8086-msdos i8086-win16 aarch64-linux aarch64-freebsd aarch64-darwin aarch64-win64 aarch64-embedded aarch64-android aarch64-ios wasm32-embedded wasm32-wasi sparc64-linux riscv32-linux riscv32-embedded riscv64-linux riscv64-embedded xtensa-linux xtensa-embedded xtensa-freertos z80-embedded z80-zxspectrum z80-msxdos z80-amstradcpc
+MAKEFILETARGETS=i386-linux i386-go32v2 i386-win32 i386-os2 i386-freebsd i386-beos i386-haiku i386-netbsd i386-solaris i386-netware i386-openbsd i386-wdosx i386-darwin i386-emx i386-watcom i386-netwlibc i386-wince i386-embedded i386-symbian i386-nativent i386-iphonesim i386-android i386-aros m68k-linux m68k-netbsd m68k-amiga m68k-atari m68k-palmos m68k-macosclassic m68k-embedded m68k-sinclairql powerpc-linux powerpc-netbsd powerpc-amiga powerpc-macosclassic powerpc-darwin powerpc-morphos powerpc-embedded powerpc-wii powerpc-aix sparc-linux sparc-netbsd sparc-solaris sparc-embedded x86_64-linux x86_64-freebsd x86_64-haiku x86_64-netbsd x86_64-solaris x86_64-openbsd x86_64-darwin x86_64-win64 x86_64-embedded x86_64-iphonesim x86_64-android x86_64-aros x86_64-dragonfly arm-linux arm-netbsd arm-palmos arm-wince arm-gba arm-nds arm-embedded arm-symbian arm-android arm-aros arm-freertos arm-ios powerpc64-linux powerpc64-darwin powerpc64-embedded powerpc64-aix avr-embedded armeb-linux armeb-embedded mips-linux mipsel-linux mipsel-embedded mipsel-android mips64-linux mips64el-linux jvm-java jvm-android i8086-embedded i8086-msdos i8086-win16 aarch64-linux aarch64-freebsd aarch64-darwin aarch64-win64 aarch64-embedded aarch64-android aarch64-ios wasm32-embedded wasm32-wasi sparc64-linux riscv32-linux riscv32-embedded riscv32-freertos riscv64-linux riscv64-embedded xtensa-linux xtensa-embedded xtensa-freertos z80-embedded z80-zxspectrum z80-msxdos z80-amstradcpc
 BSDs = freebsd netbsd openbsd darwin dragonfly
 UNIXs = linux $(BSDs) solaris qnx haiku aix
 LIMIT83fs = go32v2 os2 emx watcom msdos win16 atari
@@ -499,9 +499,9 @@ endif
 endif
 ifeq ($(ARCH),riscv32)
 CPU_SPECIFIC_COMMON_UNITS=sysutils math classes fgl macpas typinfo types rtlconsts getopts lineinfo
-ifeq ($(SUBARCH),rv32imac)
-override FPCOPT+=-Cprv32imac
-CPU_UNITS=fe310g000 fe310g002 gd32vf103xx
+ifeq ($(SUBARCH),rv32imc)
+override FPCOPT+=-Cprv32imc
+CPU_UNITS=esp32c3 esp32c3idf_50000
 CPU_UNITS_DEFINED=1
 endif
 ifeq ($(CPU_UNITS_DEFINED),)
@@ -829,6 +829,9 @@ endif
 ifeq ($(FULL_TARGET),riscv32-embedded)
 override TARGET_UNITS+=$(SYSTEMUNIT) $(CPU_UNITS) uuchar objpas iso7185 extpas strings heapmgr consoleio sortbase $(CPU_SPECIFIC_COMMON_UNITS) dos ctypes charset cpall sysconst character
 endif
+ifeq ($(FULL_TARGET),riscv32-freertos)
+override TARGET_UNITS+=$(SYSTEMUNIT) $(CPU_UNITS) uuchar objpas iso7185 extpas strings heapmgr consoleio sortbase $(CPU_SPECIFIC_COMMON_UNITS) dos ctypes charset cpall sysconst character
+endif
 ifeq ($(FULL_TARGET),riscv64-linux)
 override TARGET_UNITS+=$(SYSTEMUNIT) $(CPU_UNITS) uuchar objpas iso7185 extpas strings heapmgr consoleio sortbase $(CPU_SPECIFIC_COMMON_UNITS) dos ctypes charset cpall sysconst character
 endif
@@ -1153,6 +1156,9 @@ endif
 ifeq ($(FULL_TARGET),riscv32-embedded)
 override TARGET_IMPLICITUNITS+=exeinfo cp1250 cp1251 cp1252 cp1253 cp1254 cp1255 cp1256 cp1257 cp1258 cp437 cp646 cp737 cp775 cp850 cp852 cp855 cp856 cp857 cp860 cp861 cp862 cp863 cp864 cp865 cp866 cp869 cp874 cp3021 cp8859_1 cp8859_2 cp8859_3 cp8859_4 cp8859_5 cp8859_6 cp8859_7 cp8859_8 cp8859_9 cp8859_10 cp8859_11 cp8859_13 cp8859_14 cp8859_15 cp8859_16 cpkoi8_r cpkoi8_u unicodedata
 endif
+ifeq ($(FULL_TARGET),riscv32-freertos)
+override TARGET_IMPLICITUNITS+=exeinfo cp1250 cp1251 cp1252 cp1253 cp1254 cp1255 cp1256 cp1257 cp1258 cp437 cp646 cp737 cp775 cp850 cp852 cp855 cp856 cp857 cp860 cp861 cp862 cp863 cp864 cp865 cp866 cp869 cp874 cp3021 cp8859_1 cp8859_2 cp8859_3 cp8859_4 cp8859_5 cp8859_6 cp8859_7 cp8859_8 cp8859_9 cp8859_10 cp8859_11 cp8859_13 cp8859_14 cp8859_15 cp8859_16 cpkoi8_r cpkoi8_u unicodedata
+endif
 ifeq ($(FULL_TARGET),riscv64-linux)
 override TARGET_IMPLICITUNITS+=exeinfo cp1250 cp1251 cp1252 cp1253 cp1254 cp1255 cp1256 cp1257 cp1258 cp437 cp646 cp737 cp775 cp850 cp852 cp855 cp856 cp857 cp860 cp861 cp862 cp863 cp864 cp865 cp866 cp869 cp874 cp3021 cp8859_1 cp8859_2 cp8859_3 cp8859_4 cp8859_5 cp8859_6 cp8859_7 cp8859_8 cp8859_9 cp8859_10 cp8859_11 cp8859_13 cp8859_14 cp8859_15 cp8859_16 cpkoi8_r cpkoi8_u unicodedata
 endif
@@ -1477,6 +1483,9 @@ endif
 ifeq ($(FULL_TARGET),riscv32-embedded)
 override TARGET_LOADERS+=$(LOADERS)
 endif
+ifeq ($(FULL_TARGET),riscv32-freertos)
+override TARGET_LOADERS+=$(LOADERS)
+endif
 ifeq ($(FULL_TARGET),riscv64-linux)
 override TARGET_LOADERS+=$(LOADERS)
 endif
@@ -1802,6 +1811,9 @@ endif
 ifeq ($(FULL_TARGET),riscv32-embedded)
 override COMPILER_INCLUDEDIR+=$(INC) $(PROCINC)
 endif
+ifeq ($(FULL_TARGET),riscv32-freertos)
+override COMPILER_INCLUDEDIR+=$(INC) $(PROCINC)
+endif
 ifeq ($(FULL_TARGET),riscv64-linux)
 override COMPILER_INCLUDEDIR+=$(INC) $(PROCINC)
 endif
@@ -2126,6 +2138,9 @@ endif
 ifeq ($(FULL_TARGET),riscv32-embedded)
 override COMPILER_SOURCEDIR+=$(INC) $(PROCINC) $(COMMON) $(ARCH)
 endif
+ifeq ($(FULL_TARGET),riscv32-freertos)
+override COMPILER_SOURCEDIR+=$(INC) $(PROCINC) $(COMMON) $(ARCH)
+endif
 ifeq ($(FULL_TARGET),riscv64-linux)
 override COMPILER_SOURCEDIR+=$(INC) $(PROCINC) $(COMMON) $(ARCH)
 endif

+ 3 - 4
rtl/freertos/Makefile.fpc

@@ -204,9 +204,9 @@ endif
 
 ifeq ($(ARCH),riscv32)
 CPU_SPECIFIC_COMMON_UNITS=sysutils math classes fgl macpas typinfo types rtlconsts getopts lineinfo
-ifeq ($(SUBARCH),rv32imac)
-override FPCOPT+=-Cprv32imac
-CPU_UNITS=fe310g000 fe310g002 gd32vf103xx
+ifeq ($(SUBARCH),rv32imc)
+override FPCOPT+=-Cprv32imc
+CPU_UNITS=esp32c3 esp32c3idf_50000
 CPU_UNITS_DEFINED=1
 endif
 ifeq ($(CPU_UNITS_DEFINED),)
@@ -223,7 +223,6 @@ $(error No CPUs enabled for given SUBARCH, pass either a SUBARCH or set CPU_UNIT
 endif
 endif
 
-
 ifeq ($(ARCH),xtensa)
 CPU_SPECIFIC_COMMON_UNITS=sysutils math classes fgl macpas typinfo types rtlconsts getopts lineinfo
 ifeq ($(SUBARCH),lx6)

+ 77 - 0
rtl/freertos/riscv32/esp32c3.pp

@@ -0,0 +1,77 @@
+{******************************************************************************
+Startup code for riscv32-esp32c3 using idf
+
+******************************************************************************}
+unit esp32;
+
+{$goto on}
+{$macro on}
+
+  interface
+
+  implementation
+
+    uses
+      consoleio,heapmgr;
+
+    var
+      _stack_top: record end; public name '_stack_top';
+      operatingsystem_result: longint; external name 'operatingsystem_result';
+
+    procedure PASCALMAIN; external name 'PASCALMAIN';
+
+    procedure esp_deep_sleep_start;external;
+    procedure putchar(c : char);external;
+    function getchar : char;external;
+    function __getreent : pointer;external;
+    procedure fflush(f : pointer);external;
+    procedure vTaskDelay(xTicksToDelay: uint32); external;
+
+    procedure flushOutput(var t : TextRec);
+      begin
+        fflush(ppointer(__getreent+8)^);
+      end;
+
+
+    procedure _FPC_haltproc; public name '_haltproc';noreturn;
+      begin
+        if operatingsystem_result <> 0 then
+          writeln('Runtime error ', operatingsystem_result);
+
+        writeln('_haltproc called, exit code: ',operatingsystem_result);
+        flushOutput(TextRec(Output));
+        repeat
+          // Allow other tasks to run
+          // Do not enter deep sleep, can lead to problems with flashing
+          vTaskDelay(1000);
+        until false;
+      end;
+
+
+    procedure app_main;public name 'app_main';noreturn;
+      begin
+        PASCALMAIN;
+        _FPC_haltproc;
+      end;
+
+
+    function WriteChar(ACh: char; AUserData: pointer): boolean;
+      begin
+        WriteChar:=true;
+        putchar(ACh);
+      end;
+
+
+    function ReadChar(var ACh: char; AUserData: pointer): boolean;
+      begin
+        ReadChar:=true;
+        ACh:=getchar;
+      end;
+
+begin
+  OpenIO(Input, @WriteChar, @ReadChar, fmInput, nil);
+  OpenIO(Output, @WriteChar, @ReadChar, fmOutput, nil);
+  OpenIO(ErrOutput, @WriteChar, @ReadChar, fmOutput, nil);
+  OpenIO(StdOut, @WriteChar, @ReadChar, fmOutput, nil);
+  OpenIO(StdErr, @WriteChar, @ReadChar, fmOutput, nil);
+end.

+ 52 - 0
rtl/freertos/riscv32/esp32c3idf_50000.pp

@@ -0,0 +1,52 @@
+{
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 2021 by Florian Klaempfl
+    member of the Free Pascal development team.
+
+    System unit for FreeRTOS systems
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************}
+unit espidf_40400;
+
+interface
+
+{$linklib soc,static}
+{$linklib driver,static}
+{$linklib freertos,static}
+{$linklib log,static}
+{$linklib esp_common,static}
+{$linklib heap,static}
+{$linklib newlib,static}
+{$linklib vfs,static}
+{$linklib esp_ringbuf,static}
+{$linklib spi_flash,static}
+{$linklib app_update,static}
+{$linklib xtensa,static}
+{$linklib bootloader_support,static}
+{$linklib pthread,static}
+{$linklib hal,static}
+{$linklib libm,static}
+{$linklib libg,static}
+{$linklib c,static}
+{$linklib esp_event,static}
+{$linklib esp_system, static}
+{$linklib esp_hw_support, static}
+{$linklib esp_rom, static}
+{$linklib esp_timer, static}
+{$linklib bootloader_support, static}
+{$linklib esp_pm, static}
+{$linklib driver, static}
+{$linklib esp_ipc, static}
+{$linklib xt_hal, static}
+{$linklib efuse, static}
+
+implementation
+
+end.