Commit 9bbf8f43 authored by Johny Mattsson's avatar Johny Mattsson
Browse files

Successfully boot barebones NodeMCU on ESP32 (only).

RTOS driver evicted as it did not play nice with stdio etc.

Implemented a minimal driver to fully support Lua console on UART0. Output
on UART0 done via stdout (provided by the IDF). Input and setup handled
via driver_console/console.c. In addition to the direct input function
console_getc(), the driver also registers in the syscall tables to enable
regular stdio input functions to work (yay!). The Lua VM is still using the
direct interface since it's less overhead, but does also work when going
through stdin/fd 0.

Auto-bauding on the console is not yet functional; revisit when the UART docs
are available.

Module registration/linking/enabling moved over to be Kconfig based. See
updates to base_nodemcu/include/module.h and base_nodemcu/Kconfig for
details.

The sdk-overrides directory/approach is no longer used. The IDF is simply
too different to the old RTOS SDK - we need to adapt our code directly instead.

Everything in app/ is now unused, and will need to be gradually migrated
into components/ though it is probably better to migrate straight from the
latest dev branch.
parent a463d764
......@@ -10,7 +10,6 @@
#include <limits.h>
#include <stddef.h>
#include "user_config.h"
/*
** ==================================================================
......
menu "NodeMCU modules"
config LUA_MODULE_NODE
bool "Node module"
default "y"
help
Includes the node module (recommended).
endmenu
# Match up all the module source files with their corresponding Kconfig
# option in the form LUA_MODULE_<modname> and if enabled, add a
# "-u <modname>_module_selected1" option to force the linker to include
# the module. See components/core/include/module.h for further details on
# how this works.
-include $(PROJECT_PATH)/build/include/config/auto.conf
include $(PROJECT_PATH)/components/modules/uppercase.mk
MODULE_NAMES:=$(call uppercase,$(subst .c,,$(wildcard *.c)))
FORCE_LINK:=$(foreach mod,$(MODULE_NAMES),$(if $(CONFIG_LUA_MODULE_$(mod)), -u $(mod)_module_selected1))
COMPONENT_ADD_LDFLAGS=$(FORCE_LINK) -lmodules
include $(IDF_PATH)/make/component_common.mk
#include "module.h"
#include "lauxlib.h"
#include "esp_system.h"
// Lua: heap()
static int node_heap( lua_State* L )
{
uint32_t sz = system_get_free_heap_size();
lua_pushinteger(L, sz);
return 1;
}
static const LUA_REG_TYPE node_map[] =
{
{ LSTRKEY( "heap" ), LFUNCVAL( node_heap ) },
{ LNILKEY, LNILVAL }
};
NODEMCU_MODULE(NODE, "node", node_map, NULL);
uppercase_TABLE:=a,A b,B c,C d,D e,E f,F g,G h,H i,I j,J k,K l,L m,M n,N o,O p,P q,Q r,R s,S t,T u,U v,V w,W x,X y,Y z,Z
define uppercase_internal
$(if $1,$$(subst $(firstword $1),$(call uppercase_internal,$(wordlist
2,$(words $1),$1),$2)),$2)
endef
define uppercase
$(eval uppercase_RESULT:=$(call
uppercase_internal,$(uppercase_TABLE),$1))$(uppercase_RESULT)
endef
......@@ -3,7 +3,6 @@
* NodeMCU Team
* 2014-12-31
*******************************************************************************/
#include "user_config.h"
#include "flash_api.h"
#include <stdio.h>
#include <string.h>
......
......@@ -4,7 +4,7 @@
#include "sdkconfig.h"
#include "esp_spi_flash.h"
#define NUM_UART 2
#define NUM_UART 3
#if defined(CONFIG_FLASH_SIZE_512K)
# define FLASH_SEC_NUM 0x80 // 4MByte: 0x400, 2MByte: 0x200, 1MByte: 0x100, 512KByte: 0x80
......
......@@ -50,7 +50,6 @@ static inline int platform_uart_exists( unsigned id ) { return id < NUM_UART; }
uint32_t platform_uart_setup( unsigned id, uint32_t baud, int databits, int parity, int stopbits );
void platform_uart_send( unsigned id, uint8_t data );
int platform_uart_set_flow_control( unsigned id, int type );
void platform_uart_alt( int set );
......
#include "platform.h"
#include "driver/uart.h"
#include "driver/console.h"
#include <stdio.h>
int platform_init (void)
{
......@@ -11,89 +12,49 @@ int platform_init (void)
uint32_t platform_uart_setup( unsigned id, uint32_t baud, int databits, int parity, int stopbits )
{
UART_ConfigTypeDef cfg;
switch( baud )
if (id == CONSOLE_UART)
{
case BIT_RATE_300:
case BIT_RATE_600:
case BIT_RATE_1200:
case BIT_RATE_2400:
case BIT_RATE_4800:
case BIT_RATE_9600:
case BIT_RATE_19200:
case BIT_RATE_38400:
case BIT_RATE_57600:
case BIT_RATE_74880:
case BIT_RATE_115200:
case BIT_RATE_230400:
case BIT_RATE_460800:
case BIT_RATE_921600:
case BIT_RATE_1843200:
case BIT_RATE_3686400:
cfg.baud_rate = baud;
break;
default:
cfg.baud_rate = BIT_RATE_9600;
break;
ConsoleSetup_t cfg;
cfg.bit_rate = baud;
switch (databits)
{
case 5: cfg.data_bits = CONSOLE_NUM_BITS_5; break;
case 6: cfg.data_bits = CONSOLE_NUM_BITS_6; break;
case 7: cfg.data_bits = CONSOLE_NUM_BITS_7; break;
case 8: // fall-through
default: cfg.data_bits = CONSOLE_NUM_BITS_8; break;
}
switch (parity)
{
case PLATFORM_UART_PARITY_EVEN: cfg.parity = CONSOLE_PARITY_EVEN; break;
case PLATFORM_UART_PARITY_ODD: cfg.parity = CONSOLE_PARITY_ODD; break;
default: // fall-through
case PLATFORM_UART_PARITY_NONE: cfg.parity = CONSOLE_PARITY_NONE; break;
}
switch (stopbits)
{
default: // fall-through
case PLATFORM_UART_STOPBITS_1:
cfg.stop_bits = CONSOLE_STOP_BITS_1; break;
case PLATFORM_UART_STOPBITS_1_5:
cfg.stop_bits = CONSOLE_STOP_BITS_1_5; break;
case PLATFORM_UART_STOPBITS_2:
cfg.stop_bits = CONSOLE_STOP_BITS_2; break;
}
cfg.auto_baud = false;
console_setup (&cfg);
return baud;
}
switch( databits )
{
case 5:
cfg.data_bits = UART_WordLength_5b;
break;
case 6:
cfg.data_bits = UART_WordLength_6b;
break;
case 7:
cfg.data_bits = UART_WordLength_7b;
break;
case 8:
default:
cfg.data_bits = UART_WordLength_8b;
break;
}
switch (stopbits)
{
case PLATFORM_UART_STOPBITS_1_5:
cfg.stop_bits = USART_StopBits_1_5;
break;
case PLATFORM_UART_STOPBITS_2:
cfg.stop_bits = USART_StopBits_2;
break;
default:
cfg.stop_bits = USART_StopBits_1;
break;
}
switch (parity)
else
{
case PLATFORM_UART_PARITY_EVEN:
cfg.parity = USART_Parity_Even;
break;
case PLATFORM_UART_PARITY_ODD:
cfg.parity = USART_Parity_Odd;
break;
default:
cfg.parity = USART_Parity_None;
break;
printf("UART1/UART2 not yet supported\n");
return 0;
}
UART_ParamConfig (id, &cfg);
return baud;
}
// if set=1, then alternate serial output pins are used. (15=rx, 13=tx)
void platform_uart_alt( int set )
{
uart0_alt( set );
return;
}
void platform_uart_send( unsigned id, uint8_t data )
{
uart_tx_one_char(id, data);
if (id == CONSOLE_UART)
putchar (data);
}
COMPONENT_ADD_INCLUDEDIRS:=include
include $(IDF_PATH)/make/component_common.mk
#include <stdint.h>
#include <stdbool.h>
#include <rom.h>
#include "rom/ets_sys.h"
static char space[]=" ";
static char blank[]=".. ";
......
#ifndef _HEXDUMP_H_
#define _HEXDUMP_H_
#include <stdint.h>
void hexdump (char *src, uint32_t len, uint32_t base_addr);
#endif
......@@ -8,7 +8,6 @@
#ifndef SPIFFS_CONFIG_H_
#define SPIFFS_CONFIG_H_
#include "user_config.h"
#include <stdio.h>
#include <stdint.h>
#include <string.h>
......
......@@ -3,7 +3,6 @@
#include <stdint.h>
#include <stdbool.h>
#include <c_types.h>
/* use LOW / MEDIUM / HIGH since it isn't clear from the docs which is higher */
......
......@@ -2,10 +2,10 @@
This file encapsulates the SDK-based task handling for the NodeMCU Lua firmware.
*/
#include "task/task.h"
#include "mem.h"
#include <stdlib.h>
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/queue.h"
#include "freertos/semphr.h"
......
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
void pingTask(void *pvParameters)
{
while (1) {
vTaskDelay(1000 / portTICK_PERIOD_MS);
printf("ping\n");
}
}
void app_main()
{
xTaskCreatePinnedToCore(&pingTask, "pingTask", 2048, NULL, 5, NULL, 0);
}
include $(IDF_PATH)/make/component_common.mk
#ifndef _SDK_OVERRIDES_C_TYPES_H
#define _SDK_OVERRIDES_C_TYPES_H
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment