I am having a problem with a large const char compiling but not running on the STM32F4 Discovery board. Here is a clip of the code. The line that causes program not to work is down towards the bottom and has a comment to that effect towards the right. Help, ALB.
static WORKING_AREA(waThread2, 128);
static msg_t Thread2(void *arg) {
systime_t time; /* Next deadline.*/
(void)arg;
int P0 = 0;
// const uint8_t menu1[] = //59 * 19 = 1121 bytes
const char menu1[] = //59 * 19 = 1121 bytes
"|-------------------------------------------------------|\r\n"
"| FLEXSTACK TEST MENU |\r\n"
"|-------------------------------------------------------|\r\n"
"| 0 | | Initialize Flexstack |\r\n"
"| 1 | | Run four motor goal list 1 |\r\n"
"| 2 | | Manually enter goal |\r\n"
"| 3 | | Ping |\r\n"
"| 4 | | Read Model Number and FW Version |\r\n"
"| 5 | | Goal 270 degrees, V=57 RPM |\r\n"
"| 6 | | Goal 90 degrees, V=57 RPM |\r\n"
"| 7 | | Read memory values |\r\n"
"| 8 | | Run one motor goal list |\r\n"
"| 9 | | Run two motor goal list |\r\n"
"|-------------------------------------------------------|\r\n"
"| |\r\n"
"|-------------------------------------------------------|\r\n"
"| M | | Menu |\r\n"
"| Q | | Quit |\r\n"
"|-------------------------------------------------------|\r\n"; //59 * 19 = 1121 bytes
const char message1[] = "***** message1 *****\r\n"; // 22 bytes
int str_len1,str_len2;
str_len1 = strlen(message1);
str_len2 = strlen(menu1);
time = chTimeNow();
P0=1;
while(P0) {
chprintf((BaseSequentialStream*)&SDU1, "%s", message1);
chprintf((BaseSequentialStream*)&SDU1, "%s", menu1); // ALB - does not work with this line
chprintf((BaseSequentialStream*)&SDU1, "str_len1 = %d\r\n", str_len1);
chprintf((BaseSequentialStream*)&SDU1, "str_len2 = %d\r\n", str_len2);
// Waiting until the next 250 milliseconds time interval.
chThdSleepUntil(time += MS2ST(100));
}
}
Problem with large constant character strings
Moderator: RoccoMarco
- Giovanni
- Site Admin
- Posts: 14892
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 996 times
Re: Problem with large constant character strings
Hi,
What is the effect of the bug? plese give context or I just see a block of code.
Giovanni
What is the effect of the bug? plese give context or I just see a block of code.
Giovanni
Re: Problem with large constant character strings
I don't understand why you use:
chprintf((BaseSequentialStream*)&SDU1, "%s", menu1); // ALB - does not work with this line
instead of:
chprintf((BaseSequentialStream*)&SDU1, menu1);
I don't think that "%s" is meant to be used on long strings.
Regards
Vicente
chprintf((BaseSequentialStream*)&SDU1, "%s", menu1); // ALB - does not work with this line
instead of:
chprintf((BaseSequentialStream*)&SDU1, menu1);
I don't think that "%s" is meant to be used on long strings.
Regards
Vicente
Re: Problem with large constant character strings
Am I perhaps running into a limit on string length problem? With the menu1 string reduced to one line the program will compile and execute as desired, but with menu1 at two or more lines the program will compile but not execute as desired - generally one of the four LEDs between the two push buttons will be on but no action when the board is moved and no action with the USB terminal emulation. I started with the mems example. It also displayed the same problem when I increased the length of the first line to 70 characters. I'm going try sending menu1 one line at a time. Thanks, ALB.
- Giovanni
- Site Admin
- Posts: 14892
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 996 times
Re: Problem with large constant character strings
If the application locks probably the program crashed for some reason. Do you have the debug options enabled in chconf.h? those can detect a lot of hidden errors, for example a stack overflow.
Giovanni
Giovanni
Re: Problem with large constant character strings
I have not used the debugger yet. Probably my next step. I am not using an IDE so, I'm looking on how to use debugger. Thanks, ALB
Re: Problem with large constant character strings
Looking at the FLASH memory it looks like the menu1 table is getting put into three separate areas of FLASH instead of being located contiguously as I would have expected. Some of the data is missing - unless the five lines of hyphens are getting stored as just one line since they are all the same. Are there maybe some configuaation files that I need to set up that would resolve this? Compiler options? ALB
Re: Problem with large constant character strings
I have used long strings before without problem.
If it is a flash storage problem it will show also sending one char, or one line, on each print or sendchar command.
Did you try my suggestion of not using the %s method?
You really don't need to format the string.
Vicente
If it is a flash storage problem it will show also sending one char, or one line, on each print or sendchar command.
Did you try my suggestion of not using the %s method?
You really don't need to format the string.
Vicente
Re: Problem with large constant character strings
Anyone interested in taking a look at full code to see what the problem might be? If so, holler and I'll attach a zip file. I am using an STM32F4 Discovery board, Yagarto, Chibios 2.6.4, STM32 ST-LINK Utility, and TeraTerm for my setup. Thanks, ALB
- Giovanni
- Site Admin
- Posts: 14892
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 996 times
Re: Problem with large constant character strings
Post a small project, it is the best way, somebody could give it a try.
Giovanni
Giovanni