2020-03-20 01:53 PM
I have the 8S105C based Discovery. I'm new to STM, but been writing NXP 9S08 assembler >20 yrs. Customer has 2 products using 9S08PA4, but needs them ported to STM8S. Both are pure assembler - I wrote them and now must port. Best of worlds would illustrate ADC, Timer and PWM aspects, but I'd be happy with just some simple GPIO and the framework to assemble, download and debug. I've looked and see all kinds of C, but only an ST7 asm example - enough different to not seem practical. Thanks in advance, Kevin (66yo newby)
2020-03-23 05:43 PM
Ok, Fine, I'll figure it out myself.
2020-03-23 11:57 PM
Not many STM8 users here, and even less that fiddle with assembler.
However, you could go the indirect route.
Take a C example, compile it, and look at the generated assembler code.
You might need to tweak the compiler settings to generate asm files at all.
2020-03-24 02:34 AM
2020-03-24 02:36 AM
I'm also training for STM8 Assembly Language coding. Hope to see your advancement.
2020-03-24 06:39 AM
Thanks for the replies, I was getting discouraged. Ozone is right in a dearth of assembler pilots. But where would OOP and 4GL flyers be without us shrubs writing device drivers and atomic little service routines where speed and size are paramount? When I started out 4MHz and 64k RAM was a big machine, so assembler was a good idea for fairly simple stuff. A steady stream of projects from colleagues and customers and it's 40 years later.
I'm just at LED blinking, ADC reading and learning the timers. But that's enough to port one project as a start. Structural stuff still confuses me; segments, including address equate files, etc. Single segment linear code may be crude, but enough for now.
Thanks, MQi.1 for the links. I'll answer stuff if I think I'm helping. Good Hunting, <<<)))
2020-03-30 01:04 PM
Hi CustomSarge!
I write my programs in assembler for STM8s. I use the asst8 & aslink assembler and linker form asxxxx (https://shop-pdp.net/ashtml/asxxxx.htm).
After you get used to it and know the instructions it can be way more fun than C. Implementing functions is really easy and can be used across multiple projects especially because of the STM8 architecture and the same type of peripherals in families.
Below a verry short example of STM8 assembler coding:
;Some definitions here...
.equ VBATT_ICORR, 36
.equ SRAM_VBATT, 0x00C4
.area MAIN_CODE (ABS,CSEG)
.org 0x008000
int RESET
int TRAP_INT
int TLI_INT
....
RESET:
;select external crystal osc.
bset CLK_SWCR, #CLK_SWCR_SWEN_bp
mov CLK_SWR, #CLK_SWR_HSE_gc
;setup port B
ld A, #(1<<BLIN_0)|(1<<BOUT_EN_1)|(1<<BHIN_2)
ld PB_DDR, A
ld PB_CR1, A
ld PB_CR2, A
;start RTC
call Start_RTC
....
Start_RTC:
;this is a function called above
;setam Frtcclk = Fmaster/128 = 18,432/128 = 144,000 kHz
mov CLK_CRTCR, #CLK_CRTCR_DIV_128_gc|CLK_CRTCR_SEL_HSE_gc
;activam Frtcclk pentru RTC
bset CLK_PCKENR2, #CLK_PCKENR2_RTC_bp
;dezactivam write protection pentru registrii RTC
mov RTC_WPR, #0xCA
mov RTC_WPR, #0x53
;intram in init mode sa putem configura RTC
bset RTC_ISR1, #RTC_ISR1_INIT_bp
.....
mov RTC_WPR, #0xFF
ret
You would need to fetch the definitions files from some compiler - if you don't want to do it manually, I hope not :) !
2020-03-30 02:54 PM
Thanks, Cristian. I'm boots-forward - read the datasheet and set the device registers accordingly.
When I was learning ('78+), library errors were all too common.
I vowed to never be held hostage to someone else's definitions / libraries.
I have the chip (8S105CxT6) doing all I need for now.
Only thing I really could use is how to get the full set of register address equates included.
I'm using the ST Visual Development assembler / linker,
I'm writing my own for now, in the NXP9S08 it was done at project generation.
There must be a way in STVD, I'm just not seeing it - but it's not a deal breaker.
It's SO refreshing to have so many addressing modes.
I learned Z80 first, went HC908 in mid '90s (colleague demanded it), then 9S08 when it came out.
But I always missed multiple index registers and Mostly indirect addressing.
I'm asking questions now, but will be answering as I get better with the STM8 series.
If there's a forum for us "bit bangers", let me know.
If not, maybe start one? It may not get a lot of traffic, but we know & do tricks compilers can't.
Thanks to All - now and as we move forward. CS
Weird - my chevrons don't show and the word hard+core is asterisked out ?
Had to sub CS & boots-forward - huh?
2024-09-08 04:56 AM
Hello! I wrote a small library for initialization UART, TIM, ADC,CLK, maybe it will be usefull for you: https://github.com/aaw20904/STM8_library/tree/main/asm
2024-10-09 04:35 AM - edited 2024-10-09 12:54 PM
Adding another link I've found helpful: https://www.circuitstate.com/tutorials/wiring-up-writing-your-first-blink-program-using-assembly-language-learn-microcontroller-with-stm8s-tutorial-part-4
Especially helpful is the discussion around addressing modes.
I'll also mention that if you're going with assembler, asxxxx is probably a better fit than sdcc. sdcc uses an outdated version of asxxxx (possibly with some modifications), and assembler-specific documentation for sdcc is present but sparse.