STM8S103F3 Development Board (HCDVBD0034)

ST Microelectronics microcontroller development boards and accessories
Alfredo
Posts: 23
Joined: Sat May 13, 2017 12:43 pm

Re: STM8S103F3 Development Board (HCDVBD0034)

Post by Alfredo » Sat Jul 08, 2017 8:07 pm

Now it's just a small step to playing a tune in the background:

* a words to represent musical notes
* maybe some kind of ADSR simulation using the PWM duty cycle
* some kind of action table
* a background task that interprets the action table

Actions can also be percussion elements, e.g. an annoy beep from the buzzer output. In Forth anything goes!

barewires
Posts: 49
Joined: Wed Aug 21, 2013 7:38 am

Re: STM8S103F3 Development Board (HCDVBD0034)

Post by barewires » Sat Sep 16, 2017 5:26 pm

Any ideas on calibrating TIM1 to give more accurate frequencies? 32kHz = 31.75

Alfredo
Posts: 23
Joined: Sat May 13, 2017 12:43 pm

Re: STM8S103F3 Development Board (HCDVBD0034)

Post by Alfredo » Tue Sep 19, 2017 7:08 pm

31.75kHz is within 0.8% of 32kHz. Application note AN2822 describes calibration procedures for the internal oscillator. The calibration steps are 1%: in your case decreasing CLK_HSITRIMR by one would reduce the error to 0.2%. If your application needs better accuracy you either need a reference frequency, or a crystal.

barewires
Posts: 49
Joined: Wed Aug 21, 2013 7:38 am

Re: STM8S103F3 Development Board (HCDVBD0034)

Post by barewires » Tue Sep 19, 2017 11:44 pm

Cool, I will try that. I do have perfect pitch so it should be more tolerable.
Trimming the clock does now seem to work on another chip. :shock: On certain chips it didn't. :?:

I now use
ls ~/Desktop/Forth/HSI.f and then copy the confirmed file name and paste it.

This file is loaded in picocom with ctrl-A ctrl-S ~/Desktop/Forth/HSI.f

\ contents of HSI.f
\ Pin PC3 trim freq and confirm register readback at 16 kHz
\ I previously used, say f7 as frequency7, as a word. This was confusing as it was valid hex and a word, so a potential future programming conflict.

FILE \ note no longer a supported word
NVM
: CLK_HSITRIMR $50CC ;
: z3 CLK_HSITRIMR C! CLK_HSITRIMR C@ . ; \ 15.45 lowest freq
: z2 CLK_HSITRIMR C! CLK_HSITRIMR C@ . ; \ 15.52
: z1 CLK_HSITRIMR C! CLK_HSITRIMR C@ . ; \ 15.70
: z0 CLK_HSITRIMR C! CLK_HSITRIMR C@ . ; \ 15.87 kHz reset value
: z7 CLK_HSITRIMR C! CLK_HSITRIMR C@ . ; \ 16.05
: z6 CLK_HSITRIMR C! CLK_HSITRIMR C@ . ; \ 16.24
: z5 CLK_HSITRIMR C! CLK_HSITRIMR C@ . ; \ 16.43
: z4 CLK_HSITRIMR C! CLK_HSITRIMR C@ . ; \ 16.62 highest freq
: cx $50C0 $F dump ;
RAM
HAND \ note no longer a supported word
initTIM1
decimal
16000 Hz
z6 <enter> 6 ok

Three-bit two's-complement integers
Bits, Unsigned value, Two's complement value

011 3  3 
010 2  2 
001 1  1 
000 0  0 
111 7  −1 
110 6  −2 
101 5  −3 
100 4  −4 

https://en.wikipedia.org/wiki/Two%27s_complement
Last edited by barewires on Fri Oct 06, 2017 2:39 pm, edited 2 times in total.

barewires
Posts: 49
Joined: Wed Aug 21, 2013 7:38 am

Re: STM8S103F3 Development Board (HCDVBD0034)

Post by barewires » Sat Sep 30, 2017 2:31 pm

Debugging the STM8S is easy to do by dumping the contents of blocks of data within the memory map.

words
IRET SAVEC RESET RAM NVM LOCK ULOCK ADC@ ADC! WORDS .S DUMP ALLOT VARIABLE CREATE DOES> ] IMMEDIATE : ; OVERT ." $" ABORT" AFT REPEAT WHILE AHEAD ELSE THEN IF AGAIN UNTIL BEGIN +LOOP LOOP DO NEXT FOR COMPILE [COMPILE] LITERAL CALL, C, , ' [ NAME> \ ( .( ? . U. TYPE U.R .R CR SPACES SPACE KEY DECIMAL HEX <# SIGN HOLD #S # #> ERASE FILL CMOVE HERE COUNT +! DEPTH PICK 0= ABS NEGATE NOT 1+ 1- 2+ 2- 2* 2/ EXG */ */MOD M* * UM* / MOD /MOD M/MOD UM/MOD WITHIN MIN MAX < U< = DNEGATE 2DUP ROT ?DUP BG TIM BL OUT last '?KEY 'EMIT BASE - 0< OR AND XOR + UM+ I OVER SWAP DUP 2DROP DROP NIP >R R@ R> C! C@ ! @ B! 2C@ 2C! 2@ 2! EXIT EXECUTE LEAVE EMIT ?KEY TX! ?RX hi 'BOOT OUT! COLD ok

\ real programmers only use hex (or octal or binary) ;)
https://xkcd.com/378/
https://explainxkcd.com/378/
https://www.youtube.com/watch?v=UIKGV2cTgqA
Remember octal is just like decimal - if you're missing two fingers.

: ramdump 0 $3FF dump ; \ for S003 and S103 only

Words can be decoded by:
hex
' ramdump . 9B58 ok

' called TICK gives the address of the machine code associated with the word and prints it with dot . It is always best to give your dump a spread before and after to see the full context. $ is hex and it shows the code beginning at $9B58 as 83 0 0 ...
Now look at the value before 'ramdump' and you will see it is 7 which is the number of bytes in the word 'ramdump.'

This area of flash is called the dictionary. Anything typed into eForth OS command line is interpreted immediately as a previous word command, a number or discarded. Colon begins a new word and semicolon ends it, the compiler then stores the new word in flash or RAM which then adds it to the dictionary.

\ the DUMP command needs to be fixed to show byte leading zeros and the html spacing here is bad. DUMP also displays 16 bytes per line regardless of desired length. Data shown here will vary by version.

$9B40 3F dump
9B40 64 75 6D 70 83 48 0 83 0 A CD 91 16 81 9B 3C dump_H____M____<
9B50 7 72 61 6D 64 75 6D 70 83 0 0 83 3 FF CD 91 _ramdump______M_
9B60 16 81 9B 50
A 69 6E 74 76 65 63 74 6F 72 73 83 ___P_intvectors_
9B70 80 0 83 0 7F CD 91 16 81 9B 64 6 62 75 66 66 _____M____d_buff ok

eForth is too small to store the source code so it is best to keep a text file in a project directory or folder. Using picocom the command ctrl-a ctrl-s will ask for the file name to be loaded.

In a text console I like to print out the file name to be sure.
ls /home/pi/Desktop/ForthPidrive/dumps.f
/home/pi/Desktop/ForthPidrive/dumps.f
Then I copy the details and paste it into the eForth command.

NVM or nvm (Forth doesn't care) puts the following code into Non Volatile Memory = flash. RAM then restores new input default into RAM or ram.

NVM
: ww words ;
: uniqid $4865 $0C dump ;
: eedump $4000 $27F dump ;
: optdump $4800 $0A dump ;
: ramdump 0 $3FF dump ;
: intvectors $8000 $7F dump ;
: buffer $350 $4F dump ;
: flashdump $8080 $1EFF dump ;
: gpiodump $5000 $7FF dump ;
: alldump CR uniqid CR eedump CR optdump CR intvectors CR gpiodump
CR buffer CR ramdump CR flashdump CR ;
RAM

Here CR is an eForth word equal to carriage return. eForth only has an 80 character buffer so it is required to separate long lines. Of course all commands are separated by space.

Debugging in this manner is exactly like it was done in the mid 60s to late 70s if one couldn't afford a development system or computer then the price of a house or two.

The beauty of eForth means that once the target has been blasted, one can throw away the source system like the Billion Dollar Brain (terrible movie) or in Tron, the MCP no longer is needed - End of Line.

MCP is in no way related to the 5 year old who passed the Miracle Soft exams. This is, after all, about real computing.
http://www.bbc.co.uk/news/technology-30054140

Non of this would be possible without the twisted minds of: Chuck, Thomas and C.H. Ting and others.
https://github.com/TG9541/stm8ef/wiki
https://hackaday.io/project/16097-efort ... 8s-gadgets
https://hackaday.io/project/18286-misc- ... 8-stm8s003
http://www.greenarraychips.com/home/about/bios.html
Last edited by barewires on Mon Oct 23, 2017 9:33 am, edited 4 times in total.

barewires
Posts: 49
Joined: Wed Aug 21, 2013 7:38 am

Re: STM8S103F3 Development Board (HCDVBD0034)

Post by barewires » Wed Oct 18, 2017 4:46 pm

Running eForth on many of HC STM8S products, I highly recommend Thomas' excellent project.
https://github.com/TG9541/stm8ef

NVM
: eedump $4000 $27F dump ;
RAM
HEX
eedump
4000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ________________
...
4270 4F 43 54 31 37 20 32 30 31 37 0 32 32 31 37 0 OCT17 2017_2217_ ok

When I blast the chips with eForth I place the text date and version number in high eeprom.
There is currently no way to see which version is loaded but I have requested this feature. I need the sub-minor number added.
hi
stm8eForth v2.2
ok
One day it will hopefully be:
stm8eForth v2.2.17

Filling eeprom requires unlocking memory.
ULOCK
4000 26F 41 FILL \ note FILL does not write to the final location, bug or feature?

eedump
4000 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 AAAAAAAAAAAAAAAA
...
4260 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 0 AAAAAAAAAAAAAAA_
4270 4F 43 54 31 37 20 32 30 31 37 0 32 32 31 37 0 OCT17 2017_2217_ ok

The beauty of eForth is being able to change built-in words to suit, by adding new words for testing or even over-writing factory words.
HEX
NVM
: myfill ULOCK SWAP 1 + SWAP FILL eedump LOCK ;
RAM
4000 26F 39 myfill

LOCK \ when finally done writing to eeprom

Alfredo
Posts: 23
Joined: Sat May 13, 2017 12:43 pm

Re: STM8S103F3 Development Board (HCDVBD0034)

Post by Alfredo » Wed Oct 25, 2017 5:22 am

Filling eeprom requires unlocking memory.
ULOCK
4000 26F 41 FILL \ note FILL does not write to the final location, bug or feature?
Hi barewires, that's a feature. The byte at the start address (0) is also counted (FILL does the same as memset() in C ):
; FILL ( b u c -- )
; Fill u bytes of character c
; to area beginning at b.
To fill a memory area you need the start address, and the number of bytes, or the address of the first byte in the next memory area, e.g.

Code: Select all

: params $4000 ;
: states $4700 ;
: params.init ULOCK params states OVER - 0 FILL LOCK ;

Alfredo
Posts: 23
Joined: Sat May 13, 2017 12:43 pm

Re: STM8S103F3 Development Board (HCDVBD0034)

Post by Alfredo » Wed Oct 25, 2017 5:22 am

Filling eeprom requires unlocking memory.
ULOCK
4000 26F 41 FILL \ note FILL does not write to the final location, bug or feature?
Hi barewires, that's a feature. The byte at the start address (0) is also counted (FILL does the same as memset() in C ):
; FILL ( b u c -- )
; Fill u bytes of character c
; to area beginning at b.
To fill a memory area you need the start address, and the number of bytes, or the address of the first byte in the next memory area, e.g.

Code: Select all

: params $4000 ;
: states $4700 ;
: params.init ULOCK params states OVER - 0 FILL LOCK ;

barewires
Posts: 49
Joined: Wed Aug 21, 2013 7:38 am

Re: STM8S103F3 Development Board (HCDVBD0034)

Post by barewires » Wed Oct 25, 2017 2:47 pm

I believe that I already gave that solution in my last post. I ask rhetorical questions to get new learners thinking about it, not to ask experts for help.
Filling or erasing is easier to have a start and end address inclusive, not by wondering where the last byte will end up.
NVM
: myfill ULOCK SWAP 1 + SWAP FILL eedump LOCK ;
RAM
4000 26F 39 myfill

Alfredo
Posts: 23
Joined: Sat May 13, 2017 12:43 pm

Re: STM8S103F3 Development Board (HCDVBD0034)

Post by Alfredo » Wed Oct 25, 2017 5:31 pm

OK, that I'll just leave my post as a rhetorical answer :lol:

Post Reply

Return to “ST Microelectronics”