How to program a PSoC 4 via the command line

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

cross mob
lock attach
Attachments are accessible only for community members.
mari_3596111
Level 1
Level 1

I have a PSoC 4 and a PSoC 5 and am able to run programs on both boards via PSoC Creator 4.3, however I need to do this via a batch file and can successfully do this for the CY8CKIT-059 but not for the CY8CKIT-043. In both cases I create a script and when I run this script using ppcli.exe, I don't get any errors.

I can then execute using gdb and all works as expected for the CY8CKIT-059, but not with the CY8CKIT-043. If I flash the  CY8CKIT-043 via the PSoC Creator, then my program runs using gdb.

I have attached part of my batch file, that show how I am creating the scripts for both boards.

Any idea what I am doing wrong?

Thanks in advance.

Mark

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.
Rakshith
Moderator
Moderator
Moderator
250 likes received 1000 replies posted 750 replies posted

Hi mari_3596111,

Adding my response on the thread too:

As your project does not have the code in a loop the main() function gets executed as soon as you start the gdb session and thus the debug pointer is stuck at the while(1) condition in Cm0Start.c file after executing the main() code.

Two methods can be used as a workaround and I have provided the snapshot and commands used:

Method 1 -

1. Declare a volatile variable in main.c, for example - volatile uint8_t stop_var = 0x00;

2. Add a while loop before the execution of your application code - while(stop_var==0x00); before ldra_port_open();

3. Add a break point at the while(stop_var==0x00). Use the step command to stop the execution at that point.

4. Change the variable value of stop_var to 0x01 using command set variable stop_var = 0x01

5. Step through the code.

I have attached the project archive. A snapshot of gdb commands is shown below -

pastedImage_3.png

Method 2 -

1. This is very similar to the previous method.

2. Declare a volatile variable in main.c, for example - volatile uint8_t stop_var = 0x00;

3. Add a while loop at the end of your application code - while(stop_var==0x00);

4. Add a breakpoint at the while(stop_var==0x00). Use the step command to stop the execution at that point.

5. Add a breakpoint at main using the command b *main and then jump to main using jump main command.

6. Step through the code.

I have attached the project archive and snapshot of gdb commands is shown below.

pastedImage_4.png

Thanks and Regards,

Rakshith M B

Thanks and Regards,
Rakshith M B

View solution in original post

0 Likes
18 Replies
Rakshith
Moderator
Moderator
Moderator
250 likes received 1000 replies posted 750 replies posted

Hi mari_3596111​,

Can you please let me know at which point the script fails? What is the error that you are getting?

when I run this script using ppcli.exe, I don't get any errors.

If that is the case then the script is generated properly. Is it possible for you to attach the entire bat script and the scripts that get created so that we can try and debug the issue?

Thanks and Regards,

Rakshith M B

Thanks and Regards,
Rakshith M B
0 Likes
lock attach
Attachments are accessible only for community members.

Hi,

Here are the two scripts that I am using along with the simple program that I am trying to flash. Once again all works for the PSoC 5 but not for the PSoC4

Regards,

Mark

0 Likes
lock attach
Attachments are accessible only for community members.

Hi mari_3596111​,

I used the script that you gave and tried programming and it worked. Later I modified that batch script that you had shared and hardcoded all the variables accordingly and then tried programming the device.

I was able to program the device. As I did not know what your hex file contained I created a blinky project and used that hex file instead. I have attached the edited .bat script, .cli file that was generated by the batch script and the hex file that I used to program the device.

Please try it at your end and let me know if you are able to program the device.

Thanks and Regards,

Rakshith M B

Thanks and Regards,
Rakshith M B
0 Likes
lock attach
Attachments are accessible only for community members.

Hi,

It seems like the programming is working, but the execution from a batch file using gdb is not working for the PSoC 4. It only works if I have just debugged via PSoC Creator and if I don’t reprogram via my batch file. With the PSoC 5 it always works.

Using gdb, if I try to single step, then unless I have just debugged via the PSoC Creator, it just hangs.

This is the part of my gdb script, where I try to establish connection with the target and where possibly some extra monitor command is required?

set remotetimeout 5

target remote | "C:/PROGRA2/Cypress/PSOCCR1/4.3/PSOCCR~1/bin/cypsocdebugger.exe" -t PPIO:KitProg/11160FEB02105400:1

monitor reset

Any idea why this is working for the PSoC5 but not for the PSoC4?

Regards,

Mark

0 Likes

Hi mari_3596111​,

I apologize for the delay.

I was able to run the gdb session on the CY8CKIT-043 and on the CY8CKIT-059 with the same commands. This is a screenshot of the debugging session on the CY8CKIT-043 -

pastedImage_0.png

Commands -

set remotetimeout 5

target remote | C:/Program\ Files\ (x86)/Cypress/PSoC\ Creator/4.3/PSoC\ Creator/bin/cypsocdebugger.exe -t PPIO:KitProg/1A06163201324400:1

monitor reset

I noticed that you have ~ sign in your path. Can you rename the folder so that it does not have any special characters? Can you confirm your path again?

Also, please share the error that you are getting. I am not able to access the image that you have attached.

Thanks and Regards,

Rakshith M B

Thanks and Regards,
Rakshith M B
0 Likes
lock attach
Attachments are accessible only for community members.

Hi,

First of all thanks again for trying this and replying, it is greatly appreciated. The ~ was in the path, since I tried to use the windows short path in case that made a difference. With the PSoC4, I get the gdb command, but when I type s to single step, it just hangs, where as with the PSoC5 it advances to the next line of code.

It is very frustrating since all works fine for the PSoC5, but not for the PSoC4.

Regards,

Mark

0 Likes

Hi mari_3596111​,

Can you confirm that you have loaded the right elf file?

I was able to debug the target using gdb as shown in the snapshot -

pastedImage_0.png

I just added the file "<path to elf file>" command along with the previous commands. Please let me know if this works for you.

Thanks and Regards,

Rakshith M B

Thanks and Regards,
Rakshith M B
0 Likes
lock attach
Attachments are accessible only for community members.

Hi,

Yes, I have loaded the correct program, but no matter what I do, whenever I try to step through the program, it just hangs ex:

Regards,

Mark

0 Likes
lock attach
Attachments are accessible only for community members.

Hi mari_3596111,

Can you please share the .hex and .elf that you have used? I will give it a try from my end and check if I can reproduce the same issue. Meanwhile, can you please try with the .hex and .elf file that I have attached.

We received an update from our internal team that even though monitor reset is a valid gdb command it is not supported by the cypsocdebugger. Can you please remove the command and let me know if it works?

Thanks and Regards,

Rakshith M B

Thanks and Regards,
Rakshith M B
0 Likes
lock attach
Attachments are accessible only for community members.

With your project, I can single step with gdb, but with the attached it just hangs. However I can debug in PSoC Creator.

I removed the Monitor reset command, but that didn’t make any difference.

My program does not configure any components, could that be an issue?

Once again, everything works for the PSoC5, but not for the PSoC4

Regards,

Mark

0 Likes

Hi mari_3596111,

I was able to reproduce this issue with the files that you have shared. The debugging process is running. But gdb is unable to find the Cm0Start.c file -

pastedImage_0.png

Can you try including the directory and let me know if that helps?

My program does not configure any components, could that be an issue?

Can you please let me know what you mean by this? Are you not using any of the components?

As this is a project-specific issue can you please attach your project so that it will help in debugging this issue?

Thanks and Regards,

Rakshith M B

Thanks and Regards,
Rakshith M B
0 Likes
lock attach
Attachments are accessible only for community members.

Hi,

This is my project.

Regards,

Mark

0 Likes

Hi mari_3596111,

I found that in your main.c file you have included these files -

pastedImage_0.png

But these files were not included in in the PSoC Creator project explorer. So, I added the files into project explorer as shown -

pastedImage_1.png

I am unable to build the project as there are errors in the code -

pastedImage_3.png

Can you please share your complete project again?

Thanks and Regards,

Rakshith M B

Thanks and Regards,
Rakshith M B
0 Likes
lock attach
Attachments are accessible only for community members.

Hi,

Here is the latest version of my project.

Regards,

Mark

0 Likes

Hi mari_3596111​,

The files ldra_port.h, ldra_port_common.h, ldra_port.c, ldra_port_common.c are still not included into the project.

Can you please right-click on the Header Files/Source Files folder and add the files into the Workspace Explorer of PSoC Creator as shown -

pastedImage_0.png

Meanwhile, I have shared your project with our internal team and they are looking into this issue. I will respond on this thread as soon as I get an update.

Thanks and Regards,

Rakshith M B

Thanks and Regards,
Rakshith M B
0 Likes
lock attach
Attachments are accessible only for community members.
Rakshith
Moderator
Moderator
Moderator
250 likes received 1000 replies posted 750 replies posted

Hi mari_3596111,

Adding my response on the thread too:

As your project does not have the code in a loop the main() function gets executed as soon as you start the gdb session and thus the debug pointer is stuck at the while(1) condition in Cm0Start.c file after executing the main() code.

Two methods can be used as a workaround and I have provided the snapshot and commands used:

Method 1 -

1. Declare a volatile variable in main.c, for example - volatile uint8_t stop_var = 0x00;

2. Add a while loop before the execution of your application code - while(stop_var==0x00); before ldra_port_open();

3. Add a break point at the while(stop_var==0x00). Use the step command to stop the execution at that point.

4. Change the variable value of stop_var to 0x01 using command set variable stop_var = 0x01

5. Step through the code.

I have attached the project archive. A snapshot of gdb commands is shown below -

pastedImage_3.png

Method 2 -

1. This is very similar to the previous method.

2. Declare a volatile variable in main.c, for example - volatile uint8_t stop_var = 0x00;

3. Add a while loop at the end of your application code - while(stop_var==0x00);

4. Add a breakpoint at the while(stop_var==0x00). Use the step command to stop the execution at that point.

5. Add a breakpoint at main using the command b *main and then jump to main using jump main command.

6. Step through the code.

I have attached the project archive and snapshot of gdb commands is shown below.

pastedImage_4.png

Thanks and Regards,

Rakshith M B

Thanks and Regards,
Rakshith M B
0 Likes
lock attach
Attachments are accessible only for community members.

Hi,

OK I understand that since the Monitor reset command is not supported, then the program ends before the gdb can connect. I have resolved the issue by adopting one of the ideas that you proposed. This is now working for the PSoC4 and PSoC5.

Many thanks again.

Mark

0 Likes

Hi mari_3596111,

Glad your issue is resolved

Regards,

Rakshith M B

Thanks and Regards,
Rakshith M B
0 Likes