First of all thanks for such beautiful thing like Python on a MCU. At this moment I'm evaluating if it's suitable for my current project. The main feature of this project will be the possibility to update the logic on the fly, but without interrupting the C code that gets information from sensors and make some sort of smart history.
So with this in mind I will ask you for some advises and help.
The main function of the python will be to update a servo position, once at 20 ms. With my tests now I get at first run of the module 25.7 ms and afterwards around 15.6 ms. A temporary solution is to increase the MCU speed, now is 48 MHz and I can get a different one with 72 MHz.
The pmfeatures:
PM_FEATURES = {
"HAVE_PRINT": True,
"HAVE_GC": True,
"HAVE_FLOAT": True,
"HAVE_DEL": True,
"HAVE_IMPORTS": True,
"HAVE_DEFAULTARGS": True,
"HAVE_REPLICATION": True,
"HAVE_CLASSES": True,
"HAVE_ASSERT": True,
"HAVE_GENERATORS": True,
"HAVE_BACKTICK": True,
"HAVE_STRING_FORMAT": True,
"HAVE_CLOSURES": True,
"HAVE_BYTEARRAY": True,
"HAVE_DEBUG_INFO": True,
"HAVE_SNPRINTF_FORMAT": False,
"HAVE_AUTOBOX": True,
"HAVE_SLICE": True,
}
and the platform file is this one:
/*
* plat.c
*
* Created on: Nov 24, 2013
* Author: Valeriu
*/
#undef __FILE_ID__
#define __FILE_ID__ 0x70
/** PyMite platform-specific routines for AVR target */
#include "pm.h"
uint8_t buff[1024];
uint32_t pos;
PmReturn_t
plat_init(void)
{
pos = 0;
return PM_RET_OK;
}
PmReturn_t
plat_deinit(void)
{
return PM_RET_OK;
}
uint8_t
plat_memGetByte(PmMemSpace_t memspace, uint8_t const **paddr)
{
uint8_t b = 0;
switch (memspace)
{
case MEMSPACE_RAM:
case MEMSPACE_PROG:
b = **paddr;
*paddr += 1;
return b;
case MEMSPACE_EEPROM:
case MEMSPACE_SEEPROM:
case MEMSPACE_OTHER0:
case MEMSPACE_OTHER1:
case MEMSPACE_OTHER2:
case MEMSPACE_OTHER3:
default:
return 0;
}
}
PmReturn_t
plat_getByte(uint8_t *b)
{
PmReturn_t retval = PM_RET_OK;
return retval;
}
PmReturn_t
plat_putByte(uint8_t b)
{
buff[pos++] = b;
return PM_RET_OK;
}
PmReturn_t
plat_getMsTicks(uint32_t *r_ticks)
{
return PM_RET_OK;
}
void
plat_reportError(PmReturn_t result)
{
}
Because the python program uses only dict, if, loops, lists and number multiplication how should I optimize it.
I think to make the memgetbyte a inline one, also to remove the debug from the features. What will you advise me regarding your experience with PyMite.
Thanks.