From 0e9bbd3f630963517f358885a8e582a589bb86b3 Mon Sep 17 00:00:00 2001 From: James Snyder Date: Wed, 28 Aug 2013 16:24:39 -0500 Subject: [PATCH 1/4] migrate enc module to stm32f4 --- src/platform/stm32f4/build_config.lua | 4 +- src/platform/stm32f4/conf.lua | 2 +- src/platform/stm32f4/enc.c | 90 +++++++++++++++++++++++++++ src/platform/stm32f4/enc.h | 9 +++ 4 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 src/platform/stm32f4/enc.c create mode 100644 src/platform/stm32f4/enc.h diff --git a/src/platform/stm32f4/build_config.lua b/src/platform/stm32f4/build_config.lua index 3654a8dc..c0a61e34 100644 --- a/src/platform/stm32f4/build_config.lua +++ b/src/platform/stm32f4/build_config.lua @@ -8,6 +8,7 @@ local comps = require "components" -- Add specific components to the 'components' table function add_platform_components( t, board, cpu ) t.cdc = comps.cdc_uart() + t.stm32_enc = { macro = 'ENABLE_ENC' } end -- Add specific configuration to the 'configs' table @@ -26,6 +27,7 @@ end -- Return an array of all the available platform modules for the given cpu function get_platform_modules( board, cpu ) return { pio = { lib = '"pio"', map = "stm32_pio_map", open = false }, - cpu = { lib = '"cpu"', map = "stm32_cpu_map", open = "luaopen_stm32_cpu" } } + cpu = { lib = '"cpu"', map = "stm32_cpu_map", open = "luaopen_stm32_cpu" }, + enc = { guards = { 'ENABLE_ENC' }, lib = '"enc"' } } end diff --git a/src/platform/stm32f4/conf.lua b/src/platform/stm32f4/conf.lua index 7589646a..5c2c5fea 100644 --- a/src/platform/stm32f4/conf.lua +++ b/src/platform/stm32f4/conf.lua @@ -9,7 +9,7 @@ addi( sf( 'src/platform/%s/FWLib/USB/VCP/inc', platform ) ) local fwlib_files = utils.get_files( "src/platform/" .. platform .. "/FWLib/library/src", ".*%.c$" ) fwlib_files = fwlib_files .. " " .. utils.get_files( "src/platform/" .. platform .. "/FWLib/USB/", "%.c$" ) -specific_files = "system_stm32f4xx.c startup_stm32f4xx.s stm32f4xx_it.c platform.c platform_int.c cpu.c stm32_pio.c" +specific_files = "system_stm32f4xx.c startup_stm32f4xx.s stm32f4xx_it.c platform.c platform_int.c cpu.c stm32_pio.c enc.c" local ldscript = "stm32.ld" -- Prepend with path diff --git a/src/platform/stm32f4/enc.c b/src/platform/stm32f4/enc.c new file mode 100644 index 00000000..b660aba2 --- /dev/null +++ b/src/platform/stm32f4/enc.c @@ -0,0 +1,90 @@ +// eLua Module for STM32 timer encoder mode support +// enc is a platform-dependent (STM32) module, that binds to Lua the basic API +// from ST + +#include "lua.h" +#include "lualib.h" +#include "lauxlib.h" +#include "platform.h" +#include "lrotable.h" +#include "platform_conf.h" +#include "auxmods.h" +#include "elua_int.h" +#include "enc.h" + +static elua_int_c_handler prev_handler; +static elua_int_resnum index_resnum; +static int index_tmr_id; +static u16 index_count; +static void index_handler( elua_int_resnum resnum ); + +//Lua: init(id) +static int enc_init( lua_State *L ) +{ + unsigned id; + + id = luaL_checkinteger( L, 1 ); + MOD_CHECK_ID( timer, id ); + stm32_enc_init( id ); + return 0; +} + +//Lua: setcounter(id, count) +static int enc_set_counter( lua_State *L ) +{ + unsigned id, count; + + id = luaL_checkinteger( L, 1 ); + MOD_CHECK_ID( timer, id ); + count = luaL_checkinteger( L, 2 ); + + stm32_enc_set_counter( id, count ); + return 0; +} + +//Lua: setidxtrig( id, resnum, tmr_id, count ) +static int enc_set_index_handler( lua_State *L ) +{ + elua_int_id id; + + id = ( elua_int_id )luaL_checkinteger( L, 1 ); + if( id < ELUA_INT_FIRST_ID || id > INT_ELUA_LAST ) + return luaL_error( L, "invalid interrupt ID" ); + index_resnum = ( elua_int_resnum )luaL_checkinteger( L, 2 ); + index_tmr_id = luaL_checkinteger( L, 3 ); + MOD_CHECK_ID( timer, index_tmr_id ); + index_count = ( u16 )luaL_checkinteger( L, 4 ); + + platform_cpu_set_interrupt( id, index_resnum, PLATFORM_CPU_ENABLE ); + prev_handler = elua_int_set_c_handler( id, index_handler ); +} + +static void index_handler( elua_int_resnum resnum ) +{ + if( prev_handler ) + prev_handler; + + if( resnum != index_resnum ) + return; + + stm32_enc_set_counter( index_tmr_id, index_count ); +} + + +#define MIN_OPT_LEVEL 2 +#include "lrodefs.h" + +// Module function map +const LUA_REG_TYPE enc_map[] = +{ + { LSTRKEY( "init" ), LFUNCVAL( enc_init ) }, + { LSTRKEY( "setcounter" ), LFUNCVAL( enc_set_counter ) }, + { LSTRKEY( "setidxtrig" ), LFUNCVAL( enc_set_index_handler ) }, + { LNILKEY, LNILVAL } +}; + +LUALIB_API int luaopen_enc( lua_State *L ) +{ + LREGISTER( L, AUXLIB_ENC, enc_map ); +} + diff --git a/src/platform/stm32f4/enc.h b/src/platform/stm32f4/enc.h new file mode 100644 index 00000000..c20c9339 --- /dev/null +++ b/src/platform/stm32f4/enc.h @@ -0,0 +1,9 @@ +// STM32 encoder support + +#ifndef __ENC_H__ +#define __ENC_H__ + +void stm32_enc_init( unsigned id ); +void stm32_enc_set_counter( unsigned id, unsigned count ); + +#endif From 9b3c8e6eba596684daea502a0c90bde26c5f717f Mon Sep 17 00:00:00 2001 From: James Snyder Date: Mon, 11 Nov 2013 12:30:28 -0600 Subject: [PATCH 2/4] correct platform naming --- src/platform/stm32f4/build_config.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platform/stm32f4/build_config.lua b/src/platform/stm32f4/build_config.lua index c0a61e34..35ac386b 100644 --- a/src/platform/stm32f4/build_config.lua +++ b/src/platform/stm32f4/build_config.lua @@ -8,7 +8,7 @@ local comps = require "components" -- Add specific components to the 'components' table function add_platform_components( t, board, cpu ) t.cdc = comps.cdc_uart() - t.stm32_enc = { macro = 'ENABLE_ENC' } + t.stm32f4_enc = { macro = 'ENABLE_ENC' } end -- Add specific configuration to the 'configs' table From b9e5096027a86f85afe518d8fe5915bab111d1e2 Mon Sep 17 00:00:00 2001 From: James Snyder Date: Mon, 11 Nov 2013 13:43:05 -0600 Subject: [PATCH 3/4] Include remaining platform modules when some fail guards --- config/modules.lua | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/config/modules.lua b/config/modules.lua index 94b31fd2..ff50410d 100644 --- a/config/modules.lua +++ b/config/modules.lua @@ -195,10 +195,13 @@ function gen_module_list( desc, plconf, platform, boardname ) -- platform module if _any_ of the modules in gen_list_platform can be enabled. -- In order to do this, we gather their guards in a single, long condition -- Count all guards first - local nguards = 0 + local nguards, nmodules = 0, 0 local pltabname = mdesc.platform_name or platform - for m, _ in pairs( gen_list_platform ) do nguards = nguards + #( platform_modules[ m ].guards or {} ) end - if nguards == 0 then -- nothing to guard + for m, _ in pairs( gen_list_platform ) do + nmodules = nmodules + 1 + nguards = nguards + #( platform_modules[ m ].guards or {} ) + end + if nguards == 0 or nguards < nmodules then -- nothing to guard or not all have guards gstr = gstr .. gen.print_define( "PLATFORM_MODULES_LINE", sf( '_ROM( "%s", luaopen_platform, platform_map )', pltabname ) ) gstr = gstr .. gen.print_define( "PS_LIB_TABLE_NAME", sf( '"%s"', pltabname ) ) gstr = gstr .. gen.print_define( "PLATFORM_MODULES_ENABLE" ) From df10658c56df5d05d37c391d7077a04136c93f7e Mon Sep 17 00:00:00 2001 From: James Snyder Date: Mon, 11 Nov 2013 14:27:42 -0600 Subject: [PATCH 4/4] add doc for enc module and enable for other board configs --- boards/known/stm32-e407.lua | 1 + boards/known/stm32-p407.lua | 1 + boards/known/stm32-port407z.lua | 1 + boards/known/stm32f4discovery.lua | 1 + doc/docdata.lua | 2 ++ doc/eluadoc.lua | 4 ++- doc/eluadoc/refman_ps_stm32_enc.lua | 47 +++++++++++++++++++++++++++ doc/eluadoc/refman_ps_stm32f4_enc.lua | 47 +++++++++++++++++++++++++++ doc/en/configurator.txt | 7 ++++ doc/en/modules_stm32.txt | 7 ++++ doc/en/modules_stm32f4.txt | 7 ++++ 11 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 doc/eluadoc/refman_ps_stm32_enc.lua create mode 100644 doc/eluadoc/refman_ps_stm32f4_enc.lua create mode 100644 doc/en/modules_stm32.txt create mode 100644 doc/en/modules_stm32f4.txt diff --git a/boards/known/stm32-e407.lua b/boards/known/stm32-e407.lua index 8fe7881d..22a41a7a 100644 --- a/boards/known/stm32-e407.lua +++ b/boards/known/stm32-e407.lua @@ -8,6 +8,7 @@ return { advanced_shell = true, term = { lines = 25, cols = 80 }, linenoise = { shell_lines = 10, lua_lines = 50 }, + stm32f4_enc = true, rpc = { uart = 2, speed = 115200 }, adc = { buf_size = 2 }, xmodem = true, diff --git a/boards/known/stm32-p407.lua b/boards/known/stm32-p407.lua index dcb96bbc..c761ea8d 100644 --- a/boards/known/stm32-p407.lua +++ b/boards/known/stm32-p407.lua @@ -8,6 +8,7 @@ return { advanced_shell = true, term = { lines = 25, cols = 80 }, linenoise = { shell_lines = 10, lua_lines = 50 }, + stm32f4_enc = true, rpc = { uart = 2, speed = 115200 }, adc = { buf_size = 2 }, xmodem = true, diff --git a/boards/known/stm32-port407z.lua b/boards/known/stm32-port407z.lua index 494c2453..4976e981 100644 --- a/boards/known/stm32-port407z.lua +++ b/boards/known/stm32-port407z.lua @@ -8,6 +8,7 @@ return { advanced_shell = true, term = { lines = 25, cols = 80 }, linenoise = { shell_lines = 10, lua_lines = 50 }, + stm32f4_enc = true, rpc = { uart = 0, speed = 115200 }, adc = { buf_size = 2 }, xmodem = true, diff --git a/boards/known/stm32f4discovery.lua b/boards/known/stm32f4discovery.lua index 852513ce..ea737c9a 100644 --- a/boards/known/stm32f4discovery.lua +++ b/boards/known/stm32f4discovery.lua @@ -9,6 +9,7 @@ return { advanced_shell = true, term = { lines = 25, cols = 80 }, linenoise = { shell_lines = 10, lua_lines = 50 }, + stm32f4_enc = true, rpc = { uart = 0, speed = 115200 }, adc = { buf_size = 2 }, xmodem = true, diff --git a/doc/docdata.lua b/doc/docdata.lua index 032b48a1..af8fc580 100644 --- a/doc/docdata.lua +++ b/doc/docdata.lua @@ -245,6 +245,8 @@ local menu = { { "lm3s", "modules_lm3s.html", "refman_ps_lm3s" }, { "str9", "modules_str9.html", "refman_ps_str9" }, + { "stm32", "modules_stm32.html", "refman_ps_stm32" }, + { "stm32f4", "modules_stm32f4.html", "refman_ps_stm32f4" }, { "mbed", "modules_mbed.html", "refman_ps_mbed" }, { "mizar32", "modules_mizar32.html", "refman_ps_mizar32" }, } diff --git a/doc/eluadoc.lua b/doc/eluadoc.lua index 28a89841..4fdc611a 100644 --- a/doc/eluadoc.lua +++ b/doc/eluadoc.lua @@ -9,7 +9,7 @@ local sf = string.format -- Data structure declarations -- List here all the sections for which we're generating the documentation -local doc_sections = { "arch_platform", "refman_gen", "refman_ps_lm3s", "refman_ps_str9", "refman_ps_mbed", "refman_ps_mizar32" } +local doc_sections = { "arch_platform", "refman_gen", "refman_ps_lm3s", "refman_ps_str9", "refman_ps_stm32", "refman_ps_stm32f4", "refman_ps_mbed", "refman_ps_mizar32" } -- List here all the components of each section local components = @@ -19,6 +19,8 @@ local components = refman_ps_lm3s = { "disp" }, refman_ps_str9 = { "pio" }, refman_ps_mbed = { "pio" }, + refman_ps_stm32 = { "enc" }, + refman_ps_stm32f4 = { "enc" }, refman_ps_mizar32 = { "lcd", "rtc" }, } diff --git a/doc/eluadoc/refman_ps_stm32_enc.lua b/doc/eluadoc/refman_ps_stm32_enc.lua new file mode 100644 index 00000000..2614b462 --- /dev/null +++ b/doc/eluadoc/refman_ps_stm32_enc.lua @@ -0,0 +1,47 @@ +-- eLua reference manual - platform data + +data_en = +{ + + -- Title + title = "eLua reference manual - STM32 enc module", + + -- Menu name + menu_name = "enc", + + -- Overview + overview = [[This module contains functions to set up and use timers in quadrature encoder mode.]], + + -- Functions + funcs = + { + { sig = "#stm32.enc.init#( id )", + desc = "Configure the timer in quadrature mode.", + args = + { + "$id$ - the timer ID" + } + }, + { sig = "#stm32.enc.setcounter#( id, count )", + desc = "Set the current count on a timer.", + args = + { + "$id$ - the timer ID", + "$count$ - value to set counter to" + } + }, + { sig = "#stm32.enc.setidxtrig#( id, resnum, tmr_id, count )", + desc = "Set up a trigger to set the counter to a specific value when an interrupt is triggered", + args = + { + "$id$ - the interrupt ID", + "$resnum$ - resource ID associated with interrupt", + "$tmr_id$ - the timer ID", + "$count$ - value to set counter to when triggered" + } + }, + + }, +} + +data_pt = data_en diff --git a/doc/eluadoc/refman_ps_stm32f4_enc.lua b/doc/eluadoc/refman_ps_stm32f4_enc.lua new file mode 100644 index 00000000..68d6f2df --- /dev/null +++ b/doc/eluadoc/refman_ps_stm32f4_enc.lua @@ -0,0 +1,47 @@ +-- eLua reference manual - platform data + +data_en = +{ + + -- Title + title = "eLua reference manual - STM32F4 enc module", + + -- Menu name + menu_name = "enc", + + -- Overview + overview = [[This module contains functions to set up and use timers in quadrature encoder mode.]], + + -- Functions + funcs = + { + { sig = "#stm32f4.enc.init#( id )", + desc = "Configure the timer in quadrature mode.", + args = + { + "$id$ - the timer ID" + } + }, + { sig = "#stm32f4.enc.setcounter#( id, count )", + desc = "Set the current count on a timer.", + args = + { + "$id$ - the timer ID", + "$count$ - value to set counter to" + } + }, + { sig = "#stm32f4.enc.setidxtrig#( id, resnum, tmr_id, count )", + desc = "Set up a trigger to set the counter to a specific value when an interrupt is triggered", + args = + { + "$id$ - the interrupt ID", + "$resnum$ - resource ID associated with interrupt", + "$tmr_id$ - the timer ID", + "$count$ - value to set counter to when triggered" + } + }, + + }, +} + +data_pt = data_en diff --git a/doc/en/configurator.txt b/doc/en/configurator.txt index 927a0a3c..be67a2a4 100644 --- a/doc/en/configurator.txt +++ b/doc/en/configurator.txt @@ -194,6 +194,13 @@ Besides the generic components in the table above, each platform can specify its |stm32_enc |None (true or false) |Enable support for the STM32 timer encoder module |=================================================================== +.STM32F4 specific components +[width="99%", cols="<3,<5,<10", options="header"] +|=================================================================== +^|Key ^|Parameters ^|Meaning +|stm32f4_enc |None (true or false) |Enable support for the STM32F4 timer encoder module +|=================================================================== + .LPC17xx specific components [width="99%", cols="<3,<5,<10", options="header"] |=================================================================== diff --git a/doc/en/modules_stm32.txt b/doc/en/modules_stm32.txt new file mode 100644 index 00000000..6e4e1d36 --- /dev/null +++ b/doc/en/modules_stm32.txt @@ -0,0 +1,7 @@ +// $$HEADER$$ +Reference manual - STM32 platform dependent modules +-------------------------------------------------- + +This paragraph presents all the modules specific to the link:status.html[stm32] (stm32) platform. + +// $$FOOTER$$ diff --git a/doc/en/modules_stm32f4.txt b/doc/en/modules_stm32f4.txt new file mode 100644 index 00000000..48114dee --- /dev/null +++ b/doc/en/modules_stm32f4.txt @@ -0,0 +1,7 @@ +// $$HEADER$$ +Reference manual - STM32F4 platform dependent modules +----------------------------------------------------- + +This paragraph presents all the modules specific to the link:status.html[stm32f4] (stm32f4) platform. + +// $$FOOTER$$