Write for Debug or for production (read and delete protection).

cancel
Showing results for 
Search instead for 
Did you mean: 

Write for Debug or for production (read and delete protection).

Jump to solution
159 Views
luishs
Senior Contributor I


Is there a simple and fast way to be able to select between writing the microcontroller for Debug or for production (read and delete protection).

I already found out that by configuring the last byte of Flash_Config in the startup file I can program the microcontroller with read and delete protection. The problem is that having to change this byte by hand every time I want to switch between development doing Debug and production with read and delete protections is not comfortable at all.

0 Kudos
1 Solution
128 Views
ErichS
Senior Contributor III

Yes, the build configuration sets all the build options/etc.

So you can have two builds, with:

- Develop, this one has the define set with option -D, for example BUILD_FOR_PRODUCTION=0

ErichS_0-1615554158384.png

 

- Production, this one has set BUILD_FOR_PRODUCTION=1

 

Then in your startup file you have this:

__attribute__ ((used,section(".FlashConfig"))) const struct {
    unsigned int word1;
    unsigned int word2;
    unsigned int word3;
    unsigned int word4;
} Flash_Config = 
#if BUILD_FOR_PRODUCTION==1
{0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, whatever you put here }; /* flash security enabled */
#else /* debug/develop */
{0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFE};
#endif

 

That way you have the full flexibility, and you can use that macro in other places too (e.g. for extra logging, etc).

I hope this helps,

Erich

View solution in original post

0 Kudos
4 Replies
155 Views
ErichS
Senior Contributor III

Have you considered using Build Configurations (https://mcuoneclipse.com/2016/05/19/build-configurations-in-eclipse/ ) for this?

You could have a 'develop' and a 'release' configuration with just different settings (e.g define) or file included/excluded.

I hope this helps,

Erich

0 Kudos
134 Views
luishs
Senior Contributor I


Thanks.
But I think that's just for build configuration parameters, where I don't see the state of the bits to protect the microcontroller against reading or erasing.

I think that if I define a constant with #define and put an #ifdef in the startup file, I could select that various settings of these bits are applied. Although I'm not really sure if the #defines put in my sources will affect the startup file as well or I put it directly in the startup file.

 

0 Kudos
129 Views
ErichS
Senior Contributor III

Yes, the build configuration sets all the build options/etc.

So you can have two builds, with:

- Develop, this one has the define set with option -D, for example BUILD_FOR_PRODUCTION=0

ErichS_0-1615554158384.png

 

- Production, this one has set BUILD_FOR_PRODUCTION=1

 

Then in your startup file you have this:

__attribute__ ((used,section(".FlashConfig"))) const struct {
    unsigned int word1;
    unsigned int word2;
    unsigned int word3;
    unsigned int word4;
} Flash_Config = 
#if BUILD_FOR_PRODUCTION==1
{0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, whatever you put here }; /* flash security enabled */
#else /* debug/develop */
{0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFE};
#endif

 

That way you have the full flexibility, and you can use that macro in other places too (e.g. for extra logging, etc).

I hope this helps,

Erich

View solution in original post

0 Kudos
124 Views
luishs
Senior Contributor I


Ok, perfect, thank you very much.

0 Kudos