[SOLVED][STM32F407] Including C "driver" in minimal port

Discussion and questions about boards that can run MicroPython but don't have a dedicated forum.
Target audience: Everyone interested in running MicroPython on other hardware.
Post Reply
danny_h
Posts: 8
Joined: Wed Apr 03, 2019 8:10 am

[SOLVED][STM32F407] Including C "driver" in minimal port

Post by danny_h » Wed May 08, 2019 1:38 pm

I'd like to include a hardware driver to the minimal port, but first I think I should begin in a small way. So I wanted to just write a module in c, that can set the LED high but i doesn't work out.

I took the minimal set-up code that is at the bottom of the main.c file and moved everything but void stm32_init to a test.c and a test.h file. Then I created a new c-Module called Led and a function called turnOn. At the beginning of the c-Module I included test.h.

Code: Select all

#include "test.h"

[…]

STATIC mp_obj_t Led_turnOn(void) {
	gpio_init(GPIOD, 14, GPIO_MODE_OUT, GPIO_PULL_NONE, 0);
    	gpio_high(GPIOD, 14);

	return mp_const_none;
}

STATIC MP_DEFINE_CONST_FUN_OBJ_0(Led_turnOn_obj, Led_turnOn);

STATIC const mp_map_elem_t Eeprom_globals_table[]= {
	{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_Led) },
	{ MP_OBJ_NEW_QSTR(MP_QSTR_turnOn), (mp_obj_t)&Led_turnOn_obj },
};

STATIC MP_DEFINE_CONST_DICT(Led_globals, Led_globals_table);

const mp_obj_module_t Led_module = {
	.base = { &mp_type_module },
	.globals = (mp_obj_dict_t*)&Led_globals,
}; 
It compiles fine and I'm also able to use the function in the REPL, but it does not turn the led on. Also I'm still able to change the led in the main.c file, so my test.h and test.c are working fine.
Is there something, that I have to do to make the board peripherals accessable after compiling?
Last edited by danny_h on Wed Jul 17, 2019 8:14 am, edited 1 time in total.

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: [STM32F407] Including C "driver" in minimal port

Post by jimmo » Wed May 08, 2019 1:59 pm

Are you able to push your changes to github or something? Sorry I'm not quite sure I can follow what your test.c and main.c look like.

Have you enabled the port D gpio clock? Just to confirm though, when you use gpio_high(D 14) from main.c it works? And it's definitely high=on? Some boards are wired up to sink current from LEDs.

danny_h
Posts: 8
Joined: Wed Apr 03, 2019 8:10 am

Re: [STM32F407] Including C "driver" in minimal port

Post by danny_h » Wed May 08, 2019 2:26 pm

Wow what a dumb mistake... I actually missed to enable the clock for port D.
Thank you and sorry :lol:

Post Reply