KT LCD3 firmware -- Flexible OpenSource firmware for Kunteng KT-LCD3

i moved to a new appartment last month so most of my hobby gear is still in boxes LOL.. so its taking longer than i hoped for.

i also remember i need to update my SDCC to version 3.7.0 right?
need to figure that out too as there is no installer.. (i am on windows)
(or just dualboot my PC so i can do this stuff on Ubuntu/linux)
 
nieles said:
i moved to a new appartment last month so most of my hobby gear is still in boxes LOL.. so its taking longer than i hoped for.

i also remember i need to update my SDCC to version 3.7.0 right?
need to figure that out too as there is no installer.. (i am on windows)
(or just dualboot my PC so i can do this stuff on Ubuntu/linux)
Use a virtual machine with Linux, that way is even faster to backup the linux installation/virtual machine. You only need access to the STLinkV2 and serial port on Linux over the virtual machine and it works really well.

Yes, SDCC 3.7.0. If you go with Linux, I can fast help you as I am also on Linux.
 
nieles said:
right, sounds good about the virtual machine! any recommendations what to use? (freeware preferable)
I tested VirtualBox and VMWare player. I got different results depending on the computer I use. Right now I am using VMWare player but I also used before VirtualBox.
 
nieles said:
maybe i'm dense but i cant figure out how to install all the required software (sdcc and binutils)
The notes I wrote point to here: https://stm8-binutils-gdb.sourceforge.io

Go step by step...
 
Almost there, implemented: lcd_print(number, ODOMETER)

[youtube]aEfVNVFy9kA[/youtube]
 
Cool to see someone hacking the KT-LCD3.
The only thing I have found my self-wanting on it is more C5 mode current options, theres only like 5 or so current levels. It would be nice if there was a wider range of around 10 to 15 levels. Also, it seems pedal assist level-5 no matter what C5-level is you have is just full current.

I don't get why people would expect/want to see Ah on the LCD or even if its theoretically possible. The live watts works fine for me.
Ah/wattmeters can be attached on your battery plug cable or between the battery and the controller.
Ah/watt meters are practically given away for next to nothing on ebay.

Good luck hackin.
 
casainho said:
Almost there, implemented: lcd_print(number, ODOMETER)

Next step is to connect to TSDZ2 LCD cable, enable/disable the motor with LCD3 on/off button and show the TSDZ2 motor current!!

Although I was able to connect KT LCD3 to TSDZ2 and show the data sent in real time from the motor controller to the LCD, unfortunately I found that motor current is not sent to LCD :-( :-(

It is really strange, there is one byte sent that is always 0. There is another that has the pedal torque sensor value. And even other that has torque sensor value and the wheel speed... there is also a flag sent when motor is running.
Why pedal torque sensor value???? Why there is no current information when LCD symbol is available to show that?? -- I wonder if the torque sensor value was used for debug while development and the product was sent to market in a hurry...
 
allright! finally got SDCC to compile, by fiddeling around with all sort of packages/options and what not..
also installed binutils and stm8flash

now when compiling the FW i get the following

Code:
make -f  Makefile_linux
make: *** No rule to make target 'StdPeriphLib/src/stm8s_iwdg.rel', needed by 'main'.  Stop.

any clue what i did wrong?
 
nieles said:
allright! finally got SDCC to compile, by fiddeling around with all sort of packages/options and what not..
also installed binutils and stm8flash

now when compiling the FW i get the following

Code:
make -f  Makefile_linux
make: *** No rule to make target 'StdPeriphLib/src/stm8s_iwdg.rel', needed by 'main'.  Stop.

any clue what i did wrong?
Most likely you are trying to use iwdg from STM8 sources lib but you need to also add to makefile, both c and h files.
 
okay, so maybe the problem is there is no src folder in the StdPeriphLib folder included in the project. do i need to copy that my self from somewhere?
 
allright, copied the src folder from the controller project and the compilation process gets a little further. still getting an error:

Code:
niels@niels-VirtualBox:~/Documents/software/Kunteng_LCD3_firmware$ make -f Makefile_linux
sdcc -c -IStdPeriphLib/inc -I.  -mstm8 -Ddouble=float --std-c99 --nolospre --out-fmt-elf --debug  -oStdPeriphLib/src/stm8s_iwdg.c StdPeriphLib/src/stm8s_iwdg.c
sdcc -c -IStdPeriphLib/inc -I.  -mstm8 -Ddouble=float --std-c99 --nolospre --out-fmt-elf --debug  -oStdPeriphLib/src/stm8s_clk.c StdPeriphLib/src/stm8s_clk.c
sdcc -c -IStdPeriphLib/inc -I.  -mstm8 -Ddouble=float --std-c99 --nolospre --out-fmt-elf --debug  -oStdPeriphLib/src/stm8s_gpio.c StdPeriphLib/src/stm8s_gpio.c
sdcc -c -IStdPeriphLib/inc -I.  -mstm8 -Ddouble=float --std-c99 --nolospre --out-fmt-elf --debug  -oStdPeriphLib/src/stm8s_adc1.c StdPeriphLib/src/stm8s_adc1.c
Warning: Non-connected liverange found and extended to connected component of the CFG:iTemp0. Please contact sdcc authors with source code to reproduce.
Warning: Non-connected liverange found and extended to connected component of the CFG:iTemp0. Please contact sdcc authors with source code to reproduce.
Warning: Non-connected liverange found and extended to connected component of the CFG:iTemp1. Please contact sdcc authors with source code to reproduce.
Warning: Non-connected liverange found and extended to connected component of the CFG:iTemp0. Please contact sdcc authors with source code to reproduce.
Warning: Non-connected liverange found and extended to connected component of the CFG:iTemp0. Please contact sdcc authors with source code to reproduce.
Warning: Non-connected liverange found and extended to connected component of the CFG:iTemp1. Please contact sdcc authors with source code to reproduce.
sdcc -c -IStdPeriphLib/inc -I.  -mstm8 -Ddouble=float --std-c99 --nolospre --out-fmt-elf --debug  -oStdPeriphLib/src/stm8s_tim1.c StdPeriphLib/src/stm8s_tim1.c
sdcc -c -IStdPeriphLib/inc -I.  -mstm8 -Ddouble=float --std-c99 --nolospre --out-fmt-elf --debug  -oStdPeriphLib/src/stm8s_tim3.c StdPeriphLib/src/stm8s_tim3.c
sdcc -c -IStdPeriphLib/inc -I.  -mstm8 -Ddouble=float --std-c99 --nolospre --out-fmt-elf --debug  -oStdPeriphLib/src/stm8s_uart2.c StdPeriphLib/src/stm8s_uart2.c
Warning: Non-connected liverange found and extended to connected component of the CFG:iTemp4. Please contact sdcc authors with source code to reproduce.
sdcc -c -IStdPeriphLib/inc -I.  -mstm8 -Ddouble=float --std-c99 --nolospre --out-fmt-elf --debug  -ogpio.c gpio.c
sdcc -c -IStdPeriphLib/inc -I.  -mstm8 -Ddouble=float --std-c99 --nolospre --out-fmt-elf --debug  -oadc.c adc.c
sdcc -c -IStdPeriphLib/inc -I.  -mstm8 -Ddouble=float --std-c99 --nolospre --out-fmt-elf --debug  -otimers.c timers.c
sdcc -c -IStdPeriphLib/inc -I.  -mstm8 -Ddouble=float --std-c99 --nolospre --out-fmt-elf --debug  -olcd.c lcd.c
Warning: Non-connected liverange found and extended to connected component of the CFG:iTemp1. Please contact sdcc authors with source code to reproduce.
sdcc -c -IStdPeriphLib/inc -I.  -mstm8 -Ddouble=float --std-c99 --nolospre --out-fmt-elf --debug  -ouart.c uart.c
sdcc -IStdPeriphLib/inc -I.  -mstm8 -Ddouble=float --std-c99 --nolospre --out-fmt-elf --debug  main.c StdPeriphLib/src/stm8s_iwdg.rel StdPeriphLib/src/stm8s_clk.rel StdPeriphLib/src/stm8s_gpio.rel StdPeriphLib/src/stm8s_adc1.rel StdPeriphLib/src/stm8s_tim1.rel StdPeriphLib/src/stm8s_tim3.rel StdPeriphLib/src/stm8s_uart2.rel gpio.rel adc.rel timers.rel lcd.rel uart.rel
main.c:156: warning 126: unreachable code
main.c:110: warning 84: 'auto' variable 'ui32_number' may be used before initialization
main.c:110: warning 84: 'auto' variable 'ui32_number' may be used before initialization
main.c:156: warning 85: in function main unreferenced local variable : 'ui16_temp'
main.c:156: warning 85: in function main unreferenced local variable : 'ui8_button_up_state'
main.c:156: warning 85: in function main unreferenced local variable : 'ui8_button_down_state'
stm8-size main.elf -A
make: stm8-size: Command not found
Makefile_linux:60: recipe for target 'main' failed
make: *** [main] Error 127
 
Seems stm8-size is not on the path. As it is only to show size of the final file, you can as a workaround comment the use of it on the makefile.
 
allright i finally got everything build and can flash firmware!

i flashed the 'test symbols' branch to my display. i am getting a few characters, but not all. starts with 'cruise' then the big 7-segment then the ODO and Temperature segments. then nothing.

i also tried the 'enable all' function. all symbols light on.

now i am figuring out what all circuits look like, what is connected. (by measuring all Via's and drawing traces on a picture) this will take me a while LOL.. will post a schematic when done.

have you yet figured out how to turn off the display with the ON/OFF key? i think it has to do with T1/T2/T3. (from what traces i have connected)
 
I can't even detect change on button on/off. Can you please give a look at pins.h on master branch and verify??

Also, you will see that I enable 2 pins at lcd_init() but I don't remember which one does what......

Look at ny latest code: odometer + assist level numbers + send to controller assist level + read motor current:

casainho said:
Assist level now works. I wanted to show the brake symbol on LCD but turns out that TSDZ2 motor control don't send the brake state to LCD :-( -- yes, I am using brakes and I really can't live with brakes connected.

0 assist level is the same as motor turned off.

NOTE: the values shown on LCD are twice of the real value due to a small mistake I did on the code.

[youtube]lGd828Sk7tk[/youtube]
 
Will have a look tonight at the gpio.h. and also once we have the schematic we can figure out how the ON/OFF button works. i think there is some sort of set/reset flipflop logic implemented with discrete components and an output pin from the processor
 
nieles said:
Will have a look tonight at the gpio.h. and also once we have the schematic we can figure out how the ON/OFF button works. i think there is some sort of set/reset flipflop logic implemented with discrete components and an output pin from the processor
I wounder if the STM8 can run even if we disable the system. Like, for counting the time between each trip and decide when to consider starting on a new trip.
 
Nieles, can I give you access to github? I will need your user id.

I added support for saving the changed variables that need to be on EEPROM (I originally developed this code for our OpenSource firmware for KT motor controllers). Assist level is now saved on EEPROM every time we changed it.

For now, this are the variables that can be saved on EEPROM:

Code:
typedef struct _configuration_variables
{
  uint8_t ui8_assist_level;
  uint8_t ui8_wheel_size;
  uint8_t ui8_max_speed;
} struct_configuration_variables;

nieles said:
dont know. but we would need a RTC (low power clock) or an wake up interrupt to do it energy efficient.

Seems the resources are available:
Time base common to auto-wakeup unit and beeper
This application note focuses on solutions using one of the following STM8S and STM8A peripherals: auto-wakeup unit or beeper. These peripherals share a common 128 kHz clock (LS clock) which can be driven either by a low speed internal RC oscillator (LSI) or by a high speed external crystal/ceramic resonator (HSE).

The LSI clock system guarantees a much lower power consumption (consumption of about 5 µA) but it has the disadvantage of being less accurate and highly temperature dependent (about ±12.5% within the whole temperature range).
 
my github username is the same as here: nieles

if you are going to save the assist level every time you change it, we might need to think about wear-leveling the EEPROM because you can only write to them only so many times. EDIT: never mind. the EEPROM has 300k cycle endurance.. more than enough. (write 50 times a day for 16 years LOL )


before starting implementation of the low-power function, wait for the schematic. last night i drawn part of the LDO power circuit, and it has resistors before the LDO to drop a certain voltage (this implies we need a minimum current not to damage the LDO) so maybe we cant do a low-power design because of this..
hopefully the schematic will be finished tomorrow, as i don't have time tonight.
 
Corrected the pin definition for ONOFF button, now it works.
 
The first part of the Schematic is done (the interesting bits LOL)

View attachment LCD3_display_V0_1.pdf

few intersting things i see:

PA2 needs to be logic HIGH to keep the LCD on. this works like a keep alive. write a low and the LDO loses power and turns off (i tested this behaviour)

with PE3 you can short part of the resistors before the LDO. i think this is to accomodate different input voltages.
we need to do some math to figure out what is possible here.
 
Back
Top