Skip to main content

Bring-up 1: System and logs

The first bring-up stage maps your chip's RTOS and a UART onto TuyaOpen's OS abstraction, so the system boots and prints logs. Everything after this depends on it โ€” without working threads, timers, and a console you cannot debug the later stages.

Goalโ€‹

TuyaOpen boots on your chip, its OS primitives (threads, mutexes, semaphores, queues, timers, heap) run on your RTOS, and TuyaOpen log output appears over a UART.

Files to implementโ€‹

These adapter files are generated under platform/<your_chip>/tuyaos/ when you run tos.py new platform. Implement each by calling your chip SDK / RTOS.

FileWhat you implement
tkl_system.cReset, millisecond/tick time, random seed, critical-section enter/exit, CPU info
tkl_memory.cmalloc / free / realloc over your heap
tkl_thread.cCreate/destroy threads on your RTOS, priority mapping
tkl_mutex.cMutex create / lock / unlock (recursive)
tkl_semaphore.cSemaphore create / wait / post
tkl_queue.cMessage queue create / send / receive
tkl_timer.cHardware or software timer with ISR callback
tkl_output.cRoute TuyaOpen logs to your console (usually a UART printf)
tkl_uart.cUART init / read / write โ€” carries logs now and debug later

Detailsโ€‹

  • Time base first. tkl_system_get_millisecond / tick must be correct โ€” timers, timeouts, and the cloud heartbeat all depend on it.
  • Critical sections (tkl_system_enter_critical) must actually disable preemption/interrupts; many later races trace back to a no-op here.
  • tkl_output is the smallest useful milestone. Wire it to your UART printf early so the rest of bring-up is observable.
  • Thread priority mapping. TuyaOpen uses TKL_THREAD_PRI_LOWEST โ€ฆ HIGHEST; map these onto your RTOS's priority scale.
  • Start from the file closest to your RTOS in a reference port and replace its SDK calls.

Verifyโ€‹

Build apps/tuya_cloud/switch_demo (connectivity disabled is fine), flash, and boot. You succeed when the TuyaOpen banner and periodic logs print cleanly over your UART and the device does not crash or hang.

Next: Bring-up 2: Flash and storage.

See alsoโ€‹