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.
解決済! 解決策の投稿を見る。
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
- 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
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
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.
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
- 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
Ok, perfect, thank you very much.