Page 1 of 1

Serial on Mikromedia Plus STM32

Posted: Sun Jun 12, 2016 10:12 pm
by dhq
Hi,

I am using a Mikromedia Plus for STM32. I managed to get two LED's to blink using ChibiOS. The timing is correct

I have been trying to get the serial driver working on it by adapting the demo code for STM32F4 discovery but it's not working.
(I have tested the HAl test code on the Discovery board and know that it is working)

Here is the (non-working) UART code I have right now adapted from Mikromedia board.h files :


sdStart(&SD2, NULL);
palSetPadMode(GPIOC, GPIOC_HDR_UART2_TX, PAL_MODE_ALTERNATE(8));
palSetPadMode(GPIOC, GPIOC_HDR_UART2_RX, PAL_MODE_ALTERNATE(8));

chprintf((BaseSequentialStream *)&SD2, "SYSCLK=%u\r\n", STM32_SYSCLK);


A couple of questions:

1) Do I have to write the linker scipt myself for this new chip or does ChibiOS takes care of the various STM32 families.
2) The only difference I see apart from the pin changes is that this board uses an STM32F407ZG clocked from
a 25Mhz running at 150Mhz (HSS+PLL) while the STM32F4 discovery runs at 168MHz using an 8MHz clock.
How would I change the Serial driver clock from the ChibiOS API.

Here are the current clock settings. I cannot use the USB serial since it complains about the 48Mhz clock.

#define STM32_NO_INIT FALSE
#define STM32_HSI_ENABLED TRUE
#define STM32_LSI_ENABLED TRUE
#define STM32_HSE_ENABLED TRUE
#define STM32_LSE_ENABLED TRUE
#define STM32_CLOCK48_REQUIRED TRUE
#define STM32_SW STM32_SW_PLL
#define STM32_PLLSRC STM32_PLLSRC_HSE
#define STM32_PLLM_VALUE 16
#define STM32_PLLN_VALUE 192
#define STM32_PLLP_VALUE 2
#define STM32_PLLQ_VALUE 6
#define STM32_HPRE STM32_HPRE_DIV1
#define STM32_PPRE1 STM32_PPRE1_DIV4
#define STM32_PPRE2 STM32_PPRE2_DIV2
#define STM32_RTCSEL STM32_RTCSEL_LSE
#define STM32_RTCPRE_VALUE 8
#define STM32_MCO1SEL STM32_MCO1SEL_PLL
#define STM32_MCO1PRE STM32_MCO1PRE_DIV3
#define STM32_MCO2SEL STM32_MCO2SEL_SYSCLK
#define STM32_MCO2PRE STM32_MCO2PRE_DIV1
#define STM32_I2SSRC STM32_I2SSRC_CKIN
#define STM32_PLLI2SN_VALUE 192
#define STM32_PLLI2SR_VALUE 5
#define STM32_PVD_ENABLE FALSE
#define STM32_PLS STM32_PLS_LEV0
#define STM32_BKPRAM_ENABLE FALSE


Any pointers would be appreciated.

Demeter

Re: Serial on Mikromedia Plus STM32

Posted: Mon Jun 13, 2016 8:11 am
by Giovanni
Hi,

1) Linker scripts for many STM32 devices are included, creating a new one often mean changing a couple of lines (RAM-flash sizes).

2) In order to use USB you need a 48MHz clock, you cannot have that starting from a 150MHz clock, set the clock to 168 using the Discovery board settings then just change the value of the input divider in order to correctly support the 25MHz oscillator.

Serial clocks are handled by those PPRE1 PPRE2 dividers, see the STM32 reference manual. Baud rates are set in the serial driver configuration structure.

Giovanni

Re: Serial on Mikromedia Plus STM32

Posted: Mon Jun 13, 2016 8:13 am
by RoccoMarco
About linker script you can use STM32F407xG.ld

You have to create board files. Note that HSI is 25MHz. I made something similar few time ago. I wrote an article and I hope this could be useful.
Different board but same principles
Getting started with mikroe Clicker 2 for STM32 with ChibiOS
Ciao,
RM

EDIT: Giovanni has summarized well all the little problems you have to face. In the article there are some references to documentation and code which will help you.

Re: Serial on Mikromedia Plus STM32

Posted: Mon Jun 13, 2016 2:03 pm
by dhq
Hi,

@Giovanni

Thanks, I changed the clock settings by using the ST Excel sheet.

#define STM32_NO_INIT FALSE
#define STM32_HSI_ENABLED FALSE
#define STM32_LSI_ENABLED FALSE
#define STM32_HSE_ENABLED TRUE
#define STM32_LSE_ENABLED TRUE
#define STM32_CLOCK48_REQUIRED TRUE
#define STM32_SW STM32_SW_PLL
#define STM32_PLLSRC STM32_PLLSRC_HSE
#define STM32_PLLM_VALUE 25
#define STM32_PLLN_VALUE 336
#define STM32_PLLP_VALUE 2
#define STM32_PLLQ_VALUE 7
#define STM32_HPRE STM32_HPRE_DIV1
#define STM32_PPRE1 STM32_PPRE1_DIV4
#define STM32_PPRE2 STM32_PPRE2_DIV2


With these values the USB serial shell works.

I still cannot get the serial UART port 1 or 2 to work however.
I only get a single <0> on the terminal once the program starts.

I checked the baud rate.
I checked the serial to USB port and it is working.
I have enabled the serial on the HAL and MCUCONF.

@RoccoMarco

uGX seems to have a ready made board configuration file for Mikromedia plus so I "stole" if from there.
The HSI clock is disabled in my code.

I checked the article you suggested but still no dice.


At present I have reduced it to a simple test program that blinks an LED and sends the following;

sdStart(&SD2, NULL);
palSetPadMode(GPIOC, GPIOC_HDR_UART2_TX, PAL_MODE_ALTERNATE(7));
palSetPadMode(GPIOC, GPIOC_HDR_UART2_RX, PAL_MODE_ALTERNATE(7));
chprintf((BaseSequentialStream *)&SD2, "SYSCLK=%u\r\n", STM32_SYSCLK);



This seems to be the same MCU that is used in one of the OLIMEX boards.

The board is new so I don't think it is a hardware problem.
I can't think of anything else at present so I am kind of baffled.


Best,
Demeter

Re: Serial on Mikromedia Plus STM32

Posted: Mon Jun 13, 2016 3:25 pm
by Giovanni
Probably a problem with pins setup, the serial driver is ages old.

Giovanni

Re: Serial on Mikromedia Plus STM32

Posted: Tue Jun 14, 2016 7:36 am
by RoccoMarco
Hi,
Note that HDR_UART2_TX and HDR_UART2_RX are the name of board PINs. Actually on PC6 and PC7 there is USART6 using AF8.

Code should be

Code: Select all

sdStart(&SD6, NULL);
palSetPadMode(GPIOC, GPIOC_HDR_UART2_TX, PAL_MODE_ALTERNATE(8));
palSetPadMode(GPIOC, GPIOC_HDR_UART2_RX, PAL_MODE_ALTERNATE(8));   
chprintf((BaseSequentialStream *)&SD6, "SYSCLK=%u\r\n", STM32_SYSCLK);

Ciao,
RM

Re: Serial on Mikromedia Plus STM32

Posted: Thu Jun 16, 2016 1:44 am
by dhq
:o Major facepalm.

That was it. It is working right now. Thank you very much.
I had exactly the same program on STM32 discovery with the exception of the pin names.

Re: Serial on Mikromedia Plus STM32

Posted: Thu Jun 16, 2016 7:30 am
by rew
RoccoMarco wrote:Code should be

Code: Select all

sdStart(&SD6, NULL);
palSetPadMode(GPIOC, GPIOC_HDR_UART2_TX, PAL_MODE_ALTERNATE(8));
palSetPadMode(GPIOC, GPIOC_HDR_UART2_RX, PAL_MODE_ALTERNATE(8));   
chprintf((BaseSequentialStream *)&SD6, "SYSCLK=%u\r\n", STM32_SYSCLK);
So I'll say it again, there should be a define for such things. People have the "random numbers" in their code now, that 7/8 is easy to discard as "some number, hope it will work" while when moving from GPIOB to GPIOC and from uart5 to uart 6, the PAL_AF_GPIOB_UART5 will stick out....