Hardware SPI is working,
Parallel is not tested,
I2C is not implemented.
Read the readme.
Tested with STM32 Nucleo 401.
Please test and give feedback.
I started here: https://github.com/olikraus/u8g2/wiki/Porting-to-new-MCU-platform.
Basically i made three files: ch_hal.c and ch_hal.h. In these files there are two functions:
uint8_t u8g2_ch_spi_byte_cb(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);
which handles all the SPI stuff including CS line,
uint8_t u8g2_ch_gpio_and_delay_cb(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);
where all initialisation takes place and all the delays are and the u8g2.mk Makefile.
Tested Displays:
Nokia 5110 - SPI
ST7920 - SPI
have fun.
u8g2 ported to ChibiOS first draft - working
Re: u8g2 ported to ChibiOS first draft - working
UPDATE:
Parallel 8-bit is also working.
Tested Displays:
T6963 Parallel,
ST7920 over SPI,
Nokia5110 over SPI.
Download the u8g2 sources from https://github.com/olikraus/u8g2 and copy the files from the csrc folder into chibios176\u8g2\src folder.
Also copy ch_hal.c/h into chibios176\u8g2\src.
Finally copy u8g2.mk into chibios176\u8g2.
Parallel 8-bit is also working.
Tested Displays:
T6963 Parallel,
ST7920 over SPI,
Nokia5110 over SPI.
Download the u8g2 sources from https://github.com/olikraus/u8g2 and copy the files from the csrc folder into chibios176\u8g2\src folder.
Also copy ch_hal.c/h into chibios176\u8g2\src.
Finally copy u8g2.mk into chibios176\u8g2.
- Attachments
-
- u8g2.zip
- (3.82 MiB) Downloaded 296 times
- Giovanni
- Site Admin
- Posts: 14457
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1076 times
- Been thanked: 922 times
- Contact:
Re: u8g2 ported to ChibiOS first draft - working
Just a note from me, about delays.
Sleep resolution depends on settings in chconf.h, the chThdSleepMicroseconds() will round up the interval to the real resolution. You may use chSysPolledDelayX() for small delays, it is very accurate being based on an HW timer. It is not present on Cortex-M0 platforms however.
Another option is to use gptPolledDelays() which is an HAL service and always available. The resolution depends on the timer setup.
Giovanni
Sleep resolution depends on settings in chconf.h, the chThdSleepMicroseconds() will round up the interval to the real resolution. You may use chSysPolledDelayX() for small delays, it is very accurate being based on an HW timer. It is not present on Cortex-M0 platforms however.
Another option is to use gptPolledDelays() which is an HAL service and always available. The resolution depends on the timer setup.
Giovanni
Re: u8g2 ported to ChibiOS first draft - working
I am trying with gptPolledDelays(), but i need one nanosecond resolution which is not possible. I came up with some macros but i need t do some testing.
For now i have in ch_hal.h:
and in ch_hal.c:
For now i have in ch_hal.h:
Code: Select all
#define F_TIM 72 //in MHz! One Tic @ 72MHz is 13.8ns
#define GPTIM GPTD4
and in ch_hal.c:
Code: Select all
#define TICS_P100 ((F_TIM/10)+1) //Tics per 100ns - rounding up
#define TIC ((1000/F_TIM)+1) //one tic in ns
static const GPTConfig gptXcfg = { //Timer for polled delay needs 1ns resolution
F_TIM*1000000,
NULL,
0,
0
};
//############################
case U8X8_MSG_DELAY_NANO: // delay arg_int * 1 nano second
//chprintf((BaseSequentialStream *)&SD2, "Delay nano: \r\n"); //DEBUG
if (arg_int > TIC){
gptPolledDelay(&GPTIM, arg_int/TIC);
}
gptPolledDelay(&GPTIM, 1);
break;
case U8X8_MSG_DELAY_100NANO: // delay arg_int * 100 nano seconds
gptPolledDelay(&GPTIM, arg_int * TICS_P100);
break;
Re: u8g2 ported to ChibiOS first draft - working
Hi,
Just my 2 cents: Nanosecond resolution ???'
How is this handled on Arduino boards at 16MHz, or even 8MHz ????
Angelo
Just my 2 cents: Nanosecond resolution ???'
How is this handled on Arduino boards at 16MHz, or even 8MHz ????
Angelo
Re: u8g2 ported to ChibiOS first draft - working
Yes, i know. On Arduino nop's are used and timed to get the desired timings. For example the E-cycle needs about 5ns minimum. If it is more, the picture is just slower renewed. For one display and one controller nop's are fine, but to be independent of hardware the timing needs to be exact.
Re: u8g2 ported to ChibiOS first draft - working
Version 0.3 is ready for testing.
Added polled delay,
tested KS0108 Display (8-bit parallel).
The timing of the KS0108 is way off! Datasheet says 450ns - in reality 2.8us are needed. I made a hack because the u8g2 lib has only 8bit for timings. I guess it wasn't a problem because slower micros need that time anyway or a few nop's are added. I made a compiler warning for KS0108 dislays to be aware of the timing problem.
Added polled delay,
tested KS0108 Display (8-bit parallel).
The timing of the KS0108 is way off! Datasheet says 450ns - in reality 2.8us are needed. I made a hack because the u8g2 lib has only 8bit for timings. I guess it wasn't a problem because slower micros need that time anyway or a few nop's are added. I made a compiler warning for KS0108 dislays to be aware of the timing problem.
- Attachments
-
- u8g2.zip
- (3.82 MiB) Downloaded 485 times
- wurstnase
- Posts: 121
- Joined: Tue Oct 17, 2017 2:24 pm
- Has thanked: 43 times
- Been thanked: 30 times
- Contact:
Re: u8g2 ported to ChibiOS first draft - working
Instead of F_TIM you could use STM32_SYSCLK or probably the one for the timer, when it is different. I guess there is somewhere a macro for it.
I'm now doing it like this
I'm now doing it like this
Code: Select all
#define fsmc_time_ns2i(ns) \
((((ns) * 1000) * (STM32_SYSCLK / 1000000) / 1000000) + 1)
#define fsmc_delay(ns) \
gptPolledDelay(&GPTD4, fsmc_time_ns2i(ns))
\o/ Nico
- wurstnase
- Posts: 121
- Joined: Tue Oct 17, 2017 2:24 pm
- Has thanked: 43 times
- Been thanked: 30 times
- Contact:
Re: u8g2 ported to ChibiOS first draft - working
Another idea is to use the continuous mode and reset the counter by yourself.
This could make the timer more accurate.
e.g.
In this case I found the specific clock frequency. It can be found in GPTDx->clock.
This could make the timer more accurate.
e.g.
Code: Select all
void init_somewhere(void) {
/* check your timer. this can be 16bit or 32bit */
gptStartContinuous(&GPTD4, 0xFF);
}
void doint_things(void) {
gptGetCounterX(&GPTD4) = 0;
timing_critical_stuff(); //done in e.g. ~10 ticks
/* timing stuff done in 10 ticks. We want to wait 100ns */
while(gptGetCounterX(&GPTD4) <= (10 + GPTD4_TIME_NS2I(100)));
go_ahead();
}
In this case I found the specific clock frequency. It can be found in GPTDx->clock.
\o/ Nico
Re: u8g2 ported to ChibiOS first draft - working
Thank you for your suggestions. I think until there is some feedback from somebody who actually needs this and the timing problem with ks0108 display is addressed from the u8g2 developer i won't change the code again. Furthermore are this small patches, easily added. The "framework" is functional and should help anybody getting started quickly.
Who is online
Users browsing this forum: No registered users and 29 guests