切换到宽版
  • 7347阅读
  • 27回复

[STM]新年大礼包:ARDUINO  STM8   发布: (一) 安装 [复制链接]

上一主题 下一主题
在线huaweiwx
 

发帖
1327
M币
196
专家
57
粉丝
252
在 帖子:喜讯!STM8 可以用arduino开发了|http://bbs.mydigit.cn/read.php?tid=2354201中对 ARDUINO  STM8 ,经移植修改和测试,初步成果先作为新年礼包共享给坛友:

一、准备工作:
1  首先请阅读 :STM32 ARDUINO HALMX 起步|http://bbs.mydigit.cn/read.php?tid=2168292,并按该教程程序安装ARDUINO且能正确运行编译stm32代码,验证IDE集成环境构建是否正确;
2 在ARDUINO 菜单 tools->board 如果能看到 arduino avr boards 图示的板子:


说明系统已经安装过AVR板子和avr-gcc工具链,请在菜单:板管理中 检查是否是最新avr板的版本,如果没有看到,板管理中安装最新的avr 板子;尽管stm8 并不使用avr-gcc,而是用sdcc编译工具,但需要使用avr-gcc中工具来作一些预处理和分析,以便最大限度兼容于arduino官方的表达方式和库包含路径支持、板及编译参数设定方法;!因此这步检查和安装是必须的!
3 现在针对avr和stm32都应能正确编译了,可以开始安装stm8附加包:打开我共享给坛友的百度链接,可看到 arduino1805_stm8add_20180305.rar这个压缩包,请下载并解压;文件名后面的20180305是今天上传的时间,以后会有新的更新尾号也是更新的日期,请视需要自行下载更新,也可以到https://github.com/huaweiwx/sduino 查看更新日志/检查更新内容、下载或同步;
4 将3中解压文件夹 arduino1805_stm8add/hardware/ 中 ex_sduino文件夹拖放到arduino/hardware/中;
5 打开arduinoIDE ,打开 菜单 工具->board: 可以看着当前支持的芯片:


6 现在可以选择S103F3板子,并在菜单上选择:      
文件->Examples->Generic_examples->01 basic->blink打开开文件,然后点取验证,完成后的画面类似下图:


如你能看到这样的最后画面,则环境建立工作就完成了;


二、当前支持的板子:
1/2  S003F3(Breakout Board) /S103F3(Breakout Board) 这是原作者支持的(砖头)板子 芯片为 STM8S003F3P6/STM8S003F3P6,引脚编号为:


led缺省定义是接PB5;我没有买这个板子,只是编译通过,不过应该能正常运行的;


3 S103K3 (blue) 这是我买的测试板子,芯片是stm8s103k3t6:


我做了个arduino风格的引脚编号图:


这个板子的led连接到了个排针,需要短路帽连接PD7缺省,如果不用串口RX也可连接到PD6;
4 S105K4 (Breakout Board),这是我买的另一块测试板子,芯片是stm8s103k4t6(砖头板),LED位置是PE5:


5 S105K6 (Breakout Board)(未测试)
6 S105C6(Discovery)(未测试)
上述STM8S系列 3 4 都做了测试,编译下载运行都是正常的,其他没测试的应该问题不大吗,因为都是使用同一个库,而且stm8s不同型号差别也不大;
7 L152C8T6/L152R8T6(未测试),这个环境是全新的,我已经完成的了对STM8L15x_StdPeriph_Driver使用 SDCC的移植(说明,原stm8的库均不支持SDCC,但移植也只需要部分小修改,主要是语法上的差异),并做好了一个连接库(只做了一个支持 stm8L hd的,调通一个后最做其他的 );下一步就用血糖仪上的芯片来测试;


三、下载运行:


当前只使用stlink2来下载,如需要串口下载,请在github其他移植者那里下载后并入,以后我也会增加的;
如果你手头有stlink2和上述8S板子,可以直接点upload(上传),如不是上述板子,但只要型号对也是可以用的,只要修改改下自己diy的板子LED位置即可;
串口输出也是正常的;



2018.3.8 百度共享地址:
http://pan.baidu.com/s/1i48rVNJ
[ 此帖被huaweiwx在2018-03-08 08:51重新编辑 ]
本文内容包含图片或附件,获取更多资讯,请 登录 后查看;或者 注册 成为会员获得更多权限
本帖最近打赏记录:共1条打赏M币+8
afk M币 +8 認真發帖 04-18

发帖
49091
M币
4956
专家
10
粉丝
146
只看该作者 1楼 发表于: 03-05
没找着所谓的 arduino1805_stm8add_20180305.rar 百度链接...........
在线huaweiwx

发帖
1327
M币
196
专家
57
粉丝
252
只看该作者 2楼 发表于: 03-05
回 风铃夜思雨 的帖子
风铃夜思雨:没找着所谓的 arduino1805_stm8add_20180305.rar 百度链接........... (2018-03-05 21:41) 回 风铃夜思雨 的帖子

就是我 STM32 ARDUINO HALMX 起步|http://bbs.mydigit.cn/read.php?tid=2168292帖子里的那个共享地址,这里重复贴一下:

http://pan.baidu.com/s/1i48rVNJ
本帖最近打赏记录:共1条打赏M币+13
离线kinneng

发帖
24098
M币
22815
专家
47
粉丝
3983
只看该作者 3楼 发表于: 03-05
我的Arduino IDE装这些东西已经爆满,光是STM32同款菜单就有好几个,也忘了什么时候搞上去的,每次启动IDE要等好几分钟。

支持的板当然越多越好,问题是库不兼容的也多。
MSN :Kinneng@msn.cn   QQ :65686789 

我一向实话实说,虽然会得罪小人,既然是小人,我得罪得起。我是外行的,上这论坛纯灌水,灌完走人。
离线yanghc

发帖
150
M币
122
专家
1
粉丝
12
只看该作者 4楼 发表于: 03-05
厉害搞个玩玩
在线huaweiwx

发帖
1327
M币
196
专家
57
粉丝
252
只看该作者 5楼 发表于: 03-05






由于 SDCC不支持C++,因此,Sduino采用了类似c++的方案,但使用者仍面临将现有代码从 c++ 迁移到 c ,附在github上的原始说明:


Migrating existing code from C++ to C syntaxThe original Arduino environment uses C++ syntax while sduino can only use plain C syntax. Luckily, not many C++ features are used and in most cases a conversion is not very hard. In most cases a conversion from C++ to C it is just a matter of exchanging a dot for an underscore:
A C++ method name class.method() becomes a C function name class_method().
This is possible since most libraries are written to be used as a singleton anyway, so the fixed name prefix is not a problem. Only very few libraries need a slightly more complex approach to be able to deal with multiple instances.
There are two bigger problems left:


Polymorph functions

The concept of polymorphism does not exist for plain C. As a workaround 'mangled' function names are used for the different parameter type combinations supported by the original polymorph methods.
Typical name extensions are: _u for unsigned values, _i for signed integer values, _cfor characters, _s for strings, _n for data buffer/length combinations.
For more non-regular polymorphism the name extension is often related to the different use cases or to the names of the given parameters. Refer to the respective library header file for details.
Some examples of typical name changes:
C++ nameC name
Serial.print(int)Serial_print_i
Serial.print(unsigned)Serial_print_u
Serial.print(float)Serial_print_f
Serial.print(char)Serial_print_c
Serial.print(char *)Serial_print_s
Serial.print(char *buf, int len)Serial_print_n
Serial.print(unsigned n, int base)Serial_print_ub
random(long)random
random(long howsmall, long howbig)random_minmax


The _Generic selection

The C11 standard introduced the _Generic selection function. This function allows for automatic selection of different function variants at compile time depending on the type of the function arguments mimicing polymorph C++ functions.
Recent versions of SDCC already support this function (command line argument --std-sdcc99), but it's usefulness is still limited to some special cases.
#define Serial_print(X) _Generic((X), \char*: Serial_print_s, \signed long: Serial_print_i, \signed int: Serial_print_i, \signed char: Serial_print_c, \unsigned long: Serial_print_u, \unsigned int: Serial_print_u, \unsigned char: Serial_print_u \)(X)This would unify some, but not all print function variants:
C++ nameC name using _Generic
Serial.print(int)Serial_print
Serial.print(unsigned)Serial_print
Serial.print(char)Serial_print
Serial.print(char *)Serial_print_s
Serial.print(char *buf, int len)Serial_print_n
Serial.print(unsigned n, int base)Serial_print_ub
Unfortunately cpp does not match string constants and char* resulting in a very non-regular usage pattern:
char *string="Hello";Serial_print(string);   // worksSerial_print("Hello");  // doesn't workSerial_print_s("Hello");// worksTo avoid too much confusion it might be better to not use _Generic at all.
Another problem using the _Generic selector is configurable instance names. The preprocessor does not allow for variable macro names. That means _Generic would work with fixed name like Serial, but it wouldn't work for SoftwareSerial with no standard instance name.


Inheritance from Print class

Most character output modules inherit methods from the Print class by providing a virtual write method. A similar result can be achived by providing a function pointer to the write function to be used to the print functions.
This additional parameter is hidden from the user by providing more convinient defines in every library that need to 'inherit' functions from Print. This way lcd.print("Hello World!") becomes lcd_print_s("Hello World!") and Serial.print("Hello World!") becomes Serial_print_s("Hello World!"). Both call the same code from Print, but with different function pointers to their own putchar/write function.


Libraries with multiple instances

If multiple instances need to be supported, an approach similar to a C file descriptor is used. The "constructor" function allocates and initializes a data structure for one particular instance and return a pointer to this structure. Typically, this is done in the setup()-function and this pointer is stored in a global variable to be used as a device descriptor.
So far the Stepper library is the only example:
#include <Stepper.h>Stepper myStepper;      // variable to store the "device descriptor"void setup(void) {myStepper = Stepper_2phase(100,11,12);  // init a 2 phase stepper}void loop() {Stepper_step(myStepper, 20);        // do 20 steps forward}

Differences from the original Arduino environment



Additional output pin modes

Pin modePin properties
OUTPUToutput, push-pull, slow mode (default)
OUTPUT_ODoutput, open drain, fast mode
OUTPUT_FASToutput, push-pull, fast mode
OUTPUT_OD_FASToutput, open drain, fast mode


Timer

millis() uses timer4. The prescaler and end value is calculated at compile time for a cycle time as close to 1ms as possible. Default values @16Mhz: prescaler=64, counter cycle=250 (end value=249), resulting in exactly 1ms intervals.
timer1: PWM for PC3, PC4, on alternate mapping PC6, PC7, could be used for ADC
timer2: PWM for PA3, PD3, PD4 or PC5 (mutual exclusive)
timer4: millis()



Leaving out unused parts

Some functions of the core Arduino system can be left out on compilation to save code space. This is done by compiler flags that can be defined in the Makefile:
BOARD_TAG = stm8sblueCFLAGS = -DNO_SERIAL -DNO_ANALOG_IN -DNO_ANALOG_OUTinclude ../../../sduino.mkThese flags are supported:
FlagBytes savedFunctions lost
NO_SERIAL765all serial communication
NO_ANALOG_OUT406analogWrite()
NO_ANALOG_IN56analogRead()


Other modifications

makeWord(unsigned char, unsigned char) is an inline function now.


Additional compile-time flags

Some internal details can be influenced by setting compile-time defines using the CFLAGS=-Dflagname line in the Makefile.
SUPPORT_ALTERNATE_MAPPINGS: Allow the use of alternateFunctions()
ENABLE_SWIM: Do not disable the remote debugging function on the SWIM pin. This means that this pin can not be used for normal I/O functions.
USE_SPL: Use SPL functions for I/O access instead of direct register accesses. Useful only for debugging and porting to other CPU variants. Do not use for regular development.


General notes on the Arduino port



ADC

the prescaler is initialised for an ADC clock in the range of 1..2 MHz. The minimum prescaler value is 2, so for a clock speed of less than 2 MHz the required minimum ADC clock frequency can not be reached anymore.


Mapping of logical pin numbers to register addresses

The lookup-table approach for assigning port and bit adresses to the logical pin numbers is not effient on the STM8. The hole system could be changed to a more regular scheme and replace the tables by hardcoded adress calculations.


Inefficient compilation

digitalWrite compiles very ineffiently. It might be worth some hand optimization.


Accessing the alternate pin functions

Added alternateFunction() to allow switching of some pins to their alternate functions. This allows for three more PWM pins, but maybe it adds to much complexity for the Arduino API. Not sure if it should stay. Has to be enabled by defining SUPPORT_ALTERNATE_MAPPINGS.


Useful CPU features that are not supported by the Arduino API

Input-Capture-Mode: Available for all four channels, at least for timer1. Would be great for precise time measurements. Maybe build a library?
Encoder interface mode: Hardware support for reading quadrature encoder and keeping track of the current (motor) position using a hardware timer counter. Perfectly suited to all kinds of position feedback.

离线2545889167

发帖
13114
M币
20539
专家
301
粉丝
4705
只看该作者 6楼 发表于: 03-05
超级厉害,赞
离线ynymwtb

发帖
681
M币
3870
专家
10
粉丝
34
只看该作者 7楼 发表于: 03-05
avr下的arduino用户保有量大,参与维护的人多,已形成了一条完整产业链,如能把arduino下3D打印机,移植到stm下的arduino中来,通过一些接地气,接市场的产品推动,增加stm下arduino用户,参与的人多了,在stm性价比的推动下,我相信STMarduino会越来越强大。
离线se7ens

发帖
1541
M币
3038
专家
1
粉丝
25
只看该作者 8楼 发表于: 03-06
好东西啊,谢谢楼主分享
离线junyee

发帖
3977
M币
1018
专家
12
粉丝
158
只看该作者 9楼 发表于: 03-06
回 ynymwtb 的帖子
ynymwtb:avr下的arduino用户保有量大,参与维护的人多,已形成了一条完整产业链,如能把arduino下3D打印机,移植到stm下的arduino中来,通过一些接地气,接市场的产品推动,增加stm下arduino用户,参与的人多了,在stm性价比的推动下,我相信STMarduino会越来越强大。 (2018-03-05 23:31) 回 ynymwtb 的帖子

如今STM性价比不在了.

STM8S003F3P6 4元!!!