To add setup file (txt) to hex file during uC programmation

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Giancarlo
Level 1
Level 1
First solution authored First reply posted First question asked

Good morning everyone,

I develop on PSOC 4 uC (4200 M series) and I need to set some parameters that my customer asks me. As I produce many devices (with uC) I prefer to have the firmware separated from the setup but at the same time I need to program in one time otherwise the production is very expensive.

Is there anyone who knows how to do this?

A thousand thanks

Giancarlo 

0 Likes
1 Solution
Giancarlo
Level 1
Level 1
First solution authored First reply posted First question asked

Hi all and thanks for the important replies.
I do the solution like this: from the help section in "PSoC Programmer" I found the very interesting document called: "PSoC Programmer COM User Guide.pdf" which explains and publishes very well how to program, in c# (I use Visual Studio 2019) in Windows Forms, the application to program my device based on PSoc4 (PSoC4 because it's my device but there are other devices). Then I build my application on the programming device with very few code changes. After programming, via API:
"hr = ProgramFlash(hexImageSize);
if (!SUCCEEDED(hr)) return hr;" ) "
and first the security command via API:
" hr = pp.PSoC4_ProtectAll(out m_sLastError);
if (!SUCCEEDED(hr)) return hr;"
I write emulated EEProm in allotted place by compiling my project in "Creator" via API:
int row id = 113;
" byte[] dataEEpromToStoreAsRow = new byte[128];
for (int i = 0; i < dataEEpromToStoreAsRow.Length; i++)
{
if (i == 64) dataEEpromToStoreAsRow[i] = (byte)GlobalVariable.SpeedSelected;
else if (i == 66) dataEEpromToStoreAsRow[i] = (byte)(SetupSelected + 1);
}
hr = pp.PSoC4_ProgramRow(rowID, dataEEpromToStoreAsRow, out strError);"

The API writes "Row" where the size is 128 bytes.
To know the address where the compiler/linker has placed the Emulate EEProm, open the file: "project_name.map" ("Results" in the Creator environment tab) which contains the address of each object of our project.
In the "main.c file" I declare that area on eprom emulation and it is called "Em_EEPROM_em_EepromStorage". Now, in the MAP file look for "Em_EEPROM_em_EepromStorage" and the result is:
.rodata 0x00003880 0x80 .\CortexM0\ARM_GCC_541\Debug\main.o
0x00003880 Em_EEPROM_em_EepromStorage.

So, 0x00003880 is for my project the position where Emulated EEProm starts.
Warning, this location can change if the code (or the project) is changed. It is possible to define the Fixed Address: to do this, refer to the EEPROM datasheet in the section: "Fixed Address EEPROM Memory Placement".
Note that the "PSoC4_ProgramRow(rowID, dataEEpromToStoreAsRow, out strError)" API requires the row number and not the address:
To do this look for "#define CY_FLASH_SIZEOF_ROW (CYDEV_FLS_ROW_SIZE)" in "CyFlash.h" which defines the row size. To know the numeric size lookup: "CYDEV_FLS_ROW_SIZE" in "cydevice_trm.h" found #define CYDEV_FLS_ROW_SIZE 0x00000080u.
The size is 0x80h for each line.
Now to know which row number I have to pass to row calculation API like this: 0x00003880 / 0x80 = 0x71. Since the API requires Row in decimal format, I pass 0x71H in decimal = 113.

I hope my experience is useful to someone.
Thanks for your support and opinions

View solution in original post

0 Likes
15 Replies
LeoMathews
Moderator
Moderator
Moderator
First question asked 500 replies posted 100 solutions authored

Hi @Giancarlo 

Please note that editing the .hex file will create a discrepancy in the checksum area. You can modify the data in the hex, but you need to take care of two things. Every row in the hex file follows the Intel Hex Format. Firstly each of the rows has a checksum calculated at the end of the record. You need to modify this as well to align with the changes you made. Secondly, we calculate the checksum of the entire flash and store it in the location 0x90300000 in the hex. So, you will need to modify this as well to align with the changes and also the checksum of the checksum. 

But, the metadata section at 0x90500000 contains some proprietary information that is used to guarantee the integrity of the hex file. Hence, you will not be able to program the hex file even though we modify the checksums.

Thanks and Regards,
Leo

0 Likes

@LeoMathews ,

Is it possible to create two hex files?

One that has the bulk of the application and the other that programs the customer specific data in a specified location in FLASH?

The PSoC would be first erased and the application loaded with the security settings as needed.

The PSoC would then load the customer data selectively to unsecured FLASH.

Can this be done with the Infineon PSoC Programmer tool or would @Giancarlo  have to create a special tool?

Len
"Engineering is an Art. The Art of Compromise."
0 Likes

Hi @Len_CONSULTRON 

Can you please clarify the part about loading the customer data to unsecured FLASH again? I believe using 2 hex files will cause the failure of the checksum verification part. 

Thanks and Regards,
Leo

0 Likes

@LeoMathews ,

In theory, since the project can use emulated EEPROM using FLASH memory and change it at any time, the proprietary metadata section is not involved. 

The question to you: Can the PsoC programmer be given a second hex file where just the contents of emulated EEPROM area are loaded and the entire FLASH is NOT erased first?

Len
"Engineering is an Art. The Art of Compromise."
0 Likes

Hi @Len_CONSULTRON 

I believe, to load the emulated EEPROM area, the silicon has to be in OPEN mode. Therefore, this step must be executed at some point after the Erase All step, which guarantees that the part is in OPEN mode.

Please refer to the PSoC4 Programming Specification document, section 4.13 which explains the programming of user SFlash which can be used to emulate EEPROM memory.

Thanks and Regards,
Leo

 

0 Likes

Hi Leo,

I found, in the Cypress documentation, the: "PSoC Programmer COM User Guide" which helps to develop programming in Visual Studio in C# through special forms and buttons. I've done this and it works very well: I select my base HEX file and program the uC. The programming document explains how to use all the features that the environment offers and how to operate on the programming. There are also functions to write and read EEPROM but when I use them I get the error: "Eeprom record not supported in PSoC4 hex-file". I don't understand why this error occurs, I haven't found any help about this error, on the internet.

so, I don't know how to program in a specific address in EEPROM EMULATED by firmware (generated by compiler) so that after programming the specific address contains my desired value

thanks

0 Likes

Hello.

You get the EEPROM error msg when using COM because it is referring to real EEPROM memory.  PSoC4 M does not have real EEPROM memory.  Instead, use the FLASH read/write row commands such as PSoC3_ProgramRow() or PSoC3_ProgramRowFromHex() for programming.

There are several discussions on how to write to specific FLASH memory locations.
Solved: PSoC4 Em_EEPROM 2.0 Fixed Address - Infineon Developer Community

Code example CE195313:
PSoC™ 4 Code Examples for PSoC™ Creator - Infineon Technologies

You could also use ppcli to program both the project and the customer specific bytes, all in 1 script.  ppcli invokes PSoC Programmer to do the actual programming.  So, there's no software to develop.  This can be done easily when no bootloader is used since there is no Metadata data stored in the target PSoC FLASH.  If there is a bootloader, then additional flags must be set in the bootloader/bootloadable components to Exclude Checksum, or Fast boot (see KBA89149).

0 Likes
Giancarlo
Level 1
Level 1
First solution authored First reply posted First question asked

First, thanks for the help.

I try to ask the question in another way.
Since during the production phases I need to memorize some customer data, which I call PARAMETERS, I write them in some locations in emulated EEprom. Is it possible, for example, using PSoC Programmer, to write such parameters directly during the moment of uC programming?

Thank you

0 Likes

Would it be possible to create the base hex image without the parameters, load the parameters after this initial programming into the Emulated EEPROM, then perform a read of the Flash using PSoC programmer to save a new hex image that includes the loaded parameters that you could then use for programming in production?

I'm not sure if the "Read To Hex" option in PSoC Programmer will save the Emulated EEPROM section (it's part of flash right?  so I'd think it should?).  Might be worth testing out to see if it does.

 

@Giancarlo ,

You could have a separate .c file with the parameters (let's call it parameters.c).   You could then modify the parameters in it as needed.  Then you would recompile the project and it would create a single specific .hex file for loading.

If the PSoC Creator had a CLI interface, it could compile and program the part with a "simple" batch file method.

Len
"Engineering is an Art. The Art of Compromise."
0 Likes

Hi Len.

Creator has a cli interface.  I've never used it, but it's there.
CyPrjMgr Command Line Tool (in Creator user guide).

Of interest for @Giancarlo, would be the CyElfTool Command Line Tool, which combines files and updates/corrects the Metadata fields.  CyHexTool Command Line Tool does the same thing, but not for PSoC4 devices.

@Giancarlo ,

First off in my suggestion, when you are building a project, there are CLI commands being executed.  It is seen in the "Output" window with the exact CLI commands and arguments being used.

Therefore if you modify the parameters.c file and rebuild the project, you get a new .hex file with the changes and you can use the CLI command to program the device.

However @BiBi_1928986 is on to something.  I haven't worked with the CyElfTool directly and there might be a way to combine the two areas of FLASH (application and parameters) to create a new .hex file to load into the PSoC.   It's worth a look.

Len
"Engineering is an Art. The Art of Compromise."
0 Likes

@Giancarlo 

If this is of any help:  I found this section in the "PSoC Creator User Guide" document about a merge feature in the CyElfTool.

Len_CONSULTRON_0-1676378878333.png

If this works, the issue is creating a .elf file of the parameter set you want to merge.

Len
"Engineering is an Art. The Art of Compromise."
0 Likes
Giancarlo
Level 1
Level 1
First solution authored First reply posted First question asked

Hi all and thanks for the important replies.
I do the solution like this: from the help section in "PSoC Programmer" I found the very interesting document called: "PSoC Programmer COM User Guide.pdf" which explains and publishes very well how to program, in c# (I use Visual Studio 2019) in Windows Forms, the application to program my device based on PSoc4 (PSoC4 because it's my device but there are other devices). Then I build my application on the programming device with very few code changes. After programming, via API:
"hr = ProgramFlash(hexImageSize);
if (!SUCCEEDED(hr)) return hr;" ) "
and first the security command via API:
" hr = pp.PSoC4_ProtectAll(out m_sLastError);
if (!SUCCEEDED(hr)) return hr;"
I write emulated EEProm in allotted place by compiling my project in "Creator" via API:
int row id = 113;
" byte[] dataEEpromToStoreAsRow = new byte[128];
for (int i = 0; i < dataEEpromToStoreAsRow.Length; i++)
{
if (i == 64) dataEEpromToStoreAsRow[i] = (byte)GlobalVariable.SpeedSelected;
else if (i == 66) dataEEpromToStoreAsRow[i] = (byte)(SetupSelected + 1);
}
hr = pp.PSoC4_ProgramRow(rowID, dataEEpromToStoreAsRow, out strError);"

The API writes "Row" where the size is 128 bytes.
To know the address where the compiler/linker has placed the Emulate EEProm, open the file: "project_name.map" ("Results" in the Creator environment tab) which contains the address of each object of our project.
In the "main.c file" I declare that area on eprom emulation and it is called "Em_EEPROM_em_EepromStorage". Now, in the MAP file look for "Em_EEPROM_em_EepromStorage" and the result is:
.rodata 0x00003880 0x80 .\CortexM0\ARM_GCC_541\Debug\main.o
0x00003880 Em_EEPROM_em_EepromStorage.

So, 0x00003880 is for my project the position where Emulated EEProm starts.
Warning, this location can change if the code (or the project) is changed. It is possible to define the Fixed Address: to do this, refer to the EEPROM datasheet in the section: "Fixed Address EEPROM Memory Placement".
Note that the "PSoC4_ProgramRow(rowID, dataEEpromToStoreAsRow, out strError)" API requires the row number and not the address:
To do this look for "#define CY_FLASH_SIZEOF_ROW (CYDEV_FLS_ROW_SIZE)" in "CyFlash.h" which defines the row size. To know the numeric size lookup: "CYDEV_FLS_ROW_SIZE" in "cydevice_trm.h" found #define CYDEV_FLS_ROW_SIZE 0x00000080u.
The size is 0x80h for each line.
Now to know which row number I have to pass to row calculation API like this: 0x00003880 / 0x80 = 0x71. Since the API requires Row in decimal format, I pass 0x71H in decimal = 113.

I hope my experience is useful to someone.
Thanks for your support and opinions

0 Likes
LeoMathews
Moderator
Moderator
Moderator
First question asked 500 replies posted 100 solutions authored

Hi @Giancarlo 

Thread was locked due to inactivity for long time, you can continue the discussion on the topic by opening a new thread with reference to the locked one. The continuous discussion in an inactive thread may mostly be unattended by community users.

Thanks and Regards,
Leo

0 Likes