1
0
mirror of https://github.com/elua/elua.git synced 2025-01-25 01:02:54 +08:00

Added stm32.pio platform specific module

Also removed the platform specific initialization code, this is now
automatic.
This commit is contained in:
Bogdan Marinescu 2013-08-13 23:59:32 +03:00
parent 88257cdc9a
commit 2dff752740
8 changed files with 94 additions and 260 deletions

View File

@ -24,6 +24,7 @@ return {
modules = {
generic = { 'all', "-i2c", "-net" },
platform = 'all',
platform_name = 'stm32'
},
}

View File

@ -199,7 +199,7 @@ function gen_module_list( desc, plconf, platform, boardname )
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
gstr = gstr .. gen.print_define( "PLATFORM_MODULES_LINE", sf( '_ROM( "%s", luaopen_platform, platform_map )', platform ) )
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" )
else

View File

@ -25,5 +25,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" } }
end

View File

@ -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"
specific_files = "system_stm32f4xx.c startup_stm32f4xx.s stm32f4xx_it.c platform.c platform_int.c cpu.c stm32_pio.c"
local ldscript = "stm32.ld"
-- Prepend with path

View File

@ -11,8 +11,6 @@
#include "auxmods.h"
#include "cpu.h"
//Lua: reset()
static int cpu_reset( lua_State *L )
{

View File

@ -193,7 +193,7 @@ static void NVIC_Configuration(void)
// PIO
// This is pretty much common code to all STM32 devices.
// todo: Needs updates to support different processor lines.
static GPIO_TypeDef * const pio_port[] = { GPIOA, GPIOB, GPIOC, GPIOD, GPIOE, GPIOF, GPIOG, GPIOH, GPIOI };
GPIO_TypeDef * const pio_port[] = { GPIOA, GPIOB, GPIOC, GPIOD, GPIOE, GPIOF, GPIOG, GPIOH, GPIOI };
static const u32 pio_port_clk[] = { RCC_AHB1Periph_GPIOA , RCC_AHB1Periph_GPIOB
, RCC_AHB1Periph_GPIOC , RCC_AHB1Periph_GPIOD , RCC_AHB1Periph_GPIOE
, RCC_AHB1Periph_GPIOF , RCC_AHB1Periph_GPIOG , RCC_AHB1Periph_GPIOH
@ -1642,46 +1642,3 @@ int platform_flash_erase_sector( u32 sector_id )
#endif // #ifdef BUILD_WOFS
// ****************************************************************************
// Platform specific modules go here
#ifdef ENABLE_STM32_CPU
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
extern const LUA_REG_TYPE stm32_cpu_map[];
const LUA_REG_TYPE platform_map[] =
{
#if LUA_OPTIMIZE_MEMORY > 0
{ LSTRKEY( "cpu" ), LROVAL( stm32_cpu_map ) },
#endif
{ LNILKEY, LNILVAL }
};
LUALIB_API int luaopen_platform( lua_State *L )
{
#if LUA_OPTIMIZE_MEMORY > 0
return 0;
#else // #if LUA_OPTIMIZE_MEMORY > 0
luaL_register( L, PS_LIB_TABLE_NAME, platform_map );
// Setup the new tables inside platform table
lua_newtable( L );
luaL_register( L, NULL, stm32_cpu_map );
lua_setfield( L, -2, "cpu" );
return 1;
#endif // #if LUA_OPTIMIZE_MEMORY > 0
}
#else // #ifdef ENABLE_ENC
LUALIB_API int luaopen_platform( lua_State *L )
{
return 0;
}
#endif // #ifdef ENABLE_ENC

View File

@ -1,212 +0,0 @@
// eLua platform configuration
#ifndef __PLATFORM_CONF_H__
#define __PLATFORM_CONF_H__
#include "auxmods.h"
#include "type.h"
#include "stacks.h"
#include "stm32f4xx_conf.h"
#include "elua_int.h"
#include "sermux.h"
// *****************************************************************************
// Define here what components you want for this platform
#define BUILD_XMODEM
#define BUILD_SHELL
#define BUILD_ROMFS
//#define BUILD_MMCFS
#define BUILD_TERM
//#define BUILD_UIP
//#define BUILD_DHCPC
//#define BUILD_DNS
#define BUILD_CON_GENERIC
#define BUILD_ADC
#define BUILD_RPC
//#define BUILD_RFS
//#define BUILD_CON_TCP
#define BUILD_LINENOISE
#define BUILD_C_INT_HANDLERS
#define BUILD_LUA_INT_HANDLERS
//#define ENABLE_ENC
#define ENABLE_STM32_CPU
#define PLATFORM_HAS_SYSTIMER
//#define ENABLE_TRACE // Enable the ETM TRACE interface (TRACECLK, TRACE D0-3)
#define ENABLE_JTAG_SWD // Do NOT remove this unless you really not need JTAG/SWD
// *****************************************************************************
// UART/Timer IDs configuration data (used in main.c)
#define CON_UART_ID 0
#define CON_UART_SPEED 115200
#define TERM_LINES 25
#define TERM_COLS 80
// *****************************************************************************
// Auxiliary libraries that will be compiled for this platform
//#ifdef FORSTM3210E_EVAL
//#define AUXLIB_LCD "stm3210lcd"
//LUALIB_API int ( luaopen_lcd )( lua_State* L );
//#define LCDLINE _ROM( AUXLIB_LCD, luaopen_lcd, lcd_map )
//#else
#define LCDLINE
//#endif
#ifdef ENABLE_STM32_CPU
#define PS_LIB_TABLE_NAME "stm32"
#endif
#ifdef BUILD_ADC
#define ADCLINE _ROM( AUXLIB_ADC, luaopen_adc, adc_map )
#else
#define ADCLINE
#endif
#if defined( ELUA_BOOT_RPC ) && !defined( BUILD_RPC )
#define BUILD_RPC
#endif
#if defined( BUILD_RPC )
#define RPCLINE _ROM( AUXLIB_RPC, luaopen_rpc, rpc_map )
#else
#define RPCLINE
#endif
#ifdef PS_LIB_TABLE_NAME
#define PLATLINE _ROM( PS_LIB_TABLE_NAME, luaopen_platform, platform_map )
#else
#define PLATLINE
#endif
#define LUA_PLATFORM_LIBS_ROM\
_ROM( AUXLIB_PIO, luaopen_pio, pio_map )\
_ROM( AUXLIB_SPI, luaopen_spi, spi_map )\
_ROM( AUXLIB_PD, luaopen_pd, pd_map )\
_ROM( AUXLIB_UART, luaopen_uart, uart_map )\
_ROM( AUXLIB_TERM, luaopen_term, term_map )\
_ROM( AUXLIB_PACK, luaopen_pack, pack_map )\
_ROM( AUXLIB_BIT, luaopen_bit, bit_map )\
_ROM( AUXLIB_CPU, luaopen_cpu, cpu_map )\
_ROM( AUXLIB_ELUA, luaopen_elua, elua_map )\
_ROM( AUXLIB_TMR, luaopen_tmr, tmr_map )\
ADCLINE\
_ROM( AUXLIB_CAN, luaopen_can, can_map )\
_ROM( AUXLIB_PWM, luaopen_pwm, pwm_map )\
RPCLINE\
LCDLINE\
_ROM( AUXLIB_ELUA, luaopen_elua, elua_map )\
_ROM( LUA_MATHLIBNAME, luaopen_math, math_map )\
PLATLINE
// *****************************************************************************
// Configuration data
#define EGC_INITIAL_MODE 1
// Virtual timers (0 if not used)
#define VTMR_NUM_TIMERS 4
#define VTMR_FREQ_HZ 10
// Number of resources (0 if not available/not implemented)
#define NUM_PIO 5
#define NUM_SPI 3
#define NUM_UART 6
#define NUM_TIMER 12
#define NUM_PHYS_TIMER 12
#define NUM_PWM 4
#define NUM_ADC 16
#define NUM_CAN 1
// Enable RX buffering on UART
//#define BUF_ENABLE_UART
//#define CON_BUF_SIZE BUF_SIZE_128
// ADC Configuration Params
#define ADC_BIT_RESOLUTION 12
#define BUF_ENABLE_ADC
#define ADC_BUF_SIZE BUF_SIZE_2
// These should be adjusted to support multiple ADC devices
#define ADC_TIMER_FIRST_ID 0
#define ADC_NUM_TIMERS 4
// RPC boot options
#define RPC_UART_ID CON_UART_ID
#define RPC_UART_SPEED CON_UART_SPEED
// MMCFS Support (FatFs on SD/MMC)
// For STM32F407VGT6 - PA5 = CLK, PA6 = MISO, PA7 = MOSI, PA4 = CS
#define MMCFS_TICK_HZ 10
#define MMCFS_TICK_MS ( 1000 / MMCFS_TICK_HZ )
#define MMCFS_CS_PORT 1
#define MMCFS_CS_PIN 11
#define MMCFS_SPI_NUM 1
// CPU frequency (needed by the CPU module, 0 if not used)
u32 platform_s_cpu_get_frequency();
#define CPU_FREQUENCY platform_s_cpu_get_frequency()
// PIO prefix ('0' for P0, P1, ... or 'A' for PA, PB, ...)
#define PIO_PREFIX 'A'
// Pins per port configuration:
// #define PIO_PINS_PER_PORT (n) if each port has the same number of pins, or
// #define PIO_PIN_ARRAY { n1, n2, ... } to define pins per port in an array
// Use #define PIO_PINS_PER_PORT 0 if this isn't needed
#define PIO_PINS_PER_PORT 16
// Remote file system data
#define RFS_BUFFER_SIZE BUF_SIZE_512
#define RFS_UART_ID 0
#define RFS_TIMEOUT 100000
#define RFS_UART_SPEED 115200
// Linenoise buffer sizes
#define LINENOISE_HISTORY_SIZE_LUA 50
#define LINENOISE_HISTORY_SIZE_SHELL 10
// Allocator data: define your free memory zones here in two arrays
// (start address and end address)
// The F4 has 196K in total, but it is split into 3 sections:
// SRAM (xrw) : ORIGIN = 0x20000000, SIZE = 128K // Major SRAM
// CCMDATARAM (xrw) : ORIGIN = 0x10000000, SIZE = 64K // Core Coupled Data SRAM
// BKPSRAM, SIZE = 4K // Backup SRAM
//
#define CCMDATARAM_SIZE ( 64 * 1024 )
#define SRAM_SIZE ( 128 * 1024 )
#define MEM_START_ADDRESS { ( void* )end, (void* )( CCMDATARAM_BASE ) }
#define MEM_END_ADDRESS { ( void* )( SRAM_BASE + SRAM_SIZE - STACK_SIZE_TOTAL - 1 ), (void*)( CCMDATARAM_BASE + CCMDATARAM_SIZE - 1 ) }
// Flash data (only for ELUA_CPU_STM32F407VG for now)
#ifdef ELUA_CPU_STM32F407VG
#define INTERNAL_FLASH_SIZE ( 1024 * 1024 )
#define INTERNAL_FLASH_SECTOR_ARRAY { 16384, 16384, 16384, 16384, 65536, 131072, 131072, 131072, 131072, 131072, 131072, 131072 }
#define INTERNAL_FLASH_START_ADDRESS 0x08000000
#define BUILD_WOFS
#endif // #ifdef ELUA_CPU_STM32F407VG
// Interrupt queue size
#define PLATFORM_INT_QUEUE_LOG_SIZE 5
// Interrupt list
#define INT_GPIO_POSEDGE ELUA_INT_FIRST_ID
#define INT_GPIO_NEGEDGE ( ELUA_INT_FIRST_ID + 1 )
#define INT_TMR_MATCH ( ELUA_INT_FIRST_ID + 2 )
#define INT_UART_RX ( ELUA_INT_FIRST_ID + 3 )
#define INT_ELUA_LAST INT_UART_RX
#define PLATFORM_CPU_CONSTANTS\
_C( INT_GPIO_POSEDGE ), \
_C( INT_GPIO_NEGEDGE ), \
_C( INT_TMR_MATCH ), \
_C( INT_UART_RX )
// Conver from GPIO_PinSourceXX to GPIO_Pin_XX
#define GPIO_SOURCE2PIN(n) (1 << (n))
#endif // #ifndef __PLATFORM_CONF_H__

View File

@ -0,0 +1,88 @@
// STM32 specific PIO support
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
#include "platform.h"
#include "lrotable.h"
#include "platform_conf.h"
#include "auxmods.h"
#include "stm32f4xx_conf.h"
#include <string.h>
#if LUA_OPTIMIZE_MEMORY == 0
#error stm32.pio can only be compiled with LTR on (optram=true)
#endif
#define PIN_FUNC_GPIO ( -1 )
#define PIN_FUNC_ADC ( -2 )
#define PIN_FUNC_ALT_FIRST 0
#define PIN_FUNC_ALT_LAST 15
extern GPIO_TypeDef * const pio_port[];
// Lua: stm32.pio.set_function( function, pin1, pin2, ..., pinn )
// Function can be stm32.pio.GPIO, stm32.pio.AFx (x = 0..15), stm32.pio.ADC
static int stm32_pio_set_function( lua_State *L )
{
int func = luaL_checkinteger( L, 1 ), gpio, pin, port, idx;
int total = lua_gettop( L ), i;
GPIO_TypeDef *base;
if( total == 1 )
return luaL_error( L, "no pin specified" );
for( i = 2; i <= total; i ++ )
{
gpio = luaL_checkinteger( L, i );
port = PLATFORM_IO_GET_PORT( gpio );
pin = PLATFORM_IO_GET_PIN( gpio );
base = pio_port[ port ];
if( func == PIN_FUNC_GPIO )
base->MODER &= ~( 0x03 << ( pin * 2 ) );
else if( func == PIN_FUNC_ADC )
base->MODER |= 0x03 << ( pin * 2 );
else if( func >= PIN_FUNC_ALT_FIRST && func <= PIN_FUNC_ALT_LAST )
{
base->MODER &= ~( 0x03 << ( pin * 2 ) );
base->MODER |= 0x02 << ( pin * 2 );
if( pin >= 8 )
{
pin -= 8;
idx = 1;
}
else
idx = 0;
base->AFR[ idx ] &= ~( 0x0F << ( pin * 4 ) );
base->AFR[ idx ] |= func << ( pin * 4 );
}
}
return 0;
}
// Module function map
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
const LUA_REG_TYPE stm32_pio_map[] =
{
{ LSTRKEY( "set_function" ), LFUNCVAL( stm32_pio_set_function ) },
{ LSTRKEY( "GPIO" ), LNUMVAL( PIN_FUNC_GPIO ) },
{ LSTRKEY( "ADC" ), LNUMVAL( PIN_FUNC_ADC ) },
{ LSTRKEY( "AF0" ), LNUMVAL( 0 ) },
{ LSTRKEY( "AF1" ), LNUMVAL( 1 ) },
{ LSTRKEY( "AF2" ), LNUMVAL( 2 ) },
{ LSTRKEY( "AF3" ), LNUMVAL( 3 ) },
{ LSTRKEY( "AF4" ), LNUMVAL( 4 ) },
{ LSTRKEY( "AF5" ), LNUMVAL( 5 ) },
{ LSTRKEY( "AF6" ), LNUMVAL( 6 ) },
{ LSTRKEY( "AF7" ), LNUMVAL( 7 ) },
{ LSTRKEY( "AF8" ), LNUMVAL( 8 ) },
{ LSTRKEY( "AF9" ), LNUMVAL( 9 ) },
{ LSTRKEY( "AF10" ), LNUMVAL( 10 ) },
{ LSTRKEY( "AF11" ), LNUMVAL( 11 ) },
{ LSTRKEY( "AF12" ), LNUMVAL( 12 ) },
{ LSTRKEY( "AF13" ), LNUMVAL( 13 ) },
{ LSTRKEY( "AF14" ), LNUMVAL( 14 ) },
{ LSTRKEY( "AF15" ), LNUMVAL( 15 ) },
{ LNILKEY, LNILVAL }
};