作業系統之前的程式 for stm32f4 - discovery (0.2) - p103 模擬器

来源:互联网 发布:夏易网络 编辑:程序博客网 时间:2024/05/22 13:04
p103 這個模擬器有支援 stm32 p103 uart, 所以選用了這個模擬器, 主要目的是為了測試 c++ 和 uart, 為什麼不在真正的版子上測試呢? 我想把寫入 flash 的次數減少一點, 等到開發到一定程度才搬到 stm32f4 - discovery 上測試, 所以重溫一下模擬器的懷抱。

參考成大 wiki: http://wiki.csie.ncku.edu.tw/embedded/Lab1

git clone git://github.com/beckus/stm32_p103_demos.gitgit clone git://github.com/beckus/qemu_stm32.gitcd qemu_stm32 # p103 模擬器./configure --disable-werror --enable-debug \    --target-list="arm-softmmu" \    --extra-cflags=-DDEBUG_CLKTREE \    --extra-cflags=-DDEBUG_STM32_RCC \    --extra-cflags=-DDEBUG_STM32_UART \    --extra-cflags=-DSTM32_UART_NO_BAUD_DELAY \    --extra-cflags=-DSTM32_UART_ENABLE_OVERRUNmakecd ../stm32_p103_demos # p103 範例程式export PATH=/usr/local/csl/arm-2012.03/bin:$PATHmake allmake blink_flash_QEMURUNmake button_QEMURUNmake uart_echo_QEMURUN

我修改了 stm32_p103_demos/demos/uart_echo 的程式, 有了單獨的 makefile 和 mymain.cpp 程式, 還有一個 q.sh 用來執行 qemu。

main.c
 1 #define USE_STDPERIPH_DRIVER 2 #include "stm32f10x.h" 3 #include "stm32_p103.h" 4  5 void send_byte(uint8_t b) 6 { 7     /* Send one byte */ 8     USART_SendData(USART2, b); 9 10     /* Loop until USART2 DR register is empty */11     while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);12 }13 14 int main(void)15 {16     uint8_t b;17 18     init_rs232();19     USART_Cmd(USART2, ENABLE);20 21     while(1) {22         /* Loop until the USART2 has received a byte. */23         while(USART_GetFlagStatus(USART2, USART_FLAG_RXNE) == RESET);24 25         /* Capture the received byte and print it out. */26         b = (USART_ReceiveData(USART2) & 0x7F);27         send_byte('G');28         send_byte('o');29         send_byte('t');30         send_byte(':');31         send_byte(b);32         send_byte('\n');33     }34 }

mymain.cpp
 1 #define USE_STDPERIPH_DRIVER 2 #include "stm32f10x.h" 3 #include "stm32_p103.h" 4  5 void send_byte(uint8_t b) 6 { 7     /* Send one byte */ 8     USART_SendData(USART2, b); 9 10     /* Loop until USART2 DR register is empty */11     while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);12 }13 14 extern "C"15 {16 int main(void)17 {18     uint8_t b;19 20     init_rs232();21     USART_Cmd(USART2, ENABLE);22 23     while(1) {24         /* Loop until the USART2 has received a byte. */25         while(USART_GetFlagStatus(USART2, USART_FLAG_RXNE) == RESET);26 27         /* Capture the received byte and print it out. */28         b = (USART_ReceiveData(USART2) & 0x7F);29         send_byte('G');30         send_byte('o');31         send_byte('t');32         send_byte(':');33         send_byte(b);34         send_byte('\n');35     }36 }37 }

descent@debianlinux:uart_echo$ ls -l *.elf *.bin
-rwxr-xr-x 1 descent descent 9596 Oct 22 14:42 main.bin
-rwxr-xr-x 1 descent descent 113726 Oct 22 14:42 main.elf
-rwxr-xr-x 1 descent descent 9780 Oct 22 14:42 mymain.bin
-rwxr-xr-x 1 descent descent 115282 Oct 22 14:42 mymain.elf

c++ compiler 編譯出來的版本讓我疑惑, 我以為應該要和 c compiler 的版本一樣, 這個 c++ 的版本和 c 版本一模一樣, 但 elf 大小就是不一樣, 大了一點點, 我是不是被書上寫的「你沒用到的東西不應該為此付出代價」給騙了。

還發了篇文章詢問: 《c++ 編譯出來的程式檔案比較大》, 不過沒有得到什麼答案。

最後的成果就是: 《作業系統之前的 scheme》

source code:
git@github.com:descent/stm32_p103_demos.git
stm32_p103_demos/demos/uart_echo
git commit: 85e31e52bec1effd359401b83ef69c1768d13197
0 0
原创粉丝点击