09202024

Last update2016/05/28 14:38

22.runtime library I/Oのリダイレクトについて

22.runtime library I/Oのリダイレクトについて

The C runtime library include many functions, including some that typically handle I/O. The I/O related runtime functions include printf(), fopen(), fclose(), and many others.

It is common to redirect the I/O from these functions to the actual embedded platform, such as redirecting printf() output to an LCD display or a serial cable, or to redirect file operations like fopen() and fclose() to some Flash file system middleware.

The free Lite version of TrueSTUDIO ® do not support I/O redirection, and instead have do-nothing stubs compiled into the C runtime library.

The professional versions of TrueSTUDIO ® do support I/O redirection. To enable I/O redirection the file "syscalls.c" should be included and built into the project:

  • Open TrueSTUDIO ® professional and load your project.
  • In the Project explorer, Right click on the project and select New->Other...
  • Expand System calls.
  • Select "Minimal System Calls Implementation" and click next.
  • Click Browse... and select the src folder as new file container and click OK.
  • Click on Finish and verify that "syscalls.c" is added to your project.

Example: Redirect "printf()" to your target output by modifying the "_write()" function in "syscalls.c":

21.新しいメモリー領域のなかにコードを入れる

21.新しいメモリー領域のなかにコードを入れる

In TrueSTUDIO® you could do it in the following way:

Modify the .ld-linker script file’s memory regions. Let us take a look at an example of a linker script file containing the following memory regions:

MEMORY
{
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 128K
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 16K
MEMORY_B1 (rx) : ORIGIN = 0x60000000, LENGTH = 0K
}

User may add a new area by editing the file. In this example we add the IP-Code region.

MEMORY
{
FLASH (rx)      : ORIGIN = 0x08000000, LENGTH = 64K
IP_CODE (x) : ORIGIN = 0x08010000, LENGTH = 64K
RAM (xrw)       : ORIGIN = 0x20000000, LENGTH = 8K
MEMORY_B1 (rx)  : ORIGIN = 0x60000000, LENGTH = 0K
}

A bit further downin the script, between the .data { ... } and the .bss { ... } section you can place the following:

.ip_code :
{
*(.IP_Code*);
} > IP_CODE

This tells the linker to place all sections named .IP_Code* into the IP_CODE memory region which we specified to start at target memory address: 0x8010000.

In your C-code, you need to tell the compiler which functions should go to this section by adding __attribute__((section(".IP_Code"))) before the function declaration. Example:

__attribute__((section(".IP_Code"))) int placed_logic()
{
/* TODO - Add your application code here */
return 1;
}

This way the placed_logic() function will be placed in the IP_CODE memory region by the linker.

20.target settingsのなかでターゲットを変更する

20.target settingsのなかでターゲットを変更する

The target settings dialog is reached by clicking the Build settings button in the C/C++ perspective of TrueSTUDIO (V.3.0 and newer)

Target settings

This dialog simply displays the settings that applies globally to the selected project. It is not the intention that user shall be able to change microcontroller or evaluation board in this dialog. It is possible to change these settings - but not recommended unless user is certain about that the microcontroller changed to is very similar to the microcontroller that this project was generated for. Build settings for the toolchains will be changed but no new libraries will be generated and thus changing to a microcontroller of another architecture will render the included run-time libraries useless. User is instead recommended to generate a new project for the second microcontroller!

It is possible to change the Code locations option, which will generate a new linker script into the project. To make this new linker script actually apply to the build process, the linker script must be pointed out to the linker. This is done by navigating to Tool settings > C Linker > General, here change the Linker script (*.ld) that is being used. Also user must do a clean build for the linker to actually consider this new linker script!

19.プロジェクトはrebuildしますか?

19.プロジェクトはrebuildしますか?

The build console outputs the following message even after a clean:

**** Internal Builder is used for build               ****

Nothing to build for MyProject

Each build configuration, for instance Debug and Release, creates a directory in the project for the build artifacts. Changing the build settings for these directories may prevent the build configuration from rebuilding. If this happens please delete the directory from the Project Explorer view and try building again.

18.コンパイラーにchecksumを作成させる

 18.コンパイラーにchecksumを作成させる

TrueSTUDIO® don't supply any checksum programs to create the checksum itself.
However, user could write their own checksum program, and then run it as a post-build step on the generated binary image.

This is how that is done in more detail:
•    Right-click on the project in the project explorer, and select Properties.
•    Expand the C/C++ Build node and select the Settings node.

Now activate a generation of a binary image at build time.
•    Select the Tool Settings tab to the right.
•    Expand the Other tool and select Output format
•    Choose to generate Binary.

If the application elf file was called myProgram.elf, the binary will be called myProgram.elf.binary.
This is the raw image that will be downloaded to the target and the one that user should calculate the checksum on.

To automatically calculate the checksum user can add the checksum program as a post-build step:
•    Choose the Build Steps tab to the right.
•    On the Command field for the Post-build steps user should add the written checksum program.

Building the program, when the build is done user will receive a binary file, and the checksum program will run and generate the checksum.

User should patch the generated binary image with the checksum to a known location that the program later will read.

As for how far to read when application is download in the microcontroller, user can use the &_edata marker as a stopping marker when calculating your checksum.