瀏覽代碼

Extend riscv32-freertos functionality for esp32c3

ccrause 1 年之前
父節點
當前提交
c42bf9cdf5
共有 4 個文件被更改,包括 78 次插入18 次删除
  1. 21 12
      compiler/options.pas
  2. 7 0
      compiler/pmodules.pas
  3. 47 3
      compiler/systems/t_freertos.pas
  4. 3 3
      rtl/freertos/riscv32/esp32c3idf_50000.pp

+ 21 - 12
compiler/options.pas

@@ -125,7 +125,7 @@ Type
     processorstr: TCmdStr;
     function ParseMacVersionMin(out minversion, invalidateversion: tversion; const compvarname, value: string; ios: boolean): boolean;
     procedure MaybeSetDefaultMacVersionMacro;
-{$ifdef XTENSA}
+{$if defined(XTENSA) or defined(RISCV32)}
     function ParseVersionStr(out ver: longint; const compvarname, value: string): boolean;
     procedure MaybeSetIdfVersionMacro;
 {$endif}
@@ -1293,7 +1293,7 @@ function TOption.ParseMacVersionMin(out minversion,
     result:=true;
   end;
 
-{$ifdef XTENSA}
+{$if defined(XTENSA) or defined(RISCV32)}
 function TOption.ParseVersionStr(out ver: longint;
   const compvarname, value: string): boolean;
 
@@ -1372,7 +1372,7 @@ function TOption.ParseVersionStr(out ver: longint;
         result:=true;
       end;
 end;
-{$endif XTENSA}
+{$endif XTENSA or RISCV32}
 
 procedure TOption.MaybeSetDefaultMacVersionMacro;
 var
@@ -1495,15 +1495,16 @@ begin
 end;
 {$endif AVR}
 
-{$ifdef XTENSA}
+{$if defined(XTENSA) or defined(RISCV32)}
 procedure TOption.MaybeSetIdfVersionMacro;
 begin
-  if not(target_info.system=system_xtensa_freertos) then
+  if not(target_info.system in [system_xtensa_freertos,system_riscv32_freertos]) then
     exit;
   if IdfVersionSet then
     exit;
   { nothing specified -> defaults }
   case current_settings.controllertype of
+{$ifdef XTENSA}
     ct_esp8266:
       begin
         set_system_compvar('IDF_VERSION','30300');
@@ -1514,6 +1515,14 @@ begin
         set_system_compvar('IDF_VERSION','40200');
         idf_version:=40200;
       end;
+{$endif}
+{$ifdef RISCV32}
+    ct_esp32c3:
+      begin
+        set_system_compvar('IDF_VERSION','40400');
+        idf_version:=40400;
+      end;
+{$endif RISCV32}
     else
       begin
         set_system_compvar('IDF_VERSION','00000');
@@ -1521,7 +1530,7 @@ begin
       end;
   end;
 end;
-{$endif XTENSA}
+{$endif XTENSA or RISCV32}
 
 procedure TOption.VerifyTargetProcessor;
   begin
@@ -3027,7 +3036,7 @@ begin
           else
             frameworksearchpath.AddPath(More,true)
 {$if defined(XTENSA) or defined(RISCV32)}
-        else if (target_info.system=system_xtensa_freertos) then
+        else if (target_info.system in [system_xtensa_freertos,system_riscv32_freertos]) then
           idfpath:=FixPath(More,true)
 {$endif defined(XTENSA) or defined(RISCV32)}
         else
@@ -4034,13 +4043,13 @@ begin
              begin
                break;
              end
-{$ifdef XTENSA}
-           else if (target_info.system in [system_xtensa_freertos]) and
+{$if defined(XTENSA) or defined(RISCV32)}
+           else if (target_info.system in [system_xtensa_freertos,system_riscv32_freertos]) and
               ParseVersionStr(idf_version,'IDF_VERSION',copy(More,2)) then
              begin
                break;
              end
-{$endif XTENSA}
+{$endif XTENSA or RISCV32}
            else
              IllegalPara(opt);
          end;
@@ -5238,10 +5247,10 @@ begin
   { set Mac OS X version default macros if not specified explicitly }
   option.MaybeSetDefaultMacVersionMacro;
 
-{$ifdef XTENSA}
+{$if defined(XTENSA) or defined(RISCV32)}
   { set ESP32 or ESP8266 default SDK versions }
   option.MaybeSetIdfVersionMacro;
-{$endif XTENSA}
+{$endif defined(XTENSA) or defined(RISCV32)}
 
 {$ifdef cpufpemu}
   { force fpu emulation on arm/wince, arm/gba, arm/embedded and arm/nds etc.

+ 7 - 0
compiler/pmodules.pas

@@ -520,6 +520,13 @@ implementation
               else
                 Comment(V_Warning, 'Unsupported esp-rtos version');
             end;
+{$endif XTENSA}
+{$ifdef RISCV32}
+        if not(curr.is_unit) and (target_info.system=system_riscv32_freertos) then
+          if (current_settings.controllertype=ct_esp32c3) then
+            begin
+              CheckAddUnit('esp32c3idf_50000')
+            end;
 {$endif XTENSA}
       end;
 

+ 47 - 3
compiler/systems/t_freertos.pas

@@ -1446,7 +1446,7 @@ begin
       if idf_version>=40400 then
         cmdstr:=cmdstr+'-I $IDF_PATH/components/esp_system/ld $IDF_PATH/components/esp_system/ld/esp32c3/memory.ld.in'
       else
-        cmdstr:=cmdstr+'$IDF_PATH/components/esp32/ld/esp32c3.ld';
+        cmdstr:=cmdstr+'$IDF_PATH/components/esp32c3/ld/esp32c3.ld';
     end;
   Replace(cmdstr,'$IDF_PATH',idfpath);
   Replace(cmdstr,'$OUTPUT',outputexedir);
@@ -1507,10 +1507,10 @@ var
   DynLinkStr,
   StripStr,
   FixedExeFileName: string;
-{$ifdef XTENSA}
+  {$if defined(XTENSA) or defined(RISCV32)}
   memory_script,
   sections_script: AnsiString;
- {$endif XTENSA}
+  {$endif defined(XTENSA) or defined(RISCV32)}
 begin
 {$if defined(XTENSA) or defined(RISCV32)}
   { idfpath can be set by -Ff, else default to environment value of IDF_PATH }
@@ -1582,6 +1582,50 @@ begin
   Replace(Info.ExeCmd[1],'$IDF_PATH',idfpath);
 {$endif XTENSA}
 
+{$ifdef RISCV32}
+  { Locate linker scripts.  If not found, generate defaults. }
+  { Cater for different script names in different esp-idf versions }
+
+  if (current_settings.controllertype = ct_esp32c3) then
+    begin
+      if idf_version >= 40400 then
+        begin
+          memory_script := 'memory.ld';
+          sections_script := 'sections.ld';
+        end
+      else
+      begin
+        memory_script := 'esp32c3_out.ld';
+        sections_script := 'esp32c3.project.ld';
+      end;
+    end;
+
+  if not (FindLibraryFile(memory_script,'','',memory_script) and
+         FindLibraryFile(sections_script,'','',sections_script)) then
+    GenerateDefaultLinkerScripts(memory_script,sections_script);
+
+  if (current_settings.controllertype = ct_esp32c3) then
+    begin
+      Info.ExeCmd[1]:=Info.ExeCmd[1]+' -u call_user_start_cpu0 -u ld_include_panic_highint_hdl -u esp_app_desc -u vfs_include_syscalls_impl -u pthread_include_pthread_impl -u pthread_include_pthread_cond_impl -u pthread_include_pthread_local_storage_impl -u newlib_include_locks_impl '+
+       '-u newlib_include_heap_impl -u newlib_include_syscalls_impl -u newlib_include_pthread_impl -u app_main -u uxTopUsedPriority '+
+       '-L $IDF_PATH/components/esp_rom/esp32c3/ld '+
+       '-T esp32c3.rom.ld -T esp32c3.rom.libgcc.ld '+
+//       '-T esp32c3.rom.ld -T esp32c3.rom.libgcc.ld -T esp32c3.rom.newlib-data.ld -T esp32c3.rom.syscalls.ld -T esp32c3.rom.newlib-funcs.ld '+
+       '-T '+memory_script+' -T '+sections_script;
+
+      if idf_version<40400 then
+        Info.ExeCmd[1]:=Info.ExeCmd[1]+' -L $IDF_PATH/components/esp32c3/ld -T esp32c3.peripherals.ld'
+      else
+        Info.ExeCmd[1]:=Info.ExeCmd[1]+' -L $IDF_PATH/components/soc/esp32c3/ld -T esp32c3.peripherals.ld';
+      if idf_version>=40300 then
+        Info.ExeCmd[1]:=Info.ExeCmd[1]+' -T esp32c3.rom.api.ld';
+      if idf_version>=40400 then
+        Info.ExeCmd[1]:=Info.ExeCmd[1]+' -T esp32c3.rom.newlib-time.ld';
+    end;
+
+  Replace(Info.ExeCmd[1],'$IDF_PATH',idfpath);
+{$endif RISCV32}
+
   FixedExeFileName:=maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.elf')));
 
   GCSectionsStr:='--gc-sections';

+ 3 - 3
rtl/freertos/riscv32/esp32c3idf_50000.pp

@@ -28,7 +28,7 @@ interface
 {$linklib efuse.a,static}
 {$linklib esp_adc.a,static}
 {$linklib esp_app_format.a,static}
-{$linklib esp_coex.a,static}
+//{$linklib esp_coex.a,static} v5.1
 {$linklib esp_common.a,static}
 {$linklib espcoredump.a,static}
 {$linklib esp_eth.a,static}
@@ -41,7 +41,7 @@ interface
 {$linklib esp_hw_support.a,static}
 {$linklib esp_lcd.a,static}
 {$linklib esp_local_ctrl.a,static}
-{$linklib esp_mm.a,static}
+//{$linklib esp_mm.a,static}  v5.1
 {$linklib esp_netif.a,static}
 {$linklib espnow.a,static}
 {$linklib esp_partition.a,static}
@@ -61,7 +61,7 @@ interface
 {$linklib json.a,static}
 {$linklib log.a,static}
 {$linklib lwip.a,static}
-{$linklib main.a,static}
+//{$linklib main.a,static}
 {$linklib mbedcrypto.a,static}
 {$linklib mbedtls.a,static}
 {$linklib mbedx509.a,static}