Forum > Embedded - ARM
STM32: Debug in SRAM, one FPC issue
(1/1)
Peacoor:
I am using FPC and Lazarus to do some STM32 programming. I found that the download speed in flash is slow, and the flash memory has a limited number of erase times, and I like running code with small changes.
So, I think running in the internal SRAM is better, with fast speed and unlimited read and write times.
In fpcupdeluxe (or build rtl by hand), add -dREMAP_VECTTAB to build options, this will enable some code in cortexm0_start.inc, cortexm3_start.inc and cortexm4_startf.inc which allow interrupts.
Switch the platform in Lazarus, and add -WpSTM32XX (which use) and -sT to compiler options, build and it would generate xxx_link.res and xxx_ppas.sh on the project directory, open the xxx_link.res, replace the code (depending on the chip, the LENGTH is different):
--- Code: ---MEMORY
{
flash : ORIGIN = 0x08000000, LENGTH = 0x00100000
ram : ORIGIN = 0x20000000, LENGTH = 0x00020000
}
--- End code ---
with
--- Code: ---MEMORY
{
flash : ORIGIN = 0x20000000, LENGTH = 0x00010000
ram : ORIGIN = 0x20010000, LENGTH = 0x00010000
}
--- End code ---
Note the SRAM size your chip has, My STM32F407ZG has 128KB SRAM from 0x20000000 to 0x2001FFFF.
Run the xxx_ppas.sh, use arm-none-eabi-gdb to load the elf, and can debug in command line (download is really fast).
I want to debug in Lazarus not the terminal, I don't know how to pass some parameters to let FPC set the flash and ram as I need. Or use -k to pass some parameters to gnu ld (I tried some, but failed), or it is impossible for the current version(trunk)? Maybe can make a feature request?
Does anyone know it?
Laksen:
I'm guessing that the only change would be to supply the new linker script to ld
To do that you can add
--- Code: ----k-Tlink.res
--- End code ---
in the projects settings custom options. link.res being your modified linker script
Peacoor:
--- Quote from: Laksen on August 02, 2023, 08:31:54 pm ---I'm guessing that the only change would be to supply the new linker script to ld
To do that you can add
--- Code: ----k-Tlink.res
--- End code ---
in the projects settings custom options. link.res being your modified linker script
--- End quote ---
Thanks for the reply, however, it's a pity that the compiler ignore the link.res.
Peacoor:
I found the code in compiler/systems/t_embed.pas
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- begin with embedded_controllers[current_settings.controllertype] do with linkres do begin if (embedded_controllers[current_settings.controllertype].controllerunitstr='MK20D5') or (embedded_controllers[current_settings.controllertype].controllerunitstr='MK20D7') or (embedded_controllers[current_settings.controllertype].controllerunitstr='MK22F51212') or (embedded_controllers[current_settings.controllertype].controllerunitstr='MK64F12') then Add('ENTRY(_LOWLEVELSTART)') else Add('ENTRY(_START)'); Add('MEMORY'); Add('{'); if flashsize<>0 then begin LinkStr := ' flash : ORIGIN = 0x' + IntToHex(flashbase,8) + ', LENGTH = 0x' + IntToHex(flashsize,8); Add(LinkStr); end; LinkStr := ' ram : ORIGIN = 0x' + IntToHex(srambase,8) + ', LENGTH = 0x' + IntToHex(sramsize,8); Add(LinkStr); Add('}'); Add('_stack_top = 0x' + IntToHex(sramsize+srambase,8) + ';'); // Add Checksum Calculation for LPC Controllers so that the bootloader starts the uploaded binary writeln(controllerunitstr); if (controllerunitstr = 'LPC8xx') or (controllerunitstr = 'LPC11XX') or (controllerunitstr = 'LPC122X') then Add('Startup_Checksum = 0 - (_stack_top + _START + 1 + NonMaskableInt_interrupt + 1 + Hardfault_interrupt + 1);'); if (controllerunitstr = 'LPC13XX') then Add('Startup_Checksum = 0 - (_stack_top + _START + 1 + NonMaskableInt_interrupt + 1 + MemoryManagement_interrupt + 1 + BusFault_interrupt + 1 + UsageFault_interrupt + 1);'); end; end
The flash and ram information were hardcoded in embedded_controllers of cpuinfo.pas, unless change the compiler, or cannot specify flash and ram.
I'm curious if adding a compiler option to specify the flash and ram of the MCU is feasible.
Navigation
[0] Message Index