我刚刚开始将 STM8(一个 STM8L001J3,不幸的是开源工具链支持的最差)与 SDCC 一起使用。由于 ST Visual Programmer 只支持 s19,所以我需要选择这个作为输出格式。查看映射文件,一切似乎都很好,链接器将主函数放置在代码空间 0x8028 开头的稍微后面(就在中断向量后面)。
ASxxxx Linker V03.00 + NoICE + sdld, page 1.
Hexadecimal [32-Bits]
Area Addr Size Decimal Bytes (Attributes)
-------------------------------- ---- ---- ------- ----- ------------
. .ABS. 00000000 00000000 = 0. bytes (ABS,CON)
Value Global Global Defined In Module
----- -------------------------------- ------------------------
00000000 .__.ABS. main
00000000 l_CABS
00000000 l_CONST
00000000 l_DABS
00000000 l_DATA
00000000 l_INITIALIZED
00000000 l_INITIALIZER
00000000 l__CODE
00000000 s_CABS
00000000 s_DABS
00000000 s__CODE
00000001 l_SSEG
00000001 s_DATA
00000001 s_INITIALIZED
00000001 s_SSEG
00000003 l_GSFINAL
0000000B l_HOME
0000001A l_GSINIT
0000003A l_CODE
00008000 s_HOME
0000800B s_GSINIT
00008025 s_GSFINAL
00008028 s_CODE
00008028 s_CONST
00008028 s_INITIALIZER
ASxxxx Linker V03.00 + NoICE + sdld, page 2.
Hexadecimal [32-Bits]
Area Addr Size Decimal Bytes (Attributes)
-------------------------------- ---- ---- ------- ----- ------------
SSEG 00000001 00000001 = 1. bytes (REL,CON)
Value Global Global Defined In Module
----- -------------------------------- ------------------------
ASxxxx Linker V03.00 + NoICE + sdld, page 3.
Hexadecimal [32-Bits]
Area Addr Size Decimal Bytes (Attributes)
-------------------------------- ---- ---- ------- ----- ------------
HOME 00008000 0000000B = 11. bytes (REL,CON)
Value Global Global Defined In Module
----- -------------------------------- ------------------------
ASxxxx Linker V03.00 + NoICE + sdld, page 4.
Hexadecimal [32-Bits]
Area Addr Size Decimal Bytes (Attributes)
-------------------------------- ---- ---- ------- ----- ------------
GSINIT 0000800B 0000001A = 26. bytes (REL,CON)
Value Global Global Defined In Module
----- -------------------------------- ------------------------
ASxxxx Linker V03.00 + NoICE + sdld, page 5.
Hexadecimal [32-Bits]
Area Addr Size Decimal Bytes (Attributes)
-------------------------------- ---- ---- ------- ----- ------------
GSFINAL 00008025 00000003 = 3. bytes (REL,CON)
Value Global Global Defined In Module
----- -------------------------------- ------------------------
ASxxxx Linker V03.00 + NoICE + sdld, page 6.
Hexadecimal [32-Bits]
Area Addr Size Decimal Bytes (Attributes)
-------------------------------- ---- ---- ------- ----- ------------
CODE 00008028 0000003A = 58. bytes (REL,CON)
Value Global Global Defined In Module
----- -------------------------------- ------------------------
00008028 _main main
0000805D _handler main
ASxxxx Linker V03.00 + NoICE + sdld, page 7.
Files Linked [ module(s) ]
.\build\Debug\src\main.rel [ main ]
ASxxxx Linker V03.00 + NoICE + sdld, page 8.
User Base Address Definitions
HOME = 0x8000
DATA = 0x0001
代码本身如下所示:
#include <stdint.h>
#define PB_ODR (*(volatile uint8_t *)0x5005)
#define PB_IDR (*(volatile uint8_t *)0x5006)
#define PB_DDR (*(volatile uint8_t *)0x5007)
#define PB_CR1 (*(volatile uint8_t *)0x5008)
#define PB_CR2 (*(volatile uint8_t *)0x5009)
#define CLK_DIVR (*(volatile uint8_t *)0x50c0)
#define CLK_PCKENR2 (*(volatile uint8_t *)0x50c4)
void main(void)
{
CLK_DIVR = 0x01; // Set the frequency to 8 MHz
// Configure pins
PB_DDR |= (1 << 6); // Set PB6 to output
PB_CR1 &= ~(1 << 6); // Set PB6 to Open-Drain mode
PB_CR2 &= ~(1 << 6); // Set PB6 to slow mode
while(1)
{
for(int j = 0; j < 1000; j++) {
for(int i = 0; i < 1000; i++) {
__asm__("nop");
}
}
PB_ODR |= (1 << 6); // Toggle PB6
}
}
void handler (void) __trap
{
while (1)
{
__asm__("nop");
}
}
我什至设置--code-loc 0x8000
了链接器的选项以正确放置它,当我向 VSCode(带有 EIDE 扩展)询问命令行时,它告诉我以下信息:
unify_builder v2.8.0.1
C command line (sdcc): --std-c99 -c -mstm8 --opt-code-size --model-medium -I.\src
CPP command line (sdcc): -c -mstm8 --opt-code-size --model-medium -I.\src
ASM command line (sdasstm8): -l -o -s -I.\src
Linker command line (sdcc): --out-fmt-s19 -mstm8 --code-loc 0x8000
当我现在在 ST Visual Programmer 中打开文件时,它会显示:
> Loading file C:\GIT\Hardware\STM8-HowTo\STM8-SDCC-VSCode-Test\STM8-SDCC-Minimal\build\Debug\STM8-SDCC-Minimal.s19 in PROGRAM MEMORY area ...
FILE : line 1: Address 0x0 is out of range and is ignored!
FILE : line 2: Address 0x0 is out of range and is ignored!
...
如果我生成一些英特尔 HEX 文件并将其放入http://www.dlwrr.com/electronics/tools/hexview/hexview.html的在线查看器中,它看起来也不错。
由于我不会流利地说摩托罗拉 s19,也许有人可以给我一个提示。
如果有人可以批准,十六进制很好并将我链接到一个编程工具,在 Windows (10) 上支持这个变体,这也是一个可行的解决方案。