2023-08-22 08:24 AM
I'm using the STM32CubeIde 1.12.0 Build: 14980_20230301_1550 together with the STM32Cube_FW_G4_V1.5.1 and FreeRtos.
When I run the strtok the first time I see that the Register in FLASH->SR change the value from 0x00 to 0xe0. What later makes problem when I use the HAL_Flash functions.
I moved also the strtok call from the task method to the main prior to the FreeRtos setup with the same effect.
#define SVN_URL "https://bla/svn/myProject/trunk"
char *pLast;
pch = strtok (SVN_URL,"/");
while (pch != NULL)
{
pLast = pch;
pch = strtok (NULL, "/");
}
Does this come from the issue @Dave Nadler described in https://community.st.com/t5/stm32cubemx-mcu/bug-cubemx-freertos-projects-corrupt-memory/m-p/267070 ?
If yes are there recommondations from ST how to handle this?
Solved! Go to Solution.
2023-08-22 08:37 AM
Is strtok() thread safe? I'd not use it in a RTOS / multi-thread app.
I'd use strsep()
Issue here is probably that the static string is placed in "RO" FLASH, and you're trying to write NUL's in to it. Make sure it's in RAM. Copy it there, use a local/stack copy, or strmalloc() type implementation
2023-08-22 08:37 AM
Is strtok() thread safe? I'd not use it in a RTOS / multi-thread app.
I'd use strsep()
Issue here is probably that the static string is placed in "RO" FLASH, and you're trying to write NUL's in to it. Make sure it's in RAM. Copy it there, use a local/stack copy, or strmalloc() type implementation
2023-08-22 10:57 PM
@Tesla DeLoreanYes, it is the RAM thing. I changed the code as below and now it works. Thanks for the hint.
#define SVN_URL "https://bla/svn/myProject/trunk"
char * pch;
char *pLast;
char myUrl[200];
strncpy(myUrl, SVN_URL, 200);
pch = strtok (myUrl,"/");
while (pch != NULL)
{
pLast = pch;
pch = strtok (NULL, "/");
}
2023-08-24 03:48 AM
With FreeRTOS you want to use strtok_r. Or strsep as @Tesla advised. By the way strsep patches the input string like strtok does, so won't work on read-only memory as well.