开源软件名称(OpenSource Name):glegrain/STM32-with-macOS开源软件地址(OpenSource Url):https://github.com/glegrain/STM32-with-macOS开源编程语言(OpenSource Language):C 98.8%开源软件介绍(OpenSource Introduction):Using GCC and Makefiles on macOS to build STM32CubeMX projectsAs of v4.21.0, STM32CubeMX is now capable of generating Makefiles that can be used to build projects using the GNU ARM Embedded Toolchain. Makefiles allow you to be IDE independent and use you favorite text editor. For some people, IDEs are slow and take up a lot of resources. With a Makefile, building your project is as simple as typing Although this tutorial has been written with macOS in mind, similar steps can be applied to Linux or Windows machines.
0 - Installing the toolchainRequirements:
After the Command Line Tools were successfully installed, the remaining toolchain requirements can be installed using Homebrew.
If the above command does not work, you could try installing
And Java 8 will be installed at
Pro Tip: Create a symbolic link to one of the binary directory searched by your
Then,
1 - Create a Project using CubeMXIf you are also using an NUCLEO-L476RG, you can use the example "blinky" project by cloning the following repo:
Alternatively, you can generate you own project:
For more information, refer to the STM32CubeMX User Manual available on st.com. Usefull sections include:
2 - Configure your MakefileUnfortunately, Makefiles generated by CubeMX do not work out-of-the-box. You need to edit the file and set your compiler path. Luckily, this step only has to be done once. Later on, if you want to add source, header files or simply change your compiler options, refer to the [Editing your Makefile] section for more details.
#######################################
# binaries
#######################################
BINPATH = /usr/local/bin
PREFIX = arm-none-eabi-
CC = $(BINPATH)/$(PREFIX)gcc
AS = $(BINPATH)/$(PREFIX)gcc -x assembler-with-cpp
CP = $(BINPATH)/$(PREFIX)objcopy
AR = $(BINPATH)/$(PREFIX)ar
SZ = $(BINPATH)/$(PREFIX)size
HEX = $(CP) -O ihex
BIN = $(CP) -O binary -S Pro Tip: To make the Makefile more portable between different users and environment, you can remove the #######################################
# binaries
#######################################
PREFIX = arm-none-eabi-
CC = $(PREFIX)gcc
AS = $(PREFIX)gcc -x assembler-with-cpp
CP = $(PREFIX)objcopy
AR = $(PREFIX)ar
SZ = $(PREFIX)size
HEX = $(CP) -O ihex
BIN = $(CP) -O binary -S 3 - Building your projectIn a Terminal, navigate to your project's root directory (or Makefile location). Then use the
Pro Tip: for faster build time,
If all goes well, you should see a result without any errors or warning:
Pro Tip: The Makefile generated by CubeMX comes with a predefined rule called
4 - Programming the boardOption 1 - Using STM32CubeProgrammer GUI:
Note: Because STM32CubeProgrammer is still relatively new, chances are you will have to upgrade your ST-Link firmware. For more information, you can refer to the STM32CubeProgrammer User Manual Option 1.1 - Using STM32CubeProgrammer CLI:Below are some example commands to erase and program the target using STM32CubeProgrammer CLI:
Option 2 - Using texane stlink:If all you want to do is program the board, then run any of the following commands:
Otherwise, to program and debug run the gdb server with:
Option 3 - Using OpenOCD:OpenOCD requires a a configuration file. If you installed openOCD using Homebrew, list of provided configuration (
For example, you could the following command to program and verify using elf/hex/s19 files. Verify, reset and exit are optional parameters. Binary files need the flash address passing.
More examples and documentation available here 5 - DebuggingBecause you will be debugging a remote target device, GDB needs to connect to a gdbserver compliant debugger. Before launching GDB, you need to start a GDB server using your debugger to act as an interface between GDB and your device. Step 1 - Start a GDB serverOption 1.1 - Using texane stlink
Option 1.2 - Using OpenOCD
Step 2 - Launch GDB:
Here is my file "./build/Example_Project.elf"
# Connect to texane stlink gdb server
target extended-remote :4242
# Or, connect to openOCD instead
# target remote localhost:3333
# monitor reset init
# monitor halt
# Uncomment to enable semihosting
# monitor arm semihosting enable
# Flash program and load symbols
load
break main
# Run to main (first breakpoint)
continue
Pro Tip: Launch GDB in GDB in Text User Interface (TUI) mode to show the source file and GDB commands in separate windows:
Step 3 - Using GDBProgram stepping/execution:https://sourceware.org/gdb/onlinedocs/gdb/Continuing-and-Stepping.html Step over (step to next line of C code without going into functions): (gdb) next
90 SystemClock_Config();
(gdb) n
97 MX_GPIO_Init();
(gdb) Step into (step to next line of C, goes into functions): (gdb) step
SystemClock_Config () at ./Src/main.c:124
124 { Note: Use Return from a function: (gdb) finish
Run till exit from #0 SystemClock_Config () at ./Src/main.c:124
main () at ./Src/main.c:97
97 MX_GPIO_Init(); Run until next breakpoint: (gdb) continue
Continuing. Pro Tip: for most command, you can simply type in the first letter. e.g. Pro Tip: Press enter to repeat the previous command. Very usefull to quickly step trough a program. Pro Tip: gdb also supports TAB completion. e.g Pro Tip: Use Setting a breakpoint:https://sourceware.org/gdb/onlinedocs/gdb/Breakpoints.html#Breakpoints http://www.unknownroad.com/rtfm/gdbtut/gdbbreak.html From there, you can add breakpoints using any of the following methods in the GDB command: Break on line number and run until breakpoint: (gdb) break main.c:107
Breakpoint 2 at 0x800208e: file ./Src/main.c, line 107.
(gdb) continue
Continuing.
Breakpoint 2, main () at ./Src/main.c:107
107 HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin); Break on function: (gdb) break SystemClock_Config
Breakpoint 2 at 0x8001fd0: file ./Src/main.c, line 132.
(gdb) continue
Continuing.
Breakpoint 2, SystemClock_Config () at ./Src/main.c:132
132 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
(gdb) List breakpoints: (gdb) info break
Num Type Disp Enb Address What
1 breakpoint keep y 0x0800207e in main at ./Src/main.c:83
breakpoint already hit 1 time
2 breakpoint keep y 0x0800208e in main at ./Src/main.c:107
3 breakpoint keep y 0x08001fd0 in SystemClock_Config at ./Src/main.c:132 Remove a breakpoint: (gdb) delete 2
(gdb) disable 3
(gdb) i b
Num Type Disp Enb Address What
1 breakpoint keep y 0x0800207e in main at ./Src/main.c:83
breakpoint already hit 1 time
3 breakpoint keep n 0x08001fd0 in SystemClock_Config at ./Src/main.c:132 Inspecting and setting variables and memory:(gdb) print uwTick
$1 = 1206
(gdb) set uwTick=0
(gdb) p uwTick
$2 = 0 (gdb) x /32x 0x08000000
0x8000000: 0x20018000 0x080017d9 0x08001829 0x08001829
0x8000010: 0x08001829 0x08001829 0x08001829 0x00000000
0x8000020: 0x00000000 0x00000000 0x00000000 0x08001829
0x8000030: 0x08001829 0x00000000 0x08001829 0x08001785
0x8000040: 0x08001829 0x08001829 0x08001829 0x08001829
0x8000050: 0x08001829 0x08001829 0x08001829 0x08001829
0x8000060: 0x08001829 0x08001829 0x08001829 0x08001829
0x8000070: 0x08001829 0x08001829 0x08001829 0x08001829 Manipulating registers:https://community.st.com/s/question/0D50X00009XkeAmSAJ/reading-io-register-values-with-command-line-gdb https://gcc.gnu.org/onlinedocs/gcc-7.3.0/gcc/Debugging-Options.html Include additional debug information, such as all the macro definitions that can be used to inspect I/O registers:
Level 3 includes extra information, such as all the macro definitions present in the program. Some debuggers support macro expansion when you use -g3.
(gdb) p /x *GPIOA
$4 = {MODER = 0xabfff7ff, OTYPER = 0x0, OSPEEDR = 0xc000000, PUPDR = 0x64000000,
IDR = 0xc020, ODR = 0x20, BSRR = 0x0, LCKR = 0x0, AFR = {0x0, 0x0}, BRR = 0x0,
ASCR = 0x0}
(gdb) set GPIOA->ODR ^= 0x20
(gdb) p /x TIM3->CCMR1 Viewing the call stack:https://sourceware.org/gdb/onlinedocs/gdb/Backtrace.html
Restarting/reset:
Looking at the code (useful when TUI mode is disabled):(gdb) n
107 HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin);
(gdb) list
102
103 /* Infinite loop */
104 /* USER CODE BEGIN WHILE */
105 while (1)
106 {
107 HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin);
108 HAL_Delay(200);
109
110 /* USER CODE END WHILE */
111
(gdb) n
108 HAL_Delay(200);
(gdb) tui enable Show next assembly instructions:https://sourceware.org/gdb/onlinedocs/gdb/Machine-Code.html#Machine-Code (gdb) set disassemble-next-line on
(gdb) show disassemble-next-line
Debugger's willingness to use disassemble-next-line is o
(gdb) next
107 HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin);
=> 0x08000626 <main+186>: 20 21 movs r1, #32
0x08000628 <main+188>: 4f f0 90 40 mov.w r0, #1207959552 ; 0x48000000
0x0800062c <main+192>: 01 f0 92 fb bl 0x8001d54 <HAL_GPIO_TogglePin> Getting help:全部评论
专题导读
上一篇:daliansky/XiaoMi-Pro-Hackintosh: XiaoMi NoteBook Pro Hackintosh发布时间:2022-08-18下一篇:rnine/SimplyCoreAudio: 发布时间:2022-08-18热门推荐
热门话题
阅读排行榜
|
请发表评论