2023-10-02 11:50 PM
I am guessing having read forum after forum that this is an old topic
I am trying to get
to work on my STM32F302R8 and a nano
I have tried,
Changing receive and send to have volitile
I have tried the
Solved! Go to Solution.
2023-10-19 01:34 AM
You as promised I have uncovered the problems getting this to work
1/ The STM32F302R8TX_FLASH.ld does indeed send to bytes
To stop it doing this you need to change the write as others have suggested with
*(volatile uint8_t *)&pSPIx->DR = *pTxBuffer;
// pSPIx->DR = *pTxBuffer;
2/ You need to change the FRXTH in the CR2 register to be enabled
3/ You cannot use the debugger as this reads the register itself and produces different register states as a result
I managed in the end to use semihosting which provides the ability to use printf with OpenOCD and gdb. In order to use this you have to
a) remove syscalls.c from the build
b) update STM32F302R8TX_FLASH.ld to define __end__ (the build will fail with __end__ undefined otherwise)
._user_heap_stack :
{
. = ALIGN(8);
PROVIDE ( end = . );
PROVIDE ( _end = . );
PROVIDE ( __end__ = . );
. = . + _Min_Heap_Size;
. = . + _Min_Stack_Size;
. = ALIGN(8);
} >RAM
c) make sure STM32F302R8TX_FLASH.ld is linked
Now you should be able to run openocd in vs code with this launch.json
{
"name": "OpenOCD",
"type": "cppdbg",
"request": "launch",
"cwd": "${workspaceFolder}",
"program": "${command:cmake.launchTargetPath}",
"args": [],
"stopAtEntry": false,
"environment": [],
"externalConsole": false,
"filterStderr": true,
"filterStdout": false,
"logging": {
"moduleLoad": true,
"trace": true,
"engineLogging": true,
"programOutput": true,
"exceptions": false
},
"linux": {
"MIMode": "gdb",
"miDebuggerPath": "arm-none-eabi-gdb",
"debugServerPath": "openocd",
"debugServerArgs": "-f ${workspaceRoot}/test.cfg -c init -c \"reset init\"",
"setupCommands": [
{ "text": "-environment-cd ${workspaceRoot}/build" },
{
"text": "-target-select remote localhost:3333",
"description": "connect to target",
"ignoreFailures": false
},
{
"text": "-file-exec-and-symbols /home/jbond/course01.elf",
"description": "load file",
"ignoreFailures": false
},
{
"text": "-interpreter-exec console \"monitor reset\"",
"ignoreFailures": false
},
{
"text": "-interpreter-exec console \"monitor halt\"",
"ignoreFailures": false
},
{
"text": "-interpreter-exec console \"monitor arm semihosting enable\"",
"ignoreFailures": false
}
]
}
},
Remember to reverse this out when done.
The aim is hopefully to help someone, so they can build new great software. I would get this far without people who helped me.
Thanks
2023-10-19 01:34 AM
You as promised I have uncovered the problems getting this to work
1/ The STM32F302R8TX_FLASH.ld does indeed send to bytes
To stop it doing this you need to change the write as others have suggested with
*(volatile uint8_t *)&pSPIx->DR = *pTxBuffer;
// pSPIx->DR = *pTxBuffer;
2/ You need to change the FRXTH in the CR2 register to be enabled
3/ You cannot use the debugger as this reads the register itself and produces different register states as a result
I managed in the end to use semihosting which provides the ability to use printf with OpenOCD and gdb. In order to use this you have to
a) remove syscalls.c from the build
b) update STM32F302R8TX_FLASH.ld to define __end__ (the build will fail with __end__ undefined otherwise)
._user_heap_stack :
{
. = ALIGN(8);
PROVIDE ( end = . );
PROVIDE ( _end = . );
PROVIDE ( __end__ = . );
. = . + _Min_Heap_Size;
. = . + _Min_Stack_Size;
. = ALIGN(8);
} >RAM
c) make sure STM32F302R8TX_FLASH.ld is linked
Now you should be able to run openocd in vs code with this launch.json
{
"name": "OpenOCD",
"type": "cppdbg",
"request": "launch",
"cwd": "${workspaceFolder}",
"program": "${command:cmake.launchTargetPath}",
"args": [],
"stopAtEntry": false,
"environment": [],
"externalConsole": false,
"filterStderr": true,
"filterStdout": false,
"logging": {
"moduleLoad": true,
"trace": true,
"engineLogging": true,
"programOutput": true,
"exceptions": false
},
"linux": {
"MIMode": "gdb",
"miDebuggerPath": "arm-none-eabi-gdb",
"debugServerPath": "openocd",
"debugServerArgs": "-f ${workspaceRoot}/test.cfg -c init -c \"reset init\"",
"setupCommands": [
{ "text": "-environment-cd ${workspaceRoot}/build" },
{
"text": "-target-select remote localhost:3333",
"description": "connect to target",
"ignoreFailures": false
},
{
"text": "-file-exec-and-symbols /home/jbond/course01.elf",
"description": "load file",
"ignoreFailures": false
},
{
"text": "-interpreter-exec console \"monitor reset\"",
"ignoreFailures": false
},
{
"text": "-interpreter-exec console \"monitor halt\"",
"ignoreFailures": false
},
{
"text": "-interpreter-exec console \"monitor arm semihosting enable\"",
"ignoreFailures": false
}
]
}
},
Remember to reverse this out when done.
The aim is hopefully to help someone, so they can build new great software. I would get this far without people who helped me.
Thanks